"use client"; import { Cell, Legend, Pie, PieChart, ResponsiveContainer, Tooltip, } 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; } interface TooltipProps { active?: boolean; payload?: Array<{ name: string; value: number; payload: { total: number }; }>; } const CustomTooltip = ({ active, payload }: TooltipProps) => { 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; }; interface LegendProps { payload?: Array<{ value: string; color: string; type?: string; }>; } const CustomLegend = ({ payload }: LegendProps) => { return (
{payload?.map((entry, index) => (
{entry.value}
))}
); }; interface CenterLabelProps { centerText?: { title: string; value: string | number; }; total: number; } const CenterLabel = ({ centerText }: CenterLabelProps) => { 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} )}
{ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); } }} > {dataWithTotal.map((entry, index) => ( ))} } /> } />
); }