import { prisma } from "@/lib/prisma";
import ProjectsClient from "./ProjectsClient";

export const dynamic = "force-dynamic";

export default async function AdminProjectsPage() {
  const projects = await prisma.project.findMany({
    orderBy: [{ createdAt: "desc" }],
    include: { _count: { select: { assemblies: true } } },
  });
  return (
    <ProjectsClient
      initial={projects.map((p) => ({
        id: p.id,
        code: p.code,
        name: p.name,
        customerCode: p.customerCode,
        status: p.status,
        dueDate: p.dueDate?.toISOString() ?? null,
        assemblyCount: p._count.assemblies,
      }))}
    />
  );
}
