import type { Metadata } from "next";
import { notFound } from "next/navigation";
import ProjectDetail from "@/components/public/project-detail";
import { getActiveLocale, isLocale, type Locale } from "@/lib/i18n";
import { getProjectDirectoryCopy } from "@/lib/project-content";
import { getPublishedProject } from "@/lib/project-queries";

type AppDetailPageProps = {
  params: { locale: string; slug: string };
};

export function generateMetadata({ params }: AppDetailPageProps): Metadata {
  if (!isLocale(params.locale)) return {};
  const locale = getActiveLocale(params.locale as Locale);
  const copy = getProjectDirectoryCopy(locale, "APP");
  return { title: copy.eyebrow, description: copy.description };
}

export default async function AppDetailPage({ params }: AppDetailPageProps) {
  if (!isLocale(params.locale)) notFound();
  const locale = getActiveLocale(params.locale as Locale);
  const project = await getPublishedProject("APP", params.slug);
  if (!project) notFound();
  return <ProjectDetail locale={locale} type="APP" project={project} />;
}
