import { notFound } from "next/navigation";
import { db } from "@/lib/db";
import { AdminPageHeader } from "@/components/admin/page-header";
import { IndustriesForm, IndustryFormValues } from "@/components/admin/industries-form";

export const dynamic = "force-dynamic";

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

  const initial: IndustryFormValues = {
    id: ind.id,
    title: ind.title,
    slug: ind.slug,
    description: ind.description,
    image: ind.image,
    icon: ind.icon || "Factory",
    order: ind.order,
    isEnabled: ind.isEnabled,
  };

  return (
    <>
      <AdminPageHeader title="Edit Industry" description={ind.title} />
      <IndustriesForm initial={initial} />
    </>
  );
}
