import React, { useState } from 'react'; import { TrendingUp, TrendingDown, ChevronDown } from 'lucide-react'; import { toast } from 'sonner'; import { api } from '@/api.js'; import { cn, fmt } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@/components/ui/collapsible'; function DriftRow({ row, refresh }) { const [loading, setLoading] = useState(false); async function handleUpdate() { setLoading(true); const oldAmount = row.expected_amount; try { await api.updateBill(row.id, { expected_amount: row.recent_amount }); toast.success(`"${row.name}" updated to ${fmt(row.recent_amount)}`, { action: { label: 'Undo', onClick: async () => { try { await api.updateBill(row.id, { expected_amount: oldAmount }); toast.success('Reverted'); refresh(); } catch { toast.error('Failed to revert'); } }, }, }); refresh(); } catch { toast.error('Failed to update bill'); } finally { setLoading(false); } } async function handleDismiss() { setLoading(true); try { await api.snoozeBillDrift(row.id); toast.success('Hidden for 30 days'); refresh(); } catch { toast.error('Failed to dismiss'); } finally { setLoading(false); } } const isUp = row.direction === 'up'; const sign = isUp ? '+' : ''; return (