import React from "react"; import { DollarSign } from "lucide-react"; import PaginationControls from "./pagination-controls"; export type GenericRow = { id: string | number; name: string; currentBalance: number; totalCharges: number; totalPayments: number; }; export default function PatientsBalancesList({ rows, reportType, loading, error, emptyMessage, pageIndex = 1, // 1-based perPage = 10, total, // optional totalCount from backend onPrev, onNext, hasPrev, hasNext, headerRight, // optional UI node to render in header }: { rows: GenericRow[]; reportType?: string | null; loading?: boolean; error?: string | boolean; emptyMessage?: string; // cursor props (required) pageIndex?: number; perPage?: number; total?: number | undefined; onPrev: () => void; onNext: () => void; hasPrev: boolean; hasNext: boolean; headerRight?: React.ReactNode; }) { const fmt = (v: number) => new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(v); const reportTypeTitle = (rt?: string | null) => { switch (rt) { case "patients_with_balance": return "Patients with Outstanding Balances"; case "patients_no_balance": return "Patients with Zero Balance"; case "monthly_collections": return "Monthly Collections"; case "collections_by_doctor": return "Collections by Doctor"; default: return "Balances"; } }; return (

{reportTypeTitle(reportType)}

{/* headerRight rendered here (if provided) */}
{headerRight ?? null}
{loading ? (
Loading {reportType ?? "data"}…
) : error ? (
Could not fetch data
{typeof error === "string" ? error : "An error occurred while loading the report."}
) : rows.length === 0 ? (

{emptyMessage ?? "No rows for this report."}

) : ( rows.map((r) => (

{r.name}

ID: {r.id}

0 ? "text-red-600" : "text-green-600" }`} > {fmt(r.currentBalance)}
Charges: {fmt(r.totalCharges)} · Collected:{" "} {fmt(r.totalPayments)}
)) )}
{/* Cursor pagination footer (cursor-only) */}
); }