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 { SkillForm } from "@/features/skills/skill-form";

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

  return (
    <div className="min-h-screen bg-muted/10 p-6 lg:p-12">
      <SkillForm initialData={skill} skillId={skill.id} />
    </div>
  );
}
