"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import type { BankingData } from "@/lib/types"; import { PieChart, Pie, Cell, ResponsiveContainer, Legend, Tooltip, } from "recharts"; interface CategoryBreakdownProps { data: BankingData; } export function CategoryBreakdown({ data }: CategoryBreakdownProps) { // Get current month expenses by category const thisMonth = new Date(); thisMonth.setDate(1); const thisMonthStr = thisMonth.toISOString().slice(0, 7); const monthExpenses = data.transactions.filter( (t) => t.date.startsWith(thisMonthStr) && t.amount < 0, ); const categoryTotals = new Map(); monthExpenses.forEach((t) => { const catId = t.categoryId || "uncategorized"; const current = categoryTotals.get(catId) || 0; categoryTotals.set(catId, current + Math.abs(t.amount)); }); const chartData = Array.from(categoryTotals.entries()) .map(([categoryId, total]) => { const category = data.categories.find((c) => c.id === categoryId); return { name: category?.name || "Non catégorisé", value: total, color: category?.color || "#94a3b8", }; }) .sort((a, b) => b.value - a.value) .slice(0, 6); const formatCurrency = (value: number) => { return new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR", }).format(value); }; if (chartData.length === 0) { return ( Dépenses par catégorie

Pas de données ce mois-ci

); } return ( Dépenses par catégorie
{chartData.map((entry, index) => ( ))} formatCurrency(value)} contentStyle={{ backgroundColor: "hsl(var(--card))", border: "1px solid hsl(var(--border))", borderRadius: "8px", }} /> ( {value} )} />
); }