import { Aurora } from '@/site/components/art/aurora';
import { ContourArt } from '@/site/components/art/contour-art';
import { PrincipleArt } from '@/site/components/art/principle-art';
import { MediaSlot } from '@/site/components/media/media-slot';
import { Counter } from '@/site/components/motion/counter';
import { Reveal } from '@/site/components/motion/reveal';
import { ViewScene } from '@/site/components/motion/scene';
import { Spotlight } from '@/site/components/motion/spotlight';
import { CardGrid } from '@/site/components/sections/card-grid';
import { CategoryCard } from '@/site/components/sections/cards';
import { Certificates } from '@/site/components/sections/certificates';
import { ClinicGallery } from '@/site/components/sections/clinic-gallery';
import { CtaBand } from '@/site/components/sections/cta-band';
import {
    heroFrame,
    PageHero,
    sheet,
} from '@/site/components/sections/page-hero';
import { SectionHeading } from '@/site/components/ui/heading';
import { useShared } from '@/site/hooks/use-shared';
import { useT } from '@/site/i18n';
import { cx } from '@/site/lib/cx';
import type {
    CategoryCard as CategoryCardData,
    GalleryPhoto,
    Stats,
} from '@/site/types';

type AboutProps = {
    categories: CategoryCardData[];
    /** Photos of the clinic (media library: clinic/*); the first one heads the page. */
    gallery: GalleryPhoto[];
    stats: Stats;
};

/**
 * About page: the working principles, the clinic in figures and photos,
 * its memberships and certificates, and the areas of expertise. Figures
 * are real (catalogue counts, the experience set in the settings) — no
 * invented history (docs/DECISIONS.md K11).
 */
export default function About({ categories, gallery, stats }: AboutProps) {
    const { site } = useShared();
    const t = useT();
    const [cover] = gallery;

    const figures = [
        site.experienceYears
            ? { value: site.experienceYears, label: t.home.stats.experience }
            : null,
        { value: stats.categories, label: t.home.stats.categories },
        { value: stats.treatments, label: t.home.stats.treatments },
        site.experienceYears
            ? null
            : { value: stats.languages ?? 0, label: t.home.stats.languages },
    ].filter((figure) => figure !== null);

    return (
        <>
            <PageHero
                eyebrow={t.about.eyebrow}
                title={t.about.title}
                lead={t.about.lead(site.name)}
                visual={
                    <MediaSlot
                        media={cover?.media}
                        priority
                        sizes="(min-width: 64rem) 40vw, 24rem"
                        className={heroFrame}
                        fallback={<ContourArt seed="about" alive />}
                    />
                }
            />

            {/* Principles */}
            <section className={cx('stage-light section-y', sheet)}>
                <div className="shell">
                    <SectionHeading
                        eyebrow={t.about.principlesEyebrow}
                        title={t.about.principlesTitle}
                    />
                    <ol className="border-line bg-line mt-16 grid gap-px overflow-hidden rounded-xl border md:grid-cols-2">
                        {t.about.principles.map((principle, index) => (
                            <Reveal
                                as="li"
                                key={principle.title}
                                delay={(index % 2) * 90}
                                className="bg-stage-2 p-8 md:p-12"
                            >
                                <div className="flex items-start justify-between gap-6">
                                    <p
                                        aria-hidden="true"
                                        className="font-display text-accent-fg text-4xl tabular-nums"
                                    >
                                        {String(index + 1).padStart(2, '0')}
                                    </p>
                                    {/* The principle as a small drawing that draws itself. */}
                                    <PrincipleArt
                                        index={index}
                                        className="-mt-2 size-28 md:size-32"
                                    />
                                </div>
                                <h3 className="font-display text-display-4 mt-6">
                                    {principle.title}
                                </h3>
                                <p className="text-soft mt-4 max-w-md text-lg">
                                    {principle.text}
                                </p>
                            </Reveal>
                        ))}
                    </ol>
                </div>
            </section>

            {/* The clinic in numbers */}
            <section className="stage-dark section-y relative isolate overflow-clip">
                <Aurora intensity={0.55} />
                <Spotlight />
                <div className="shell relative grid items-center gap-16 lg:grid-cols-2">
                    <SectionHeading
                        eyebrow={t.about.clinicEyebrow}
                        title={t.about.clinicTitle}
                        lead={t.about.clinicText}
                    />
                    <dl className="border-line bg-line grid gap-px overflow-hidden rounded-xl border sm:grid-cols-3 lg:grid-cols-1 xl:grid-cols-3">
                        {figures.map((figure, index) => (
                            <Reveal
                                key={figure.label}
                                delay={index * 90}
                                className="bg-ink-2 flex flex-col-reverse gap-3 p-8"
                            >
                                <dt className="text-soft text-sm">
                                    {figure.label}
                                </dt>
                                <dd className="font-display text-7xl leading-none text-accent tabular-nums">
                                    <Counter value={figure.value} />
                                </dd>
                            </Reveal>
                        ))}
                    </dl>
                </div>
            </section>

            {/* Photos of the clinic */}
            {gallery.length > 0 ? (
                // A scene: the photos drift inside their frames as it scrolls past.
                <ViewScene as="section" className="stage-light section-y">
                    <div className="shell">
                        <SectionHeading
                            eyebrow={t.about.galleryEyebrow}
                            title={t.about.galleryTitle}
                        />
                        <ClinicGallery photos={gallery} className="mt-14" />
                    </div>
                </ViewScene>
            ) : null}

            {/* Memberships and certificates */}
            {site.certificates.length > 0 ? (
                <section className="stage-light section-y pt-0!">
                    <div className="shell">
                        <SectionHeading
                            eyebrow={t.about.certificatesEyebrow}
                            title={t.about.certificatesTitle}
                            size="display-4"
                        />
                        <Reveal className="border-line bg-stage-2 mt-10 rounded-xl border p-8 md:p-12">
                            <Certificates tone="light" layout="grid" />
                        </Reveal>
                    </div>
                </section>
            ) : null}

            {/* Areas of expertise */}
            {categories.length > 0 ? (
                <section className="stage-light section-y">
                    <div className="shell">
                        <SectionHeading
                            eyebrow={t.about.areasEyebrow}
                            title={t.about.areasTitle}
                        />
                        <CardGrid
                            items={categories}
                            itemKey={(category) => category.key}
                            className="mt-14"
                            itemClassName="min-h-[22rem]"
                        >
                            {(category, index) => (
                                <CategoryCard
                                    category={category}
                                    index={index + 1}
                                />
                            )}
                        </CardGrid>
                    </div>
                </section>
            ) : null}

            <CtaBand />
        </>
    );
}
