"use client"; import { Cell, Pie, PieChart, Tooltip } from "recharts"; import { ResponsiveChart } from "~/components/charts/responsive-chart"; import { useAnimationPreferences } from "~/components/providers/animation-preferences-provider"; export interface StatusChartDatum { status: string; name: string; count: number; value: number; } interface InvoiceStatusChartProps { data: StatusChartDatum[]; } const STATUS_COLORS = { draft: "hsl(0, 0%, 60%)", sent: "hsl(217, 91%, 60%)", pending: "hsl(217, 91%, 60%)", paid: "hsl(142, 71%, 45%)", overdue: "hsl(var(--destructive))", } as const; const formatChartCurrency = (value: number) => { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", minimumFractionDigits: 0, maximumFractionDigits: 0, }).format(value); }; function StatusTooltip({ active, payload, }: { active?: boolean; payload?: Array<{ payload: { name: string; count: number; value: number }; }>; }) { if (active && payload?.length) { const data = payload[0]!.payload; return (

{data.name}

{data.count} invoice{data.count !== 1 ? "s" : ""}

{formatChartCurrency(data.value)}

); } return null; } export function InvoiceStatusChart({ data }: InvoiceStatusChartProps) { const { prefersReducedMotion, animationSpeedMultiplier } = useAnimationPreferences(); const pieAnimationDuration = Math.round( 600 / (animationSpeedMultiplier || 1), ); if (data.length === 0) { return (

No invoice data available

Status breakdown will appear here once you create invoices

); } return (
{data.map((entry, index) => ( ))} } />
{data.map((item) => (
{item.name}

{item.count}

{formatChartCurrency(item.value)}

))}
); }