'use client'; /** * CustomTooltip — Themed tooltip for Recharts charts. * * Features: * - Dark background (#141414) matching Divisi card color * - Accent border (#c8e600) for brand consistency * - Displays exact value, label, and percentage where applicable * - Styled with the Divisi theme tokens * * Requirements: 16.2 */ import { tooltipStyle } from '@/lib/constants/theme'; interface TooltipPayloadItem { name?: string; value?: number | string; color?: string; dataKey?: string; payload?: Record; } interface CustomTooltipProps { active?: boolean; payload?: TooltipPayloadItem[]; label?: string; /** If true, show percentage alongside value (useful for pie charts) */ showPercentage?: boolean; /** Total value for computing percentages */ total?: number; } export default function CustomTooltip({ active, payload, label, showPercentage = false, total, }: CustomTooltipProps) { if (!active || !payload || payload.length === 0) { return null; } return (
{label && (

{label}

)} {payload.map((entry, index) => { const value = typeof entry.value === 'number' ? entry.value.toLocaleString() : entry.value; const percentage = showPercentage && total && typeof entry.value === 'number' ? ((entry.value / total) * 100).toFixed(1) : null; return (
{entry.name ?? entry.dataKey}: {value} {percentage && ( ({percentage}%) )}
); })}
); }