import { notFound } from "next/navigation";
import { db } from "@/lib/db";
import { AdminPageHeader } from "@/components/admin/page-header";
import { FaqForm, FaqFormValues } from "@/components/admin/faq-form";

export const dynamic = "force-dynamic";

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

  const initial: FaqFormValues = {
    id: f.id,
    question: f.question,
    answer: f.answer,
    category: f.category || "",
    order: f.order,
    isEnabled: f.isEnabled,
  };

  return (
    <>
      <AdminPageHeader title="Edit FAQ" description={f.question} />
      <FaqForm initial={initial} />
    </>
  );
}
