import { notFound } from "next/navigation";
import { db } from "@/lib/db";
import { AdminPageHeader } from "@/components/admin/page-header";
import { BeforeAfterForm, BeforeAfterFormValues } from "@/components/admin/before-after-form";

export const dynamic = "force-dynamic";

export default async function EditBeforeAfterPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const b = await db.beforeAfter.findUnique({ where: { id } });
  if (!b) notFound();

  const initial: BeforeAfterFormValues = {
    id: b.id,
    title: b.title,
    description: b.description || "",
    category: b.category || "",
    location: b.location || "",
    completionDate: b.completionDate || "",
    beforeImage: b.beforeImage,
    afterImage: b.afterImage,
    isEnabled: b.isEnabled,
    order: b.order,
  };

  return (
    <>
      <AdminPageHeader title="Edit Before / After" description={b.title} />
      <BeforeAfterForm initial={initial} />
    </>
  );
}
