{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billing-03",
  "description": "Recent invoices with their status and amount, what is outstanding and a PDF download for each one.",
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/billing.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/billing/billing-03.tsx",
      "content": "'use client'\n\nimport {\n  type InvoiceStatus,\n  InvoiceStatusLabel,\n  formatBillingDate,\n  getOutstandingInvoices,\n} from '@/registry/components/dashboardblocks/billing'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  DataTable,\n  DataTableBody,\n  DataTableCell,\n  DataTableHead,\n  DataTableHeader,\n  DataTableRow,\n  DataTableRowLink,\n  DataTableStateRows,\n} from '@/registry/components/dashboardblocks/table'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCurrency } from '@/registry/lib/dashboardblocks/format'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Invoice {\n  amount: number\n  date: Date\n  description: string\n  /** A muted line under the description, such as the period it covers. */\n  detail?: string\n  /** Where the invoice opens. The whole row links there. */\n  href?: string\n  id: string\n  number: string\n  status: InvoiceStatus\n}\n\ninterface Billing3Props extends BlockStateProps {\n  /** @default 'USD' */\n  currency?: string\n  /** Leave out to say what's outstanding. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  invoices?: Invoice[]\n  /** Leave out to hide Download. */\n  onDownload?: (id: string) => void\n  onViewAll?: () => void\n  title: string\n}\n\nconst invoiceDate = (month: number, day: number) => new Date(Date.UTC(2026, month, day))\n\nconst exampleProps: Billing3Props = {\n  invoices: [\n    {\n      amount: 612,\n      date: invoiceDate(8, 14),\n      description: 'Growth',\n      detail: 'Sep 14 – Oct 14',\n      href: '#in_0926',\n      id: 'in_0926',\n      number: 'INV-2026-0926',\n      status: 'due',\n    },\n    {\n      amount: 180,\n      date: invoiceDate(8, 2),\n      description: 'Extra seats',\n      detail: 'Prorated for 4 seats',\n      href: '#in_0914',\n      id: 'in_0914',\n      number: 'INV-2026-0914',\n      status: 'failed',\n    },\n    {\n      amount: 588,\n      date: invoiceDate(7, 14),\n      description: 'Growth',\n      detail: 'Aug 14 – Sep 14',\n      href: '#in_0871',\n      id: 'in_0871',\n      number: 'INV-2026-0871',\n      status: 'overdue',\n    },\n    {\n      amount: 604.5,\n      date: invoiceDate(6, 14),\n      description: 'Growth',\n      detail: 'Jul 14 – Aug 14',\n      href: '#in_0813',\n      id: 'in_0813',\n      number: 'INV-2026-0813',\n      status: 'paid',\n    },\n    {\n      amount: 541.2,\n      date: invoiceDate(5, 14),\n      description: 'Growth',\n      detail: 'Jun 14 – Jul 14',\n      href: '#in_0760',\n      id: 'in_0760',\n      number: 'INV-2026-0760',\n      status: 'paid',\n    },\n  ],\n  onDownload: () => {},\n  title: 'Invoices',\n}\n\nconst Billing3 = (props: Billing3Props) => {\n  const {\n    currency = 'USD',\n    description: givenDescription,\n    invoices = [],\n    onDownload,\n    onViewAll,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, invoices)\n  const outstanding = getOutstandingInvoices(invoices)\n  const money = (value: number) => formatCurrency(value, { currency, precision: 'exact' })\n  const description = givenDescription ?? describeOutstanding(outstanding, money)\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 items-start justify-between gap-3'>\n              <div className='flex min-w-0 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              </div>\n              {onViewAll && (\n                <Button variant='outline' size='sm' onClick={onViewAll}>\n                  View all\n                  <IconPlaceholder\n                    lucide='ArrowRightIcon'\n                    tabler='IconArrowRight'\n                    hugeicons='ArrowRight01Icon'\n                    phosphor='ArrowRightIcon'\n                    remixicon='RiArrowRightLine'\n                    data-icon='inline-end'\n                  />\n                </Button>\n              )}\n            </header>\n            <DataTable caption={state ? title : `${title}: ${description}`}>\n              <DataTableHeader>\n                <DataTableRow>\n                  <DataTableHead>Invoice</DataTableHead>\n                  <DataTableHead>Date</DataTableHead>\n                  <DataTableHead align='end'>Amount</DataTableHead>\n                  <DataTableHead>Status</DataTableHead>\n                  {onDownload && (\n                    <DataTableHead align='end'>\n                      <span className='sr-only'>Download</span>\n                    </DataTableHead>\n                  )}\n                </DataTableRow>\n              </DataTableHeader>\n              <DataTableBody>\n                <DataTableStateRows colSpan={onDownload ? 5 : 4} />\n                {!state &&\n                  invoices.map((invoice) => (\n                    <DataTableRow key={invoice.id}>\n                      <DataTableCell primary truncate>\n                        {invoice.href ? (\n                          <DataTableRowLink\n                            aria-label={`${invoice.description}, ${invoice.number}`}\n                            className='block'\n                            href={invoice.href}\n                          >\n                            {invoice.description}\n                          </DataTableRowLink>\n                        ) : (\n                          <span className='block truncate'>{invoice.description}</span>\n                        )}\n                        <Details className='text-muted-foreground block truncate text-xs font-normal tabular-nums'>\n                          {invoice.number}\n                          {invoice.detail}\n                        </Details>\n                      </DataTableCell>\n                      <DataTableCell className='text-muted-foreground whitespace-nowrap'>\n                        <time dateTime={invoice.date.toISOString()}>\n                          {formatBillingDate(invoice.date)}\n                        </time>\n                      </DataTableCell>\n                      <DataTableCell align='end'>{money(invoice.amount)}</DataTableCell>\n                      <DataTableCell>\n                        <InvoiceStatusLabel status={invoice.status} />\n                      </DataTableCell>\n                      {onDownload && (\n                        <DataTableCell align='end'>\n                          <Button\n                            variant='ghost'\n                            size='sm'\n                            onClick={() => onDownload(invoice.id)}\n                          >\n                            <IconPlaceholder\n                              lucide='DownloadIcon'\n                              tabler='IconDownload'\n                              hugeicons='Download01Icon'\n                              phosphor='DownloadIcon'\n                              remixicon='RiDownloadLine'\n                              aria-hidden\n                            />\n                            <span className='sr-only'>Download </span>\n                            PDF\n                            <span className='sr-only'> for {invoice.number}</span>\n                          </Button>\n                        </DataTableCell>\n                      )}\n                    </DataTableRow>\n                  ))}\n              </DataTableBody>\n            </DataTable>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nfunction describeOutstanding(\n  { amount, count, oldest }: ReturnType<typeof getOutstandingInvoices>,\n  money: (value: number) => string,\n) {\n  if (count === 0 || !oldest) return 'Every invoice is paid.'\n  if (count === 1) {\n    return `${money(amount)} outstanding on the invoice from ${formatBillingDate(oldest.date)}.`\n  }\n  return `${money(amount)} outstanding across ${count} invoices, the oldest from ${formatBillingDate(oldest.date)}.`\n}\n\nexport { Billing3, exampleProps as billing3ExampleProps, type Billing3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/billing/billing-03.tsx"
    }
  ],
  "meta": {
    "shows": "Recent invoices with their status and amount, what is outstanding and a PDF download for each one.",
    "size": "half",
    "usedWith": [
      "billing-02",
      "billing-05"
    ],
    "component": "Billing3",
    "props": "{ currency?: string; description?: string; invoices?: { amount: number; date: Date; description: string; detail?: string; href?: string; id: string; number: string; status: \"failed\" | \"paid\" | \"draft\" | \"due\" | \"granted\" | \"overdue\" | \"partly-paid\" | \"scheduled\" | \"sent\" | \"uncollectible\" | \"viewed\" | \"void\" }[]; onDownload?: (id: string) => void; onViewAll?: () => void; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
