import { useMemo } from "react" import { DataTablePreset, Placeholder, type ColumnDef } from "@squadbase/vantage/components" import type { DetailRow } from "./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 DetailTableProps { data: DetailRow[] } export function DetailTable({ data }: DetailTableProps) { const columns = useMemo[]>( () => [ { accessorKey: "name", header: "Column 1", }, { accessorKey: "owner", header: "Column 2", }, { accessorKey: "category", header: "Column 3", }, { accessorKey: "status", header: "Column 4", }, { accessorKey: "revenue", header: "Column 5", cell: ({ row }) => (
{formatCurrency(row.original.revenue, { short: true })}
), }, { accessorKey: "units", header: "Column 6", cell: ({ row }) => (
{row.original.units.toLocaleString("en-US")}
), }, { accessorKey: "margin", header: "Column 7", cell: ({ row }) => (
{formatPercent(row.original.margin)}
), }, { accessorKey: "updated", header: "Column 8", cell: ({ row }) => ( {row.original.updated} ), }, ], [], ) return }