import { notFound } from "next/navigation";
import { createClient } from "@/lib/supabase/server";
import { getLeadFormOptions } from "@/lib/leads/queries";
import { PageHeader } from "@/components/layout/page-header";
import { LeadForm } from "../../lead-form";

export default async function EditLeadPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const supabase = await createClient();

  const [{ data: lead }, options] = await Promise.all([
    supabase
      .from("leads")
      .select("*, lead_assignments(user_id)")
      .eq("id", id)
      .single(),
    getLeadFormOptions(),
  ]);

  if (!lead) notFound();

  return (
    <div>
      <PageHeader
        title="Edit Lead"
        breadcrumb={`Leads / ${lead.full_name ?? "Edit"} / Edit`}
      />
      <LeadForm options={options} defaults={lead} leadId={id} />
    </div>
  );
}
