import { Link2Off, Layers } from 'lucide-react'; import { cn, fmtDate } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from '@/components/ui/dialog'; import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, } from '@/components/ui/alert-dialog'; import { transactionTitle, transactionDate, fmtTransactionAmount } from '@/components/bill-modal/transactionDisplay'; // The three unmatch flows for a linked bank transaction: the choice dialog // (single vs. review-similar), the single-unmatch confirm, and the bulk review // dialog (with optional merchant-rule removal). Presentational — the parent owns // the unmatch state and the confirm/bulk handlers. export default function UnmatchDialogs({ unmatchTarget, bulkUnmatch, setBulkUnmatch, unmatchConfirmOpen, setUnmatchConfirmOpen, transactionBusyId, bulkBusy, closeUnmatch, onSingleUnmatch, onOpenBulkUnmatch, onBulkConfirm, }) { return ( <> {/* ── Unmatch choice dialog ─────────────────────────────────── */} { if (!open) closeUnmatch(); }} > Unmatch transaction How would you like to proceed? {unmatchTarget && ( {transactionTitle(unmatchTarget)} {transactionDate(unmatchTarget) ? fmtDate(transactionDate(unmatchTarget)) : 'No date'} {' · '} {fmtTransactionAmount(unmatchTarget.amount, unmatchTarget.currency)} )} setUnmatchConfirmOpen(true)} className="flex items-start gap-3 rounded-lg border border-border/60 bg-background/50 p-3 text-left transition-colors hover:border-primary/40 hover:bg-primary/5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" > Unmatch this payment only Remove just this one transaction from the bill. Review all similar matches See all transactions with a similar payee name and manage them together. Optionally remove a merchant rule too. Cancel {/* ── Single unmatch confirm ────────────────────────────────── */} { if (!open) setUnmatchConfirmOpen(false); }} > Unmatch this transaction? {unmatchTarget && ( <> {transactionTitle(unmatchTarget)} {' '}will be unlinked from this bill. {unmatchTarget.linked_payment?.payment_source === 'provider_sync' ? ' The payment record will be removed and the balance restored.' : ' The payment record will be removed.'} > )} setUnmatchConfirmOpen(false)}> Cancel {transactionBusyId ? 'Unmatching…' : 'Confirm Unmatch'} {/* ── Bulk unmatch dialog ───────────────────────────────────── */} { if (!open) closeUnmatch(); }} > Review similar matches {unmatchTarget && ( Transactions similar to {transactionTitle(unmatchTarget)}. Uncheck any you want to keep matched. )} {bulkUnmatch && ( <> Quick select: setBulkUnmatch(p => ({ ...p, checkedIds: new Set(p.similar.map(t => t.id)) }))} > All setBulkUnmatch(p => ({ ...p, checkedIds: new Set() }))} > None {bulkUnmatch.checkedIds.size} of {bulkUnmatch.similar.length} selected {bulkUnmatch.similar.map(tx => ( { setBulkUnmatch(p => { const next = new Set(p.checkedIds); checked ? next.add(tx.id) : next.delete(tx.id); return { ...p, checkedIds: next }; }); }} /> {transactionTitle(tx)} {transactionDate(tx) ? fmtDate(transactionDate(tx)) : 'No date'} {tx.account_name && ` · ${tx.account_name}`} {fmtTransactionAmount(tx.amount, tx.currency)} ))} {bulkUnmatch.rules.length > 0 && ( Merchant rules {bulkUnmatch.rules.map(rule => ( setBulkUnmatch(p => ({ ...p, removeRuleId: checked ? rule.id : null })) } /> Remove rule "{rule.merchant}" Future syncs won't auto-match this pattern to this bill. ))} )} > )} Cancel setBulkUnmatch(null)} className="text-xs" > Back {bulkBusy ? 'Unmatching…' : `Unmatch ${bulkUnmatch?.checkedIds?.size ?? 0} transaction${bulkUnmatch?.checkedIds?.size !== 1 ? 's' : ''}`} > ); }
{transactionTitle(unmatchTarget)}
{transactionDate(unmatchTarget) ? fmtDate(transactionDate(unmatchTarget)) : 'No date'} {' · '} {fmtTransactionAmount(unmatchTarget.amount, unmatchTarget.currency)}
Unmatch this payment only
Remove just this one transaction from the bill.
Review all similar matches
See all transactions with a similar payee name and manage them together. Optionally remove a merchant rule too.
{transactionTitle(tx)}
{transactionDate(tx) ? fmtDate(transactionDate(tx)) : 'No date'} {tx.account_name && ` · ${tx.account_name}`}
{fmtTransactionAmount(tx.amount, tx.currency)}
Merchant rules
Remove rule "{rule.merchant}"
Future syncs won't auto-match this pattern to this bill.