"use client";

import { useEffect, useState } from "react";
import { Header } from "@/components/header";
import { Translate } from "@/components/translate";
import { FindBestSalon } from "@/components/find-best-salon";
import dynamic from "next/dynamic";
import { Story } from "@/types/story";
import { Shop } from "@/types/shop";
import { Paginate } from "@/types/global";
import { SearchField } from "@/components/main-search-field";

const Stories = dynamic(() => import("../../components/stories"));
const NearYou = dynamic(() =>
  import("./components/near-you").then((component) => ({ default: component.NearYou }))
);
const Masters = dynamic(() =>
  import("./components/masters").then((component) => ({ default: component.Masters }))
);
const Recommended = dynamic(() =>
  import("./components/recomended").then((component) => ({ default: component.Recommended }))
);

interface HomePage4ContentProps {
  settings: Record<string, string>;
  stories?: Story[][];
  shops?: Paginate<Shop>;
}

export const HomePage4Content = ({
  settings,
  stories,
  shops,
}: HomePage4ContentProps) => {
  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 (
    <>
      <div className="relative bg-ui-2-bg bg-no-repeat bg-clip-content bg-center bg-contain bg-gray-ui4bg  lg:h-[605px] h-[605px] aspect-[11 / 5]">
        <Header showLinks={false} settings={settings} isHidden={false} />
        <section className="w-full z-[2] absolute left-[50%] translate-x-[-50%] bottom-[-30px] flex justify-center items-center flex-col px-4 md:px-8 lg:px-0">
          <h1 className="md:text-[60px] text-center text-shadow mb-5 break-all">
            <Translate value="book.beauty.services" />
          </h1>
          <div className="w-full lg:w-auto drop-shadow-search">
            <SearchField />
          </div>
        </section>
      </div>
      <main>
        {!!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>
          <Recommended data={shops} />
          <Masters />
        </section>
        <section>
          <NearYou />
        </section>
        <section className="xl:container px-4">
          <FindBestSalon />
        </section>
      </main>
    </>
  );
};
