import { cx } from '@/utils/cx'; import { formatCurrency } from '@/lib/format'; type CurrencyAmount = { amountMicros: number; currencyCode: string; }; interface BudgetBarProps { spent: CurrencyAmount | null; budget: CurrencyAmount | null; } export const BudgetBar = ({ spent, budget }: BudgetBarProps) => { const spentMicros = spent?.amountMicros ?? 0; const budgetMicros = budget?.amountMicros ?? 0; const ratio = budgetMicros > 0 ? spentMicros / budgetMicros : 0; const percentage = Math.min(ratio * 100, 100); const fillColor = ratio > 0.9 ? 'bg-error-solid' : ratio > 0.7 ? 'bg-warning-solid' : 'bg-brand-solid'; const spentDisplay = spent ? formatCurrency(spent.amountMicros, spent.currencyCode) : '--'; const budgetDisplay = budget ? formatCurrency(budget.amountMicros, budget.currencyCode) : '--'; return (
Budget {spentDisplay} / {budgetDisplay}
); };