import { PercentageTrendIndicator } from '@/components/dashboard/percentage-trend-indicator'; import { AmountDisplay } from '@/components/ui/amount-display'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; import { BreakdownData } from '@/hooks/use-cashflow-data'; import { cn } from '@/lib/utils'; import { getCategoryColorClasses } from '@/types/category'; import { __ } from '@/utils/i18n'; import * as Icons from 'lucide-react'; import { LucideIcon } from 'lucide-react'; interface BreakdownCardProps { type: 'income' | 'expense'; data: BreakdownData; loading?: boolean; currency?: string; } const CHART_COLORS = [ 'var(--chart-1)', 'var(--chart-2)', 'var(--chart-3)', 'var(--chart-4)', 'var(--chart-5)', 'var(--chart-6)', 'var(--chart-7)', 'var(--chart-8)', ]; export function BreakdownCard({ type, data, loading, currency = 'USD', }: BreakdownCardProps) { const title = type === 'income' ? __('Income Sources') : __('Expense Categories'); const description = type === 'income' ? __('Where your money comes from') : __('Where your money goes'); const emptyMessage = type === 'income' ? __('No income this period') : __('No expenses this period'); if (loading) { return ( {title}
{Array.from({ length: 4 }).map((_, i) => (
))}
); } return (
{title}
{description}
{data.data.map((item, index) => { const Icon = (Icons[ item.category.icon as keyof typeof Icons ] || Icons.HelpCircle) as LucideIcon; const percentageChange = item.previous_amount > 0 ? ((item.amount - item.previous_amount) / item.previous_amount) * 100 : null; const categoryColor = getCategoryColorClasses( item.category.color, ); const chartColor = CHART_COLORS[index % CHART_COLORS.length]; return (
{item.category.name} {percentageChange !== null && ( )}
{item.percentage.toFixed(0)}%
); })} {data.data.length === 0 && (
{emptyMessage}
)}
); }