import type { ClientView } from '@/lib/client-view'; import { Card } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; interface PaymentStatusProps { accepted_total: string; payments: ClientView['payments']; /** Label for the total row. Defaults to "Totale Investimento" */ totalLabel?: string; /** Override the displayed amount (retainer: show offer accepted_total, not project total) */ overrideAmount?: string; /** When true, hide individual payment rows (Acconto/Saldo) — used for retainer offers */ hideRows?: boolean; } type PaymentStatusValue = 'da_saldare' | 'inviata' | 'saldato'; const statusConfig: Record< PaymentStatusValue, { label: string; badgeClass: string; dotClass: string } > = { da_saldare: { label: 'Da Saldare', badgeClass: 'border-transparent bg-[#2563eb] text-white', dotClass: 'bg-[#2563eb]', }, inviata: { label: 'Inviata', badgeClass: 'border-transparent bg-[#ca8a04] text-white', dotClass: 'bg-[#ca8a04]', }, saldato: { label: 'Saldato', badgeClass: 'border-transparent bg-[#16a34a] text-white', dotClass: 'bg-[#16a34a]', }, }; export function PaymentStatus({ accepted_total, payments, totalLabel = 'Totale Investimento', overrideAmount, hideRows = false, }: PaymentStatusProps) { const displayAmount = overrideAmount ?? accepted_total; const totalFormatted = parseFloat(displayAmount || '0').toLocaleString('it-IT', { style: 'currency', currency: 'EUR', minimumFractionDigits: 2, maximumFractionDigits: 2, }); return ( {/* Totale — unico importo visibile al cliente (LOCKED) */}

{totalLabel}

{totalFormatted}

{/* Righe pagamento: solo etichetta + stato, MAI importo singolo — omesse se hideRows */} {!hideRows && (
{payments.length === 0 ? (

Nessun piano di pagamento configurato.

) : ( payments.map((payment) => { const status = payment.status as PaymentStatusValue; const config = statusConfig[status] ?? statusConfig.da_saldare; return (
{/* Indicatore dot + etichetta */}
{/* Badge stato — nessun importo */} {config.label}
); }) )}
)} {/* Nota informativa */}

Per dettagli o domande sui pagamenti, contattaci direttamente.

); }