import { prisma } from "@/lib/prisma";
import { MateriForm } from "../../_components/materi-form";
import { notFound } from "next/navigation";

interface EditMateriPageProps {
  params: Promise<{ id: string }>;
}

export default async function EditMateriPage({ params }: EditMateriPageProps) {
  const { id } = await params;

  const materi = await prisma.materiAjar.findUnique({
    where: { id },
  });

  if (!materi) {
    notFound();
  }

  // Convert dates to string/ISO if needed for serialization or handled by component
  // Prisma dates are Date objects. Client component needs serializable props if strictly passed?
  // Next.js App Router server->client props must be serializable.
  const serializedMateri = {
    ...materi,
    createdAt: materi.createdAt.toISOString(),
    updatedAt: materi.updatedAt.toISOString(),
    tanggalMulai: materi.tanggalMulai.toISOString(),
    tanggalSelesai: materi.tanggalSelesai ? materi.tanggalSelesai.toISOString() : null,
  };

  return <MateriForm initialData={serializedMateri} isEdit />;
}
