import { useState } from 'react'; import { RotateCcw, Trash2, Loader2 } from 'lucide-react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { formatUSD } from '@/lib/money'; import type { Bill } from '@/types'; function daysLeftLabel(days: number | null | undefined): string | null { if (days == null) return null; if (days <= 0) return 'purges today'; if (days === 1) return '1 day left'; return `${days} days left`; } interface RecentlyDeletedBillsDialogProps { open: boolean; onOpenChange: (open: boolean) => void; bills?: Bill[]; onRestore: (bill: Bill) => void | Promise; } /** * Lists bills that were soft-deleted within the 30-day recovery window and lets * the user restore them — a durable path beyond the transient "Undo" toast. * * Presentational: the parent owns the list (`bills`) and the async `onRestore`, * so restoring refreshes the page's active bills too. */ export default function RecentlyDeletedBillsDialog({ open, onOpenChange, bills = [], onRestore }: RecentlyDeletedBillsDialogProps) { const [busyId, setBusyId] = useState(null); async function handleRestore(bill: Bill) { setBusyId(bill.id); try { await onRestore(bill); } finally { setBusyId(null); } } return ( Recently deleted Deleted bills are kept for 30 days before they’re permanently removed. Restore one to bring it back. {bills.length === 0 ? (

Nothing to recover

Bills you delete will appear here for 30 days.

) : (
    {bills.map(bill => { const left = daysLeftLabel(bill.days_left as number | null | undefined); const busy = busyId === bill.id; return (
  • {bill.name}

    {formatUSD(bill.expected_amount)} {bill.category_name ? ` · ${bill.category_name}` : ''} {left ? · {left} : null}

  • ); })}
)}
); }