import { Reveal } from '@/site/components/motion/reveal';
import { ViewScene } from '@/site/components/motion/scene';
import { Tilt } from '@/site/components/motion/tilt';
import { CardGrid } from '@/site/components/sections/card-grid';
import { ClinicGallery } from '@/site/components/sections/clinic-gallery';
import { AppointmentSection } from '@/site/components/sections/home/appointment-section';
import { AreasShowcase } from '@/site/components/sections/home/areas-showcase';
import { BeforeAfter } from '@/site/components/sections/home/before-after';
import { HomeHero } from '@/site/components/sections/home/hero';
import { KineticBand } from '@/site/components/sections/home/kinetic-band';
import { ProcessStory } from '@/site/components/sections/home/process-story';
import { ReviewsSection } from '@/site/components/sections/home/reviews-section';
import { WhatsAppBand } from '@/site/components/sections/home/whatsapp-band';
import { PostCard } from '@/site/components/sections/post-card';
import { ButtonLink } from '@/site/components/ui/button';
import { FaqList } from '@/site/components/ui/faq-list';
import { SectionHeading } from '@/site/components/ui/heading';
import { useShared } from '@/site/hooks/use-shared';
import { useT } from '@/site/i18n';
import type {
    BeforeAfterPair,
    DepartmentPanel,
    GalleryPhoto,
    Media,
    PostCard as PostCardData,
    QA,
    Reviews,
    Stats,
} from '@/site/types';

type HomeProps = {
    /**
     * The six service groups in their order: personalised medicine, oral and
     * dental health, hair, medical aesthetics, men's health, plastic surgery.
     */
    departments: DepartmentPanel[];
    /** Before and after photo pairs (media library: before-after/*); often none. */
    beforeAfter: BeforeAfterPair[];
    /** Background video or photo of the hero (media library: home/hero). */
    heroMedia: Media | null;
    /** Faint photos behind the hero artwork (media library: home/backdrop-*). */
    backdrops: Media[];
    /** Photos of the clinic (media library: clinic/*). */
    gallery: GalleryPhoto[];
    /** Photo of each step of the process (media library: home/process-1…). */
    processMedia: (Media | null)[];
    /** The newest blog posts. */
    posts: PostCardData[];
    faqs: QA[];
    /** Review platforms and reviews copied from them; both may be empty. */
    reviews: Reviews;
    stats: Stats;
    /**
     * The appointment form: where the site's own form posts the request
     * (CRM forms off), where the area and treatment chosen afterwards go,
     * and the privacy notice the form links to.
     */
    appointment: {
        action: string;
        interestAction: string;
        privacyUrl: string;
        /** Public key of the "I am not a robot" check; null while it is off. */
        turnstile: string | null;
    };
};

/**
 * The home page: a sequence of scenes, each with its own kind of movement
 * (docs/ANIMATIONS.md lists them). Right under the hero the six service
 * groups get a panel and a scene each, in the menus' order
 * (docs/DECISIONS.md K46); before and after photos follow once the clinic
 * has added some. The page closes with the appointment request, which
 * asks for the contact details first.
 *
 * Every scene is ordinary content first — readable without JavaScript and
 * with reduced motion.
 */
export default function Home({
    departments,
    beforeAfter,
    heroMedia,
    backdrops,
    gallery,
    processMedia,
    posts,
    faqs,
    reviews,
    stats,
    appointment,
}: HomeProps) {
    const { nav } = useShared();
    const t = useT();

    return (
        <>
            <HomeHero media={heroMedia} backdrops={backdrops} />

            {departments.length > 0 ? (
                // The groups in their panels — the light sheet that slides over the hero
                <AreasShowcase departments={departments} />
            ) : null}
            {departments.length > 1 ? (
                // The departments' names, oversized, sliding past each other
                <KineticBand departments={departments} />
            ) : null}

            {/* WhatsApp — name and phone first, then the chat */}
            <WhatsAppBand stats={stats} />

            {/* Before and after — in the place of the former approach section (K46) */}
            <BeforeAfter pairs={beforeAfter} />

            {/* Process — one bundle of lines that changes shape step by step (K40). The hero's second button leads here. */}
            <ProcessStory media={processMedia} />

            {/* The clinic — photos drifting inside their frames */}
            {gallery.length > 0 ? (
                <ViewScene as="section" className="stage-light section-y">
                    <div className="shell">
                        <div className="flex flex-wrap items-end justify-between gap-8">
                            <SectionHeading
                                eyebrow={t.home.gallery.eyebrow}
                                title={t.home.gallery.title}
                                lead={t.home.gallery.lead}
                            />
                            <Reveal>
                                <ButtonLink
                                    href={nav.pages.about.url}
                                    variant="outline"
                                >
                                    {t.home.gallery.all}
                                </ButtonLink>
                            </Reveal>
                        </div>
                        <ClinicGallery
                            photos={gallery}
                            layout="mosaic"
                            className="mt-14"
                        />
                    </div>
                </ViewScene>
            ) : (
                // The sections below start without top padding: they count
                // on a light section above them, not on the dark scene.
                <div
                    aria-hidden="true"
                    className="stage-light h-[clamp(5rem,11vw,11rem)]"
                />
            )}

            {/* Reviews — copied from the platforms, or links to them */}
            <ReviewsSection reviews={reviews} />

            {posts.length > 0 && nav.pages.blog ? (
                <section className="stage-light section-y pt-0!">
                    <div className="shell">
                        <div className="flex flex-wrap items-end justify-between gap-8">
                            <SectionHeading
                                eyebrow={t.blog.eyebrow}
                                title={t.home.blog.title}
                            />
                            <Reveal>
                                <ButtonLink
                                    href={nav.pages.blog.url}
                                    variant="outline"
                                >
                                    {t.blog.all}
                                </ButtonLink>
                            </Reveal>
                        </div>

                        <CardGrid
                            items={posts}
                            itemKey={(post) => post.key}
                            className="mt-14"
                        >
                            {(post) => (
                                <Tilt className="rounded-lg">
                                    <PostCard post={post} />
                                </Tilt>
                            )}
                        </CardGrid>
                    </div>
                </section>
            ) : null}

            {faqs.length > 0 ? (
                <section className="stage-light section-y pt-0!">
                    <div className="shell grid gap-12 lg:grid-cols-12">
                        <div className="lg:col-span-4">
                            <SectionHeading
                                eyebrow={t.home.faq.eyebrow}
                                title={t.home.faq.title}
                                size="display-4"
                            />
                            <Reveal className="mt-8" delay={120}>
                                <ButtonLink
                                    href={nav.pages.faq.url}
                                    variant="ghost"
                                >
                                    {t.home.faq.all}
                                </ButtonLink>
                            </Reveal>
                        </div>
                        <FaqList
                            items={faqs}
                            name="home-faq"
                            className="lg:col-span-8"
                        />
                    </div>
                </section>
            ) : null}

            {/* Appointment — leave your details, then (if you like) the area and the treatment */}
            <AppointmentSection
                action={appointment.action}
                interestAction={appointment.interestAction}
                privacyUrl={appointment.privacyUrl}
                turnstile={appointment.turnstile}
            />
        </>
    );
}
