import { useTranslation } from 'react-i18next' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from 'recharts' import type { BudgetDetail } from '@/lib/api' import { formatCurrency } from '@/lib/format' import { palette, headerGradient, type CategoryType } from '@/lib/palette' import { cn } from '@/lib/utils' interface Props { budget: BudgetDetail locale?: string } export function AvailableBalance({ budget, locale = 'en' }: Props) { const { t } = useTranslation() const { totals } = budget const available = totals.available const allData: Array<{ name: string; value: number; categoryType: CategoryType }> = [ { name: t('dashboard.remaining'), value: Math.max(0, available), categoryType: 'carryover' }, { name: t('dashboard.bills'), value: totals.bills_actual, categoryType: 'bill' }, { name: t('dashboard.expenses'), value: totals.expenses_actual, categoryType: 'variable_expense' }, { name: t('dashboard.debts'), value: totals.debts_actual, categoryType: 'debt' }, { name: t('dashboard.savings'), value: totals.savings_actual, categoryType: 'saving' }, { name: t('dashboard.investments'), value: totals.investments_actual, categoryType: 'investment' }, ] const data = allData.filter((d) => d.value > 0) return ( {t('dashboard.availableAmount')}
{data.map((entry, index) => ( ))} { if (!active || !payload?.length) return null const item = payload[0] return (

{item.name}

{formatCurrency(Number(item.value), budget.currency, locale)}

) }} />
= 0 ? 'text-success' : 'text-destructive')}> {formatCurrency(available, budget.currency, locale)} {t('dashboard.available', 'Available')}
) }