'use client' import { PieChart, Pie, Cell, Tooltip, Legend, ResponsiveContainer, } from 'recharts' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' interface StatusDataPoint { status: string count: number } interface StatusBreakdownProps { data: StatusDataPoint[] } const STATUS_COLORS: Record = { PENDING: '#8884d8', UNDER_REVIEW: '#82ca9d', SHORTLISTED: '#ffc658', SEMIFINALIST: '#ff7300', FINALIST: '#00C49F', WINNER: '#0088FE', ELIMINATED: '#de0f1e', WITHDRAWN: '#999999', } const renderCustomLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, }: { cx?: number cy?: number midAngle?: number innerRadius?: number outerRadius?: number percent?: number }) => { if (cx === undefined || cy === undefined || midAngle === undefined || innerRadius === undefined || outerRadius === undefined || percent === undefined) { return null } if (percent < 0.05) return null // Don't show labels for small slices const RADIAN = Math.PI / 180 const radius = innerRadius + (outerRadius - innerRadius) * 0.5 const x = cx + radius * Math.cos(-midAngle * RADIAN) const y = cy + radius * Math.sin(-midAngle * RADIAN) return ( cx ? 'start' : 'end'} dominantBaseline="central" fontSize={12} fontWeight={600} > {`${(percent * 100).toFixed(0)}%`} ) } export function StatusBreakdownChart({ data }: StatusBreakdownProps) { const total = data.reduce((sum, item) => sum + item.count, 0) // Format status for display const formattedData = data.map((d) => ({ ...d, name: d.status.replace(/_/g, ' '), color: STATUS_COLORS[d.status] || '#8884d8', })) return ( Project Status Distribution {total} projects
{formattedData.map((entry, index) => ( ))} [ `${value ?? 0} (${(((value ?? 0) / total) * 100).toFixed(1)}%)`, name ?? '', ]} />
) }