import { notFound } from "next/navigation";
import { db } from "@/lib/db";
import { AdminPageHeader } from "@/components/admin/page-header";
import { ServiceForm, ServiceFormValues } from "@/components/admin/service-form";

export const dynamic = "force-dynamic";

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

  const initial: ServiceFormValues = {
    id: s.id,
    title: s.title,
    slug: s.slug,
    shortDescription: s.shortDescription,
    description: s.description,
    icon: s.icon || "Wrench",
    image: s.image,
    features: JSON.parse(s.features || "[]"),
    isEnabled: s.isEnabled,
    order: s.order,
    metaTitle: s.metaTitle || "",
    metaDescription: s.metaDescription || "",
  };

  return (
    <>
      <AdminPageHeader title="Edit Service" description={s.title} />
      <ServiceForm initial={initial} />
    </>
  );
}
