import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { BatchUploadClient } from "@/components/batch-upload/BatchUploadClient";

export const metadata = { title: "Batch Upload — VFX Review" };

export default async function BatchUploadPage() {
  const session = await auth();
  if (!session?.user) redirect("/login");

  if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
    redirect("/dashboard");
  }

  const projects = await db.project.findMany({
    where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
    select: { id: true, name: true, code: true },
    orderBy: { name: "asc" },
  });

  return <BatchUploadClient projects={projects} />;
}
