"use client"; import { PieChart, Pie, Cell, ResponsiveContainer, Legend, Tooltip, } from "recharts"; const COLORS = { pending: "#eab308", // yellow-500 in_progress: "#3b82f6", // blue-500 completed: "#22c55e", // green-500 overdue: "#ef4444", // red-500 }; const STATUS_LABELS = { pending: "Pending", in_progress: "In Progress", completed: "Completed", overdue: "Overdue", }; const CustomTooltip = ({ active, payload }) => { if (active && payload && payload.length) { const data = payload[0].payload; return (

{STATUS_LABELS[data.status]}

{data.count} tasks ({data.percentage}%)

); } return null; }; const CustomLegend = ({ payload }) => { return ( ); }; export default function TaskStatusChart({ data, completionRate }) { // Calculate total and percentages const total = data.reduce((sum, item) => sum + item.count, 0); const chartData = data.map((item) => ({ ...item, percentage: total > 0 ? Math.round((item.count / total) * 100) : 0, })); if (total === 0) { return (

No tasks available

); } return (
{chartData.map((entry, index) => ( ))} } /> ({ color: COLORS[item.status], payload: item, }))} />
Total Tasks {total}
Completion Rate {completionRate}%
); }