import { updateDonorProfileAction } from "@/app/actions/donor";
import { Notice } from "@/components/dashboard/notice";
import { PageHeader } from "@/components/dashboard/page-header";
import { SubmitButton } from "@/components/forms/submit-button";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { requireProfile } from "@/lib/auth";

export default async function SponsorProfilePage({ searchParams }: { searchParams: Promise<{ success?: string; error?: string }> }) {
  const messages = await searchParams;
  const profile = await requireProfile("donor");
  return (
    <>
      <PageHeader title="الملف الشخصي" description="يعرض رقم الدخول كما سجلته الإدارة، ويمكنك تحديث الاسم الظاهر." />
      <Notice success={messages.success} error={messages.error} />
      <Card className="max-w-2xl p-5 sm:p-6">
        <form action={updateDonorProfileAction} className="grid gap-5">
          <div><Label>الاسم الكامل</Label><Input name="fullName" defaultValue={profile.full_name} required /></div>
          <div><Label>رقم الهاتف</Label><Input value={profile.phone ?? ""} readOnly dir="ltr" className="bg-[var(--surface-muted)]" /></div>
          <SubmitButton pendingText="جارٍ حفظ الاسم..." className="w-full sm:w-auto sm:justify-self-start">حفظ الاسم</SubmitButton>
        </form>
      </Card>
    </>
  );
}
