import { prisma } from "@/core/db/prisma";
import { verifySession } from "@/core/security/session";
import { redirect } from "@/i18n/routing";
import { getLocale } from "next-intl/server";
import { notFound } from "next/navigation";
import { EducationForm } from "@/features/education/education-form";

export default async function EditEducationPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const session = await verifySession();
  const locale = await getLocale();

  if (!session) redirect({ href: "/admin/login", locale });

  const { id } = await params;
  const education = await prisma.education.findUnique({ where: { id } });

  if (!education) notFound();

  return (
    <div className="min-h-screen bg-muted/10 p-6 lg:p-12">
      <EducationForm
        initialData={{
          institution: education.institution,
          degree: education.degree,
          fieldOfStudy: education.fieldOfStudy,
          location: education.location,
          startYear: education.startYear,
          endYear: education.endYear,
          isOngoing: education.isOngoing,
          description: education.description,
          gpa: education.gpa,
          finalProjectTitle: education.finalProjectTitle,
          finalProjectUrl: education.finalProjectUrl,
          order: education.order,
        }}
        educationId={education.id}
      />
    </div>
  );
}
