import { notFound } from "next/navigation";
import { isLocale, type Locale } from "@/lib/i18n/config";
import { getDictionary } from "@/lib/i18n";
import { legalDocs } from "@/lib/legal-content";
import { buildMetadata } from "@/lib/seo";
import { LegalPage } from "@/components/store/legal-page";

export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
  const { locale: raw } = await params;
  if (!isLocale(raw)) return {};
  const locale = raw as Locale;
  const doc = legalDocs["legal"][locale];
  return buildMetadata({
    locale,
    title: `${doc.title} — DAR ZELLIGE`,
    description: doc.intro,
    path: "/legal",
  });
}

export default async function LegalRoutePage({ params }: { params: Promise<{ locale: string }> }) {
  const { locale: raw } = await params;
  if (!isLocale(raw)) notFound();
  const locale = raw as Locale;
  const dict = getDictionary(locale);
  const doc = legalDocs["legal"][locale];

  const links = [
    { href: `/${locale}/shipping`, label: dict.footer.shipping },
    { href: `/${locale}/faq`, label: dict.footer.faq },
    { href: `/${locale}/care`, label: dict.footer.care },
    { href: `/${locale}/privacy`, label: dict.footer.privacy },
    { href: `/${locale}/terms`, label: dict.footer.terms },
    { href: `/${locale}/legal`, label: dict.footer.legal },
  ];

  return (
    <LegalPage
      locale={locale}
      doc={doc}
      links={links}
      labels={{
        onThisPage: dict.legal.title,
        updated: dict.legal.updated,
        backHome: dict.errors.backHome,
        contact: dict.footer.contact,
        help: dict.footer.help,
      }}
    />
  );
}
