import { notFound } from "next/navigation";
import type { Metadata } from "next";
import MarketingRuntime from "@/components/MarketingRuntime";
import { BRAND_HTML, BRAND_SLUGS } from "@/content/brandIndex";
import { BRAND_META } from "@/content/brandMeta";

export const revalidate = 600;

export function generateStaticParams() {
  return BRAND_SLUGS.map((brand) => ({ brand }));
}

export async function generateMetadata({ params }: { params: Promise<{ brand: string }> }): Promise<Metadata> {
  const { brand } = await params;
  const meta = BRAND_META[brand];
  if (!meta) return { title: "Brands — Awafi Drugstore" };
  return {
    title: `${meta.name} — Awafi Drugstore`,
    description: meta.desc,
    openGraph: { title: `${meta.name} · ${meta.tagline}`, description: meta.desc },
  };
}

export default async function BrandProductsPage({ params }: { params: Promise<{ brand: string }> }) {
  const { brand } = await params;
  const html = BRAND_HTML[brand];
  if (!html) notFound();
  return (
    <>
      <link rel="stylesheet" href="/css/pages/brand-products.css" />
      <link rel="stylesheet" href="/css/pages/product-modal.css" />
      {/* Per-brand bespoke animated design stylesheet (scoped under its own class). */}
      <link rel="stylesheet" href={`/css/pages/${brand}.css`} />
      <MarketingRuntime html={html} scriptSrc={`/js/page-brand--${brand}.js`} />
    </>
  );
}
