import { notFound } from "next/navigation";
import { db } from "@/lib/db";
import { AdminPageHeader } from "@/components/admin/page-header";
import { TestimonialForm, TestimonialFormValues } from "@/components/admin/testimonial-form";

export const dynamic = "force-dynamic";

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

  const initial: TestimonialFormValues = {
    id: t.id,
    name: t.name,
    position: t.position || "",
    company: t.company || "",
    content: t.content,
    rating: t.rating,
    avatar: t.avatar,
    isEnabled: t.isEnabled,
    order: t.order,
  };

  return (
    <>
      <AdminPageHeader title="Edit Testimonial" description={t.name} />
      <TestimonialForm initial={initial} />
    </>
  );
}
