import { Plus, Link2, Pencil, Trash2 } from 'lucide-react'; import { cn, fmt, fmtDate } from '@/lib/utils'; import { Button } from '@/components/ui/button'; function isTransactionLinkedPayment(payment) { return payment?.payment_source === 'transaction_match' || payment?.transaction_id != null; } function isHistoryOnlyPayment(payment) { return !!payment?.accounting_excluded; } function paymentSourceLabel(source) { const labels = { manual: 'Manual', file_import: 'File import', provider_sync: 'Sync', transaction_match: 'Transaction', auto_match: 'SimpleFIN', }; return labels[source] || source || 'Manual'; } function paymentSourceTone(source) { const tones = { manual: 'border-emerald-500/25 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400', file_import: 'border-sky-500/25 bg-sky-500/10 text-sky-600 dark:text-sky-400', provider_sync: 'border-violet-500/25 bg-violet-500/10 text-violet-600 dark:text-violet-400', transaction_match: 'border-primary/25 bg-primary/10 text-primary', auto_match: 'border-violet-500/25 bg-violet-500/10 text-violet-600 dark:text-violet-400', }; return tones[source] || tones.manual; } // Payment-history list for a bill (edit mode): each recorded payment with its // source badge, plus edit/remove actions for manual payments (matched and // history-only rows are read-only). Presentational — the parent owns the // payment state and the add/edit/delete handlers. export default function PaymentHistoryList({ payments, paymentsLoading, paymentBusy, onAdd, onEdit, onDelete, }) { return ( <>

Payment history

{payments.length} recorded

{paymentsLoading ? (
Loading payment history...
) : payments.length === 0 ? (

No payments yet

Use the form below to record the first payment.

) : (
{payments.map(payment => { const linkedPayment = isTransactionLinkedPayment(payment); const historyOnly = isHistoryOnlyPayment(payment); return (

{fmt(payment.amount)}

{paymentSourceLabel(payment.payment_source)} {historyOnly && ( History only )}

{fmtDate(payment.paid_date)} · {payment.method || (payment.payment_source === 'transaction_match' ? 'Synced' : 'manual')}

{payment.notes && (

{payment.notes}

)}
{historyOnly ? ( Overridden ) : linkedPayment ? ( Matched ) : ( <> )}
); })}
)} ); }