import AboutSection from "@/components/home/AboutSection";
import CertificationSection from "@/components/home/CertificationSection";
import GallerySection from "@/components/home/GallerySection";
import HeroHome from "@/components/home/HeroHome";
import MaterialsSection from "@/components/home/MaterialsSection";
import ProcessSection from "@/components/home/ProcessSection";
import StatsSection from "@/components/home/StatsSection";
import ValuePropSection from "@/components/home/ValuePropSection";
import { buildPageMetadata, homeJsonLd, readKeywords, seo } from "@/config/seo";
import type { Metadata } from "next";
import { type Locale, useTranslations } from "next-intl";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { use } from "react";
import HeroImage from "../../../public/home/white-gold-set-advance-manufacturer.webp";

export async function generateMetadata({
  params,
}: Omit<PageProps<"/[locale]">, "children">): Promise<Metadata> {
  const { locale } = await params;
  const typedLocale = locale as Locale;
  const t = await getTranslations({
    locale: typedLocale,
    namespace: "IndexPage.seo",
  });
  const base = await buildPageMetadata({
    href: "/",
    locale: typedLocale,
    title: t("title"),
    description: t("metaDescription"),
    keywords: readKeywords(t, "IndexPage.seo"),
  });

  // `title.template` in a layout only reaches CHILD segments. The home page
  // shares its segment with `[locale]/layout.tsx`, so it never receives the
  // suffix and was the only page shipping a title without the brand in it —
  // costly on branded search. Applied here from the same single source, so the
  // two cannot drift apart.
  return { ...base, title: seo.titleTemplate.replace("%s", t("title")) };
}

export default function IndexPage({ params }: PageProps<"/[locale]">) {
  const { locale } = use(params);

  // Enable static rendering
  setRequestLocale(locale as Locale);

  const tSeo = useTranslations("IndexPage.seo");

  return (
    <div>
      <HeroHome />
      <StatsSection />
      <AboutSection />
      <CertificationSection />
      <ValuePropSection />
      <MaterialsSection />
      <ProcessSection />
      <GallerySection />
      {/* One @graph for the whole page — Organization, WebSite and WebPage cross-
          reference each other by @id — emitted after the content it describes. */}
      <script
        type="application/ld+json"
        // biome-ignore lint/security/noDangerouslySetInnerHtml: structured data
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(
            homeJsonLd({
              name: tSeo("title"),
              description: tSeo("metaDescription"),
              href: "/",
              locale: locale as Locale,
              // The hero is the page's LCP image; the static import carries its
              // real dimensions, so they cannot drift from the file.
              primaryImage: HeroImage,
            }),
          ),
        }}
      />
    </div>
  );
}
