import { getDemoBySlug, demos } from "@/data/demos";
import KlinikTemplate from "@/components/templates/KlinikTemplate";
import RestoranTemplate from "@/components/templates/RestoranTemplate";
import KurumsalTemplate from "@/components/templates/KurumsalTemplate";
import DentalTemplate from "@/components/templates/DentalTemplate";
import RestoranTemplate2 from "@/components/templates/RestoranTemplate2";
import { notFound } from "next/navigation";
import { i18n, Locale } from "@/i18n-config";

export async function generateStaticParams() {
  const paths: Array<{ lang: Locale; slug: string }> = [];
  const demoList = Object.keys(demos);
  for (const lang of i18n.locales) {
    for (const slug of demoList) {
      paths.push({ lang, slug });
    }
  }
  return paths;
}

export async function generateMetadata({ params }: { params: Promise<{ lang: Locale; slug: string }> }) {
  const { slug } = await params;
  const data = getDemoBySlug(slug);
  if (!data) return { title: "Demo Bulunamadı | Ayris Tech" };
  return {
    title: `${data.firma.adi} — Premium Arayüz Demosu`,
    description: data.firma.slogan,
  };
}

export default async function DemoPage({ params }: { params: Promise<{ lang: Locale; slug: string }> }) {
  const { slug } = await params;
  const data = getDemoBySlug(slug);
  if (!data) notFound();

  if (data.template === "klinik") return <KlinikTemplate data={data} />;
  if (data.template === "restoran") return <RestoranTemplate data={data} />;
  if (data.template === "kurumsal") return <KurumsalTemplate data={data} />;
  if (data.template === "dental") return <DentalTemplate data={data} />;
  if (data.template === "restoran2") return <RestoranTemplate2 data={data} />;
  notFound();
}
