"use client"; import Link from "next/link"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { CategoryIcon } from "@/components/ui/category-icon"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Cell, } from "recharts"; import type { CategoryChartData } from "./category-pie-chart"; interface CategoryBarChartProps { data: CategoryChartData[]; formatCurrency: (amount: number) => string; title?: string; maxItems?: number; } export function CategoryBarChart({ data, formatCurrency, title = "Top catégories de dépenses", maxItems = 10, }: CategoryBarChartProps) { const displayData = data.slice(0, maxItems).reverse(); // Reverse pour avoir le plus grand en haut // Custom tick component for clickable labels const CustomYAxisTick = ({ x, y, payload }: any) => { const categoryName = payload.value; const item = displayData.find((d) => d.name === categoryName); if (!item) { return ( {categoryName} ); } const href = item.categoryId === null || item.categoryId === undefined ? "/transactions?includeUncategorized=true" : `/transactions?categoryIds=${item.categoryId}`; return ( {categoryName} ); }; return ( {title} {displayData.length > 0 ? ( { if (Math.abs(v) >= 1000) { return `${(v / 1000).toFixed(1)}k€`; } return `${Math.round(v)}€`; }} tick={{ fill: "var(--muted-foreground)" }} /> { if (!active || !payload?.length) return null; const item = payload[0].payload as CategoryChartData; return ( {item.name} {formatCurrency(item.value)} ); }} /> {displayData.map((entry, index) => ( ))} ) : ( Pas de données pour cette période )} ); } // Find the Card component in this file