import { Fragment, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { ChevronRightIcon, ChevronDownIcon, PlusIcon } from '@heroicons/react/24/outline'; import { toast } from 'sonner'; import PageHeader from '../components/ui/PageHeader'; import Pagination from '../components/ui/Pagination'; import { formatRial, formatDate, formatNumber } from '../lib/utils'; import { usePatientInvoices, MY_PAYMENTS_LIMIT, type PatientInvoiceRow, type InvoiceRowStatus, } from '../hooks/useMyPayments'; const STATUS_LABEL: Record = { paid: 'پرداخت شده', unsettled: 'تسویه نشده' }; const STATUS_BADGE: Record = { paid: 'green', unsettled: 'amber' }; const EMPTY: PatientInvoiceRow[] = []; /** HH:MM (Persian digits) from a unix timestamp. */ function formatTime(unix: number): string { return new Intl.DateTimeFormat('fa-IR', { hour: '2-digit', minute: '2-digit' }).format(new Date(unix * 1000)); } /** پرداخت‌های ثبت‌شده — a single patient's recorded invoices (node 2). */ export default function MyPaymentDetailPage() { const { patientUuid } = useParams<{ patientUuid: string }>(); const navigate = useNavigate(); const [page, setPage] = useState(1); const [expanded, setExpanded] = useState(null); const { data, isLoading } = usePatientInvoices(patientUuid, page); const payload = data?.data; const patient = payload?.patient; const rows = payload?.data ?? EMPTY; const total = payload?.meta?.totalRecords ?? 0; const th: React.CSSProperties = { textAlign: 'right', padding: '12px 16px', fontWeight: 600 }; const td: React.CSSProperties = { padding: '12px 16px' }; return ( <> } /> {/* سربرگ بیمار */}
نام بیمار: {patient?.name ?? '—'} کدملی: {patient?.national_code ?? '—'}
{isLoading ? (
در حال بارگذاری…
) : rows.length === 0 ? (
صورتحسابی ثبت نشده است
برای این بیمار هنوز پرداخت ثبت‌شده‌ای وجود ندارد.
) : ( <>
{rows.map((row) => { const open = expanded === row.uuid; return ( {open && ( )} ); })}
شماره صورتحساب تاریخ ساعت نوع خدمت مبلغ کل (تومان) وضعیت جزئیات
#{formatNumber(row.number)} {formatDate(row.issued_at)} {formatTime(row.issued_at)} {row.service_title ?? '—'} {formatRial(row.total_rials)} {STATUS_LABEL[row.status]}
{row.items.length === 0 ? ( آیتمی ثبت نشده است. ) : (
{row.items.map((it) => (
{it.title}{it.quantity > 1 ? ` × ${formatNumber(it.quantity)}` : ''} {formatRial(it.total_rials)}
))}
)}
)} ); }