"use client";

import { useEffect, useState } from "react";
import { Translate } from "@/components/translate";
import Image from "next/image";
import clsx from "clsx";
import { Header } from "@/components/header";
import { FindBestSalon } from "@/components/find-best-salon";
import { Services } from "./components/services";
import { MobileCard } from "./components/mobile-card";
import { SearchField } from "./components/search-field";
import { NearYou } from "./components/near-you";
import { Salons } from "./components/salons";
import { Recommended } from "./components/recomended";
import Stories from "../../../components/stories";
import { Paginate } from "@/types/global";
import { Category } from "@/types/category";
import { Shop } from "@/types/shop";
import { Story } from "@/types/story";

const userImages = [
  "/img/user1.png",
  "/img/user2.png",
  "/img/user3.png",
  "/img/user4.png",
  "/img/user5.png",
  "/img/user6.png",
];

interface Home2ContentProps {
  settings: Record<string, string>;
  services?: Paginate<Category>;
  shops?: Paginate<Shop>;
  stories?: Story[][];
}

export function Home2Content({ settings, services, shops, stories }: Home2ContentProps) {
  const [mounted, setMounted] = useState(false);
  useEffect(() => {
    setMounted(true);
  }, []);

  if (!mounted) {
    return (
      <main className="xl:container px-4 py-20">
        <div className="h-10 w-40 bg-gray-200 rounded mb-10 animate-pulse" />
        <div className="h-16 w-2/3 max-w-xl bg-gray-200 rounded mb-6 animate-pulse" />
        <div className="h-14 w-full max-w-3xl bg-gray-200 rounded-button mb-16 animate-pulse" />
        <div className="flex gap-4 overflow-hidden">
          {Array.from(Array(4).keys()).map((i) => (
            <div key={i} className="bg-gray-200 rounded-button min-w-[240px] h-80 animate-pulse" />
          ))}
        </div>
      </main>
    );
  }

  return (
    <>
      <Header isHidden={false} settings={settings} />
      <main>
        <section className="flex flex-col items-center justify-center xl:container mb-24">
          <div className="grid md:grid-cols-2 lg:gap-48 mb-10">
            <div className="px-4 xl:px-0">
              <h1 className="lg:text-[65px] md:text-5xl text-3xl break-words leading-normal text-center md:text-start">
                <span className="font-bold text-giantsOrange">
                  <Translate value="book.service" />
                </span>{" "}
                <Translate value="in.the.best.salon.near.you" />
              </h1>
              <p className="text-xl my-5 hidden md:block">
                <Translate value="home-2.hero.description" />
              </p>
              <div className="hidden md:flex items-center gap-2 pb-32">
                <div className="flex items-center">
                  {userImages.map((img, i) => (
                    <Image
                      src={img}
                      alt={`user-${i}`}
                      width={36}
                      height={36}
                      className={clsx("w-9 h-9 rounded-full", i !== 0 && "-ml-3")}
                      key={img}
                    />
                  ))}
                </div>
                <span className="text-gray-field text-xl">
                  {10} <Translate value="people.booked" />
                </span>
              </div>
            </div>
            <div className="relative h-[300px] md:h-full px-4 xl:px-0 mt-10 md:mt-0 mb-32 md:mb-0">
              <div className="hero-1 relative h-full w-1/2" />
              <div className="hero-2 absolute w-44 aspect-square top-0 rounded-full z-[2]" />
              <div className="hero-3 absolute aspect-[1/1.5] w-36 top-48 z-[2]" />
              <div className="hero-4 absolute aspect-square w-28 top-16 z-[2] rounded-full" />
            </div>
          </div>
          <SearchField />
        </section>

        {!!stories?.length && (
          <section className="mt-10">
            <div className="flex items-center pt-12 pb-9 flex-col">
              <div className="text-4xl font-semibold">
                <Translate value="stories.widget" />
              </div>
              <span className="text-xl">
                <Translate value="view.the.stories" />
              </span>
            </div>
            <div className="xl:container pb-12">
              <Stories data={stories} buttonVariant="2" />
            </div>
          </section>
        )}

        <section className="xl:container px-4">
          <Recommended data={shops} />
        </section>

        <section className="xl:container px-4">
          <Services data={services} />
        </section>

        <section className="xl:container px-4">
          <NearYou data={shops} />
        </section>
        <section className="xl:container px-4">
          <Salons />
        </section>
        <section className="xl:container px-4">
          <div className="grid md:grid-cols-2 gap-7 my-14">
            <MobileCard title="best.masters" description="mobile.card.description" />
            <MobileCard img="/img/mobile-card-3.png" />
          </div>
        </section>
        <section className="xl:container px-4">
          <FindBestSalon />
        </section>
      </main>
    </>
  );
}
