"use client"; import { useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Layers, SplitSquareHorizontal } from "lucide-react"; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend, } from "recharts"; import type { Account } from "@/lib/types"; interface BalanceChartDataPoint { date: string; [key: string]: string | number; } interface BalanceLineChartProps { aggregatedData: BalanceChartDataPoint[]; perAccountData: BalanceChartDataPoint[]; accounts: Account[]; formatCurrency: (amount: number) => string; } const ACCOUNT_COLORS = [ "#6366f1", // indigo "#22c55e", // green "#f59e0b", // amber "#ef4444", // red "#8b5cf6", // violet "#06b6d4", // cyan "#ec4899", // pink "#84cc16", // lime ]; export function BalanceLineChart({ aggregatedData, perAccountData, accounts, formatCurrency, }: BalanceLineChartProps) { const [mode, setMode] = useState<"aggregated" | "split">("aggregated"); const [hoveredAccount, setHoveredAccount] = useState(null); const data = mode === "aggregated" ? aggregatedData : perAccountData; const hasData = data.length > 0; const getLineOpacity = (accountId: string) => { if (!hoveredAccount) return 1; return hoveredAccount === accountId ? 1 : 0.15; }; return ( Évolution du solde
{hasData ? (
{ // Format compact pour les grandes valeurs if (Math.abs(v) >= 1000) { return `${(v / 1000).toFixed(1)}k€`; } return `${Math.round(v)}€`; }} tick={{ fill: "var(--muted-foreground)" }} /> formatCurrency(value)} contentStyle={{ backgroundColor: "var(--card)", border: "1px solid var(--border)", borderRadius: "8px", }} /> {mode === "aggregated" ? ( ) : ( accounts.map((account, index) => ( )) )} {mode === "split" && ( (
setHoveredAccount(null)} > {payload?.map((entry, index) => { const accountId = entry.dataKey as string; const isHovered = hoveredAccount === accountId; const isDimmed = hoveredAccount && hoveredAccount !== accountId; return (
setHoveredAccount(accountId)} >
{entry.value}
); })}
)} /> )}
) : (
Pas de données pour cette période
)} ); }