"use client"; import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip, Legend, } from "recharts"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; interface DonutChartProps { data: Array<{ name: string; value: number; color?: string }>; title?: string; centerText?: { title: string; value: string | number; }; colors?: string[]; height?: number; className?: string; } const CustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { const data = payload[0]; return (

{data.name}

{data.value}{" "} sessions ({((data.value / data.payload.total) * 100).toFixed(1)}%)

); } return null; }; const CustomLegend = ({ payload }: any) => { return (
{payload.map((entry: any, index: number) => (
{entry.value}
))}
); }; const CenterLabel = ({ centerText, total }: any) => { if (!centerText) return null; return (

{centerText.value}

{centerText.title}

); }; export default function ModernDonutChart({ data, title, centerText, colors = [ "hsl(var(--chart-1))", "hsl(var(--chart-2))", "hsl(var(--chart-3))", "hsl(var(--chart-4))", "hsl(var(--chart-5))", ], height = 300, className, }: DonutChartProps) { const total = data.reduce((sum, item) => sum + item.value, 0); const dataWithTotal = data.map((item) => ({ ...item, total })); return ( {title && ( {title} )}
{dataWithTotal.map((entry, index) => ( ))} } /> } />
); }