import { createClient } from "@/lib/supabase/server";
import { notFound } from "next/navigation";
import { PatientForm } from "@/components/patients/patient-form";

export const dynamic = "force-dynamic";

export default async function EditPatientPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const supabase = await createClient();
  const { data: patient, error } = await supabase
    .from("patients")
    .select("*")
    .eq("id", id)
    .single();

  if (error || !patient) notFound();

  return (
    <div className="mx-auto max-w-2xl space-y-6">
      <div>
        <h1 className="text-3xl font-bold tracking-tight">Editar paciente</h1>
        <p className="text-muted-foreground">
          Modifica los datos de {patient.first_name} {patient.last_name}.
        </p>
      </div>
      <PatientForm patient={patient} />
    </div>
  );
}
