import { prisma } from "@/lib/prisma";
import ProjectDetailClient from "@/app/_ui/ProjectDetailClient";
import { notFound } from "next/navigation";

export const revalidate = 300;

export default async function ProjectPage({
  params,
}: {
  params: Promise<{ locale: string; slug: string }>;
}) {
  const { locale, slug } = await params;

  const project = await prisma.project.findFirst({
    where: { slug, published: true },
    include: {
      translations: {
        where: { locale },
        select: { title: true, description: true },
      },
    },
  });

  if (!project) return notFound();

  const tr = project.translations?.[0];
  const { translations: _translations, ...rest } = project;
  const localized = {
    ...rest,
    title: tr?.title ?? project.title,
    description: tr?.description ?? project.description,
  };

  return <ProjectDetailClient project={localized} locale={locale} />;
}

