import { useBudgetSummary, useMonthlyData } from '@/hooks/useBudget'; import { useBudgetContext } from '@/contexts/BudgetContext'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip, Legend, BarChart, Bar, XAxis, YAxis, CartesianGrid, } from 'recharts'; import { Server, Users, ShoppingCart, Building, Zap, Cpu, Package, Plane, Scale, Shield, Briefcase, HelpCircle, Megaphone, FileText, } from 'lucide-react'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; const CATEGORY_COLORS: Record = { 'Purchase': 'hsl(340 82% 52%)', // Vibrant pink 'Salary': 'hsl(262 83% 58%)', // Rich purple 'Cloud/Subscription': 'hsl(199 89% 48%)', // Bright cyan 'Marketing': 'hsl(43 96% 56%)', // Golden yellow 'Rent': 'hsl(280 68% 50%)', // Deep violet 'Utilities': 'hsl(173 80% 40%)', // Teal 'Hardware': 'hsl(22 92% 53%)', // Vivid orange 'Software': 'hsl(142 76% 36%)', // Emerald green 'Travel': 'hsl(217 91% 60%)', // Bright blue 'Legal': 'hsl(350 89% 60%)', // Coral red 'Insurance': 'hsl(192 91% 36%)', // Deep cyan 'Office Supplies': 'hsl(83 78% 41%)', // Lime green 'Consulting': 'hsl(291 64% 42%)', // Magenta 'Other': 'hsl(220 14% 46%)', // Slate }; const CATEGORY_ICONS: Record = { 'Purchase': , 'Salary': , 'Cloud/Subscription': , 'Marketing': , 'Rent': , 'Utilities': , 'Hardware': , 'Software': , 'Travel': , 'Legal': , 'Insurance': , 'Office Supplies': , 'Consulting': , 'Other': , }; export function ExpenseBreakdownChart() { const { data: summary, isLoading: summaryLoading } = useBudgetSummary(); const { data: monthlyData, isLoading: monthlyLoading } = useMonthlyData(6); const { formatCurrency } = useBudgetContext(); const pieData = summary?.expensesByCategory ? Object.entries(summary.expensesByCategory) .map(([name, value]) => ({ name, value })) .sort((a, b) => b.value - a.value) : []; const barData = monthlyData?.map(d => ({ ...d, month: new Date(d.month + '-01').toLocaleDateString('en-US', { month: 'short' }), })) || []; if (summaryLoading || monthlyLoading) { return ( Financial Overview Loading charts... ); } return ( Financial Overview Expense Breakdown Monthly Trends {pieData.length === 0 ? (
No expense data yet. Add transactions to see breakdown.
) : (
{/* Pie Chart */}
{pieData.map((entry, index) => ( ))} formatCurrency(value)} contentStyle={{ backgroundColor: 'hsl(var(--popover))', border: '1px solid hsl(var(--border))', borderRadius: '8px', color: 'hsl(var(--popover-foreground))' }} />
{/* Category List */}
{pieData.map((entry) => (
{CATEGORY_ICONS[entry.name] || CATEGORY_ICONS['Other']} {entry.name}
{formatCurrency(entry.value)}
))}
)} {barData.length === 0 ? (
No monthly data yet.
) : (
`$${(value / 1000).toFixed(0)}k`} /> formatCurrency(value)} contentStyle={{ backgroundColor: 'hsl(var(--popover))', border: '1px solid hsl(var(--border))', borderRadius: '8px', color: 'hsl(var(--popover-foreground))' }} />
)}
); } export { CATEGORY_COLORS, CATEGORY_ICONS };