import { auth } from "@/auth";
import { redirect } from "next/navigation";
import { db } from "@/lib/db";
import { ShootLogClient } from "@/components/shoot-log/ShootLogClient";

export const metadata = { title: "Shot Log" };

export default async function ShootLogPage() {
  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 <ShootLogClient projects={projects} />;
}
