{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "states-03",
  "description": "A filtered table with no matching rows, explaining why it is empty and offering a way out.",
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/dashboard-header.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/states/states-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockMessage,\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { FilterChip } from '@/registry/components/dashboardblocks/dashboard-header'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport {\n  DataTable,\n  DataTableBody,\n  DataTableCell,\n  DataTableHead,\n  DataTableHeader,\n  DataTableRow,\n  DataTableStateRows,\n} from '@/registry/components/dashboardblocks/table'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCurrency } from '@/registry/lib/dashboardblocks/format'\nimport { useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\ntype OrderStatus = 'Paid' | 'Pending' | 'Refunded'\n\ninterface Order {\n  amount: number\n  customer: string\n  id: string\n  region: string\n  status: OrderStatus\n}\n\ninterface Filter {\n  field: 'region' | 'status'\n  label: string\n  value: string\n}\n\ninterface States3Props extends BlockStateProps {\n  defaultFilters: Filter[]\n  /** Leave out, or pass none, to show the empty state. */\n  orders?: Order[]\n  title: string\n}\n\nconst exampleProps: States3Props = {\n  defaultFilters: [\n    { field: 'status', label: 'Status', value: 'Refunded' },\n    { field: 'region', label: 'Region', value: 'Asia Pacific' },\n  ],\n  orders: [\n    {\n      amount: 184.5,\n      customer: 'Ava Thompson',\n      id: '#4821',\n      region: 'Europe',\n      status: 'Paid',\n    },\n    {\n      amount: 62,\n      customer: 'Leo Martins',\n      id: '#4820',\n      region: 'Asia Pacific',\n      status: 'Paid',\n    },\n    {\n      amount: 311.2,\n      customer: 'Maya Chen',\n      id: '#4819',\n      region: 'North America',\n      status: 'Refunded',\n    },\n    {\n      amount: 94.99,\n      customer: 'Noah Patel',\n      id: '#4818',\n      region: 'Asia Pacific',\n      status: 'Pending',\n    },\n    {\n      amount: 48,\n      customer: 'Zoe Williams',\n      id: '#4817',\n      region: 'Europe',\n      status: 'Refunded',\n    },\n  ],\n  title: 'Orders',\n}\n\nconst STATUS_TONES: Record<OrderStatus, StatusTone> = {\n  Paid: 'good',\n  Pending: 'warning',\n  Refunded: 'neutral',\n}\n\nconst currency = (value: number) => formatCurrency(value, { precision: 'exact' })\n\nfunction describe(shown: number, total: number, filters: Filter[]) {\n  const orders = `${total} ${total === 1 ? 'order' : 'orders'}`\n  if (filters.length === 0) return `All ${orders}, newest first.`\n  const matching = filters\n    .map((filter) => `${filter.label.toLowerCase()} ${filter.value}`)\n    .join(' and ')\n  return `${shown} of ${orders} with ${matching}.`\n}\n\nconst States3 = (props: States3Props) => {\n  const { defaultFilters, orders = [], errorMessage, status, title } = props\n  const [filters, setFilters] = useState(defaultFilters)\n  const state = getBlockState(status, orders)\n  const rows = orders.filter((order) =>\n    filters.every((filter) => order[filter.field] === filter.value),\n  )\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\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 aria-live='polite' className='text-muted-foreground text-sm'>\n                  {describe(rows.length, orders.length, filters)}\n                </p>\n              </BlockReady>\n            </header>\n            {filters.length > 0 && (\n              <ul aria-label='Active filters' className='flex flex-wrap gap-2'>\n                {filters.map((filter) => (\n                  <li key={filter.field} className='flex'>\n                    <FilterChip\n                      field={filter.label}\n                      value={filter.value}\n                      onRemove={() =>\n                        setFilters((current) => current.filter((item) => item !== filter))\n                      }\n                    />\n                  </li>\n                ))}\n              </ul>\n            )}\n            {!state && rows.length === 0 ? (\n              <BlockMessage\n                icon={\n                  <IconPlaceholder\n                    lucide='SearchXIcon'\n                    tabler='IconZoomCancel'\n                    hugeicons='SearchRemoveIcon'\n                    phosphor='MagnifyingGlassMinusIcon'\n                    remixicon='RiSearchLine'\n                  />\n                }\n                className='border-t'\n                title='No orders match these filters'\n                description='Remove a filter, or clear them all to see every order.'\n                action={\n                  <Button variant='outline' size='sm' onClick={() => setFilters([])}>\n                    Clear filters\n                  </Button>\n                }\n              />\n            ) : (\n              <DataTable caption={title}>\n                <DataTableHeader>\n                  <DataTableRow>\n                    <DataTableHead>Customer</DataTableHead>\n                    <DataTableHead>Region</DataTableHead>\n                    <DataTableHead>Status</DataTableHead>\n                    <DataTableHead align='end'>Amount</DataTableHead>\n                  </DataTableRow>\n                </DataTableHeader>\n                <DataTableBody>\n                  <DataTableStateRows colSpan={4} rows={5} />\n                  {!state &&\n                    rows.map((order) => (\n                      <DataTableRow key={order.id}>\n                        <DataTableCell primary truncate>\n                          <span className='block truncate'>{order.customer}</span>\n                          <span className='text-muted-foreground block text-xs font-normal tabular-nums'>\n                            {order.id}\n                          </span>\n                        </DataTableCell>\n                        <DataTableCell>{order.region}</DataTableCell>\n                        <DataTableCell>\n                          <StatusLabel tone={STATUS_TONES[order.status]}>\n                            {order.status}\n                          </StatusLabel>\n                        </DataTableCell>\n                        <DataTableCell align='end'>\n                          {currency(order.amount)}\n                        </DataTableCell>\n                      </DataTableRow>\n                    ))}\n                </DataTableBody>\n              </DataTable>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { States3, exampleProps as states3ExampleProps, type States3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/states/states-03.tsx"
    }
  ],
  "meta": {
    "shows": "A filtered table with no matching rows, explaining why it is empty and offering a way out.",
    "size": "full",
    "usedWith": [
      "data-table-02",
      "dashboard-header-01"
    ],
    "component": "States3",
    "props": "{ defaultFilters: { field: \"status\" | \"region\"; label: string; value: string }[]; orders?: { amount: number; customer: string; id: string; region: string; status: \"Paid\" | \"Pending\" | \"Refunded\" }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
