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 { ExperienceForm } from "@/features/experience/experience-form";

export default async function EditExperiencePage({
  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 experience = await prisma.experience.findUnique({ where: { id } });
  if (!experience) notFound();

  return (
    <div className="min-h-screen bg-muted/10 p-6 lg:p-12">
      <ExperienceForm
        initialData={{
          year: experience.year,
          title: experience.title,
          company: experience.company,
          description: experience.description,
          achievements: experience.achievements as string[],
          order: experience.order,
        }}
        experienceId={experience.id}
      />
    </div>
  );
}
