"use client"; import { Bar, BarChart, CartesianGrid, LabelList, Line, LineChart, XAxis, YAxis, } from "recharts"; import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/components/ui/chart"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import type { PreparedComparisonChart } from "@/lib/charts/comparison"; interface ComparisonChartProps { prepared: PreparedComparisonChart; } function suffix(normalization: PreparedComparisonChart["config"]["normalization"]) { return normalization === "percent-of-total" ? "%" : ""; } export function ComparisonChart({ prepared }: ComparisonChartProps) { const { config, rows } = prepared; const chartConfig: ChartConfig = Object.fromEntries( config.series.map((series) => [ series.field, { label: series.label, color: `var(--${series.color})` }, ]), ); const data = rows.map((row) => ({ category: row.category, ...row.values, })); const valueSuffix = suffix(config.normalization); const chartHeight = Math.max( config.presentation === "horizontal-bar" ? rows.length * 54 : 320, 280, ); const common = { data, accessibilityLayer: true, margin: { top: 20, right: 28, left: 8, bottom: 12 }, } as const; return (