{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table-05",
  "description": "A table of recent orders split into pages of five, with controls to move between them.",
  "registryDependencies": [
    "button",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/data-table.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/data-table/data-table-05.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  createDataTableColumnHelper,\n  DataTableContent,\n  DataTablePagination,\n  useDataTable,\n} from '@/registry/components/dashboardblocks/data-table'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { formatCurrency } from '@/registry/lib/dashboardblocks/format'\n\ntype OrderState = 'failed' | 'paid' | 'pending' | 'refunded'\n\ninterface OrderRow {\n  amount: number\n  customer: string\n  date: string\n  email: string\n  id: string\n  state: OrderState\n}\n\ninterface DataTable5Props extends BlockStateProps {\n  /** Defaults to a sentence with the orders' total and any that failed. */\n  description?: string\n  pageSize?: number\n  /** Follows the totals in the default description. */\n  period?: string\n  /** Leave out, or pass none, to show the empty state. */\n  rows?: OrderRow[]\n  title: string\n}\n\nconst CUSTOMERS = [\n  ['Ava Thompson', 'ava@northwind.io'],\n  ['Leo Martins', 'leo@brightpath.dev'],\n  ['Maya Chen', 'maya@loop.studio'],\n  ['Noah Patel', 'noah@fieldnotes.co'],\n  ['Zoe Williams', 'zoe@harbor.app'],\n  ['Ethan Brooks', 'ethan@quanta.ai'],\n]\n\nconst STATES: OrderState[] = [\n  'paid',\n  'paid',\n  'pending',\n  'paid',\n  'refunded',\n  'paid',\n  'failed',\n]\n\nconst exampleProps: DataTable5Props = {\n  pageSize: 5,\n  period: 'in the last 7 days',\n  rows: Array.from({ length: 18 }, (_, index) => {\n    const [customer, email] = CUSTOMERS[(index * 5) % CUSTOMERS.length]\n    return {\n      amount: Math.round((42 + ((index * 73) % 380) + (index % 3) * 0.49) * 100) / 100,\n      customer,\n      date: `Sep ${25 - Math.floor(index / 3)}`,\n      email,\n      id: `#${(4_821 - index).toString()}`,\n      state: STATES[index % STATES.length],\n    }\n  }),\n  title: 'Recent orders',\n}\n\nconst STATE_CONFIG: Record<OrderState, { label: string; tone: StatusTone }> = {\n  failed: { label: 'Failed', tone: 'bad' },\n  paid: { label: 'Paid', tone: 'good' },\n  pending: { label: 'Pending', tone: 'warning' },\n  refunded: { label: 'Refunded', tone: 'neutral' },\n}\n\nconst money = (value: number) => formatCurrency(value, { precision: 'exact' })\n\nconst summarize = (rows: OrderRow[], period?: string) => {\n  const paid = rows.filter((row) => row.state === 'paid')\n  const failed = rows.filter((row) => row.state === 'failed').length\n  const total = paid.reduce((sum, row) => sum + row.amount, 0)\n  const orders = `${rows.length} ${rows.length === 1 ? 'order' : 'orders'}${period ? ` ${period}` : ''}`\n  const failures = failed > 0 ? `, ${failed} failed` : ''\n  return `${orders}, ${money(total)} paid${failures}.`\n}\n\nconst noRows: OrderRow[] = []\n\nconst columnHelper = createDataTableColumnHelper<OrderRow>()\n\nconst columns = columnHelper.columns([\n  columnHelper.accessor('customer', {\n    cell: ({ row }) => (\n      <>\n        <span className='block truncate'>{row.original.customer}</span>\n        <span className='text-muted-foreground block truncate text-xs font-normal'>\n          {row.original.email}\n        </span>\n      </>\n    ),\n    header: 'Customer',\n    meta: { primary: true, truncate: true },\n  }),\n  columnHelper.accessor('id', {\n    header: 'Order',\n    meta: { cellClassName: 'tabular-nums' },\n  }),\n  columnHelper.accessor('date', {\n    header: 'Date',\n    meta: { cellClassName: 'whitespace-nowrap' },\n  }),\n  columnHelper.accessor('state', {\n    cell: ({ getValue }) => {\n      const state = STATE_CONFIG[getValue()]\n      return <StatusLabel tone={state.tone}>{state.label}</StatusLabel>\n    },\n    header: 'Status',\n  }),\n  columnHelper.accessor('amount', {\n    cell: ({ getValue }) => money(getValue()),\n    header: 'Amount',\n    meta: { align: 'end' },\n  }),\n])\n\nconst DataTable5 = (props: DataTable5Props) => {\n  const { pageSize = 5, period, rows = noRows, errorMessage, status, title } = props\n  const { description = summarize(rows, period) } = props\n  const table = useDataTable({\n    columns,\n    data: rows,\n    enableSorting: false,\n    pageSize,\n  })\n  const { pageIndex } = table.state.pagination\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, rows)}>\n      <section className='@container/data-table flex flex-col gap-3'>\n        <header className='flex flex-col gap-0.5'>\n          <h2 className='font-semibold tracking-tight'>{title}</h2>\n          <BlockReady className='text-sm'>\n            <p className='text-muted-foreground text-sm'>{description}</p>\n          </BlockReady>\n        </header>\n        <DataTableContent\n          caption={`${title}: ${description} Page ${pageIndex + 1} of ${table.getPageCount()}.`}\n          loadingRows={pageSize}\n          table={table}\n        />\n        <DataTablePagination className='border-t pt-3' table={table} />\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { DataTable5, exampleProps as dataTable5ExampleProps, type DataTable5Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/data-table/data-table-05.tsx"
    }
  ],
  "meta": {
    "shows": "A table of recent orders split into pages of five, with controls to move between them.",
    "size": "full",
    "usedWith": [
      "data-table-06",
      "billing-03"
    ],
    "component": "DataTable5",
    "props": "{ description?: string; pageSize?: number; period?: string; rows?: { amount: number; customer: string; date: string; email: string; id: string; state: \"failed\" | \"paid\" | \"pending\" | \"refunded\" }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
