import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { prisma } from "@/lib/db";
import { getTemplates } from "@/lib/server-data";
import { NewEvaluationForm } from "@/components/NewEvaluationForm";

export default async function NewEvaluationPage() {
  const [session, templates] = await Promise.all([auth(), getTemplates()]);
  if (!session?.user?.id) redirect("/auth/login");

  const user = await prisma.user.findUnique({
    where: { id: session.user.id },
    select: { name: true, email: true },
  });

  const initialEvaluatorName = user?.name || user?.email || "";

  return (
    <NewEvaluationForm
      templates={templates.map((t) => ({ id: t.id, name: t.name }))}
      initialEvaluatorName={initialEvaluatorName}
    />
  );
}
