import { Table2 } from 'lucide-react' import { useState, type ReactNode } from 'react' import { panel } from '../styles' export interface LegendItem { label: string color: string shape?: 'rect' | 'line' } export interface TableData { columns: string[] rows: (string | number)[][] } /** * Card for one chart: title, legend (2+ series), and a table view that shows every value, so * nothing depends on hovering or on telling colors apart. */ export function ChartFrame({ title, subtitle, legend, table, children, className = '' }: { title: string; subtitle?: string; legend?: LegendItem[]; table: TableData; children: ReactNode; className?: string }) { const [showTable, setShowTable] = useState(false) return (
{title}
{subtitle &&

{subtitle}

}
{legend && legend.length > 1 && !showTable && ( )} {showTable ? : children}
) } export function DataTable({ data }: { data: TableData }) { return (
{data.columns.map((column, i) => ( ))} {data.rows.map((row, r) => ( {row.map((cell, i) => ( ))} ))}
{column}
{typeof cell === 'number' ? cell.toLocaleString('en-US', { maximumFractionDigits: 2 }) : cell}
) } /** Tooltip: value first (strong), series second, keyed with a short line in the series color. */ export function Tooltip({ x, y, title, rows, containerWidth }: { x: number; y: number; title: string; rows: { label: string; value: string; color?: string }[]; containerWidth: number }) { const flip = x > containerWidth - 180 return (

{title}

{rows.map((row) => (

{row.color && } {row.value} {row.label}

))}
) } export function ChartEmpty({ children }: { children: ReactNode }) { return
{children}
}