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 >= 100_000_000) return `${sign}${(abs / 100_000_000).toFixed(2)}億円` if (abs >= 10_000) return `${sign}${(abs / 10_000).toFixed(0)}万円` return `${sign}¥${abs.toLocaleString("ja-JP")}` } return `${sign}¥${Math.round(abs).toLocaleString("ja-JP")}` } 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: "列1", }, { accessorKey: "category", header: "列2", }, { accessorKey: "revenue", header: "列3", cell: ({ row }) => (
{formatCurrency(row.original.revenue, { short: true })}
), }, { accessorKey: "units", header: "列4", cell: ({ row }) => (
{row.original.units.toLocaleString("ja-JP")}
), }, { accessorKey: "share", header: "列5", cell: ({ row }) => (
{formatPercent(row.original.share * 100)}
), }, ], [], ) return }