import { Copy, PenLine, EyeOff, Eye, Clock, Trash2 } from 'lucide-react';
import { cn } from '@/lib/utils';
import { MobileBillRow } from '@/components/MobileBillRow';
function ordinal(n) {
const d = Number(n);
if (!d) return '—';
if (d > 3 && d < 21) return `${d}th`;
switch (d % 10) {
case 1: return `${d}st`;
case 2: return `${d}nd`;
case 3: return `${d}rd`;
default: return `${d}th`;
}
}
function hasHistoricalVisibility(bill) {
return !!bill.has_history_ranges || (bill.history_visibility && bill.history_visibility !== 'default');
}
function AprColor({ rate }) {
const cls =
rate >= 25 ? 'text-rose-400' :
rate >= 15 ? 'text-amber-400' :
'text-muted-foreground';
return {rate}% APR;
}
const ALL_ON = {
showCategory: true, showDueDay: true, showAmount: true, showCycle: true,
showApr: true, showBalance: true, showMinPayment: true, showAutopay: true, show2fa: true,
};
function BillCard({ bill, prefs = ALL_ON, onEdit, onToggle, onDelete, onHistory, onDuplicate }) {
const isDebt = bill.current_balance != null || bill.minimum_payment != null;
const hasHistory = hasHistoricalVisibility(bill);
return (
{/* Main info */}
{/* Name + badges */}
{prefs.showCategory && bill.category_name && (
{bill.category_name}
)}
{prefs.showAutopay && !!bill.autopay_enabled && (
Autopay
)}
{prefs.show2fa && !!bill.has_2fa && (
2FA
)}
{prefs.showSubscription && !!bill.is_subscription && (
Sub
)}
{hasHistory && (
)}
{/* Meta row */}
{prefs.showCycle &&
{bill.billing_cycle || 'monthly'}}
{prefs.showCycle && prefs.showDueDay &&
·}
{prefs.showDueDay &&
Due {ordinal(bill.due_day)}}
{prefs.showApr && isDebt && bill.interest_rate != null && (
<>
{(prefs.showCycle || prefs.showDueDay) &&
·}
>
)}
{prefs.showBalance && isDebt && bill.current_balance != null && (
<>
{(prefs.showCycle || prefs.showDueDay || (prefs.showApr && bill.interest_rate != null)) &&
·}
${Number(bill.current_balance).toLocaleString(undefined, { maximumFractionDigits: 0 })} balance
>
)}
{/* Amount */}
{prefs.showAmount && (
${Number(bill.expected_amount).toFixed(2)}
{prefs.showMinPayment && bill.minimum_payment != null && (
${Number(bill.minimum_payment).toFixed(0)} min
)}
)}
{/* Action icons */}
{!bill.active && onHistory && (
)}
);
}
export default function BillsTableInner({ bills, prefs = ALL_ON, onEdit, onToggle, onDelete, onHistory, onDuplicate }) {
return (
<>
{bills.map(bill => (
))}
{bills.map(bill => (
))}
>
);
}