import { useMemo } from "react" import { DataTablePreset, Placeholder } from "@squadbase/vantage/components" import type { ColumnDef } from "@squadbase/vantage/components" import type { TopItemRow } from "../../lib/kpi-chart-simple/types" function formatCurrency(n: number, opts: { short?: boolean } = {}): string { const sign = n < 0 ? "-" : "" const abs = Math.abs(n) if (opts.short) { if (abs >= 1_000_000) return `${sign}$${(abs / 1_000_000).toFixed(2)}M` if (abs >= 1_000) return `${sign}$${(abs / 1_000).toFixed(1)}K` return `${sign}$${abs.toLocaleString("en-US")}` } return `${sign}$${Math.round(abs).toLocaleString("en-US")}` } function formatPercent(value: number, digits = 1): string { return `${value.toFixed(digits)}%` } interface TopItemsTableProps { data: TopItemRow[] } export function TopItemsTable({ data }: TopItemsTableProps) { const columns = useMemo[]>( () => [ { accessorKey: "name", header: "Column 1", }, { accessorKey: "category", header: "Column 2", }, { accessorKey: "revenue", header: "Column 3", cell: ({ row }) => (
{formatCurrency(row.original.revenue, { short: true })}
), }, { accessorKey: "units", header: "Column 4", cell: ({ row }) => (
{row.original.units.toLocaleString("en-US")}
), }, { accessorKey: "share", header: "Column 5", cell: ({ row }) => (
{formatPercent(row.original.share * 100)}
), }, ], [], ) return }