{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "invoice-02",
  "description": "A paid receipt with the payment method, a partial refund and the net amount paid.",
  "registryDependencies": [
    "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/invoice.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/invoice/invoice-02.tsx",
      "content": "'use client'\n\nimport {\n  InvoiceStatusLabel,\n  formatBillingDate,\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  DocumentBrand,\n  DocumentFooter,\n  DocumentHeader,\n  DocumentHeadline,\n  DocumentLayout,\n  DocumentMeta,\n  DocumentPage,\n  DocumentSection,\n  DocumentSummary,\n  DocumentToolbar,\n  DocumentTotals,\n  type DocumentLine,\n  type DocumentTotalRow,\n  LineItemsTable,\n  PrintButton,\n  formatDocumentAmount,\n  getCurrencyDigits,\n  getDocumentTotals,\n  getTotalRows,\n  toMinorUnits,\n} from '@/registry/components/dashboardblocks/invoice'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { startTransition, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\n\ninterface Refund {\n  amount: number\n  date: Date\n  reason: string\n}\n\ninterface Invoice2Props extends BlockStateProps {\n  brand: { name: string; website: string }\n  /** @default 'USD' */\n  currency?: string\n  email: string\n  /** Facts about the sender, printed at the foot of the page. */\n  footer: string[]\n  /** Leave out, or pass none, to show the empty state. */\n  lines?: DocumentLine[]\n  number: string\n  onDownload?: () => void\n  onEmail?: () => Promise<void>\n  orderNumber: string\n  paidAt: Date\n  paymentMethod: string\n  refunds: Refund[]\n  shipping?: number\n  shippingMethod: string\n  supportEmail: string\n  taxRate?: number\n}\n\nconst exampleProps: Invoice2Props = {\n  brand: { name: 'Fernhill Coffee Roasters', website: 'fernhill.coffee' },\n  email: 'maya.okafor@fastmail.com',\n  footer: ['Fernhill Coffee Roasters LLC', '1180 Folsom Street, San Francisco, CA 94103'],\n  lines: [\n    {\n      description: 'Ethiopia Guji, whole bean',\n      detail: '340 g, not taxed',\n      id: 'guji',\n      quantity: 2,\n      taxRate: 0,\n      unitPrice: 21,\n    },\n    {\n      description: 'Stovetop gooseneck kettle',\n      detail: 'Matte black, 1 L',\n      id: 'kettle',\n      quantity: 1,\n      unitPrice: 56,\n    },\n    {\n      description: 'Ceramic pour-over dripper',\n      detail: 'Size 02, white',\n      id: 'dripper',\n      quantity: 1,\n      unitPrice: 28,\n    },\n    {\n      description: 'Paper filters',\n      detail: 'Size 02, pack of 100',\n      id: 'filters',\n      quantity: 2,\n      unitPrice: 7.5,\n    },\n  ],\n  number: 'RCPT-58210',\n  orderNumber: '#FH-20931',\n  paidAt: new Date(Date.UTC(2026, 8, 14, 17, 42)),\n  paymentMethod: 'Visa •••• 4242',\n  refunds: [\n    {\n      amount: 60.06,\n      date: new Date(Date.UTC(2026, 8, 22)),\n      reason: 'Kettle returned',\n    },\n  ],\n  shipping: 8.95,\n  shippingMethod: 'USPS Priority Mail',\n  supportEmail: 'orders@fernhill.coffee',\n  taxRate: 0.0725,\n}\n\nfunction emailReceipt() {\n  return new Promise<void>((resolve) => setTimeout(resolve, 600))\n}\n\nconst logo = (\n  <svg viewBox='0 0 36 36' fill='none' aria-hidden>\n    <circle cx='18' cy='18' r='17' stroke='currentColor' strokeWidth='2' />\n    <path\n      d='M18 8c-5 4-5 16 0 20M18 8c5 4 5 16 0 20'\n      stroke='currentColor'\n      strokeWidth='2'\n      strokeLinecap='round'\n    />\n  </svg>\n)\n\nconst Invoice2 = (props: Invoice2Props) => {\n  const {\n    brand,\n    currency = 'USD',\n    email,\n    footer,\n    lines = [],\n    number,\n    onDownload = () => {},\n    onEmail = emailReceipt,\n    orderNumber,\n    paidAt,\n    paymentMethod,\n    refunds,\n    shipping,\n    shippingMethod,\n    errorMessage,\n    status,\n    supportEmail,\n    taxRate,\n  } = props\n  const state = getBlockState(status, lines)\n  const [emailState, setEmailState] = useState<'idle' | 'sending' | 'sent'>('idle')\n  const amounts = getDocumentTotals(lines, { currency, shipping, taxRate })\n  const unit = 10 ** getCurrencyDigits(currency)\n  const refunded =\n    refunds.reduce((sum, refund) => sum + toMinorUnits(refund.amount, currency), 0) / unit\n  const netPaid =\n    (toMinorUnits(amounts.total, currency) - toMinorUnits(refunded, currency)) / unit\n\n  const rows: DocumentTotalRow[] = [\n    ...getTotalRows(amounts).map((row) =>\n      row.id === 'total' ? { ...row, emphasis: 'total' as const } : row,\n    ),\n    ...refunds.map((refund, index) => ({\n      id: `refund-${index}`,\n      label: (\n        <>\n          Refunded {formatBillingDate(refund.date)}\n          <span className='block text-xs'>{refund.reason}</span>\n        </>\n      ),\n      value: -refund.amount,\n    })),\n  ]\n  if (refunds.length > 0) {\n    rows.push({ emphasis: 'due', id: 'net', label: 'Net paid', value: netPaid })\n  }\n\n  const sendEmail = async () => {\n    setEmailState('sending')\n    try {\n      await onEmail()\n      startTransition(() => setEmailState('sent'))\n    } catch {\n      startTransition(() => setEmailState('idle'))\n    }\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <DocumentLayout className='max-w-md'>\n        <DocumentToolbar\n          description={\n            <p role='status' className={emailState === 'sent' ? undefined : 'sr-only'}>\n              {emailState === 'sent' ? `Sent to ${email}` : ''}\n            </p>\n          }\n        >\n          <PrintButton />\n          <Button variant='outline' size='sm' disabled={!!state} onClick={onDownload}>\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          </Button>\n          <Button\n            variant='outline'\n            size='sm'\n            disabled={!!state || emailState === 'sending'}\n            onClick={sendEmail}\n          >\n            <IconPlaceholder\n              lucide='MailIcon'\n              tabler='IconMail'\n              hugeicons='MailIcon'\n              phosphor='EnvelopeIcon'\n              remixicon='RiMailLine'\n              aria-hidden\n            />\n            {emailState === 'sending' ? 'Sending' : 'Email'}\n          </Button>\n        </DocumentToolbar>\n        <DocumentPage>\n          <DocumentHeader\n            brand={<DocumentBrand logo={logo} name={brand.name} detail={brand.website} />}\n            title='Receipt'\n            number={number}\n            status={\n              <Details>\n                <InvoiceStatusLabel variant='text' status='paid' />\n                {refunded > 0 && (\n                  <StatusLabel variant='text' tone='neutral'>\n                    {refunded >= amounts.total ? 'Refunded' : 'Partially refunded'}\n                  </StatusLabel>\n                )}\n              </Details>\n            }\n          />\n          <DocumentSummary>\n            <DocumentHeadline\n              label='Amount paid'\n              value={formatDocumentAmount(amounts.total, currency)}\n            >\n              {refunded > 0 ? (\n                <>\n                  <span className='tabular-nums'>\n                    {formatDocumentAmount(refunded, currency)}\n                  </span>{' '}\n                  refunded, so you paid{' '}\n                  <span className='text-foreground font-medium tabular-nums'>\n                    {formatDocumentAmount(netPaid, currency)}\n                  </span>\n                  .\n                </>\n              ) : (\n                `Paid with ${paymentMethod}.`\n              )}\n            </DocumentHeadline>\n            <DocumentMeta\n              items={[\n                { label: 'Date paid', value: formatBillingDate(paidAt) },\n                { label: 'Order', value: orderNumber },\n                { label: 'Payment method', value: paymentMethod },\n                { label: 'Shipping', value: shippingMethod },\n              ]}\n            />\n          </DocumentSummary>\n          {state !== 'empty' && state !== 'error' && (\n            <>\n              <div className='flex flex-col gap-6'>\n                <LineItemsTable currency={currency} lines={lines} />\n                <DocumentTotals className='max-w-none' currency={currency} rows={rows} />\n              </div>\n              <DocumentSection title='Questions about your order?'>\n                <BlockReady>\n                  <p className='text-muted-foreground'>\n                    Reply to your receipt email or write to{' '}\n                    <a\n                      href={`mailto:${supportEmail}`}\n                      className='text-foreground underline underline-offset-4'\n                    >\n                      {supportEmail}\n                    </a>\n                    . Returns are free within 30 days.\n                  </p>\n                </BlockReady>\n              </DocumentSection>\n            </>\n          )}\n          <DocumentFooter parts={footer} />\n        </DocumentPage>\n      </DocumentLayout>\n    </BlockStateProvider>\n  )\n}\n\nexport { Invoice2, exampleProps as invoice2ExampleProps, type Invoice2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/invoice/invoice-02.tsx"
    }
  ],
  "meta": {
    "shows": "A paid receipt with the payment method, a partial refund and the net amount paid.",
    "size": "full",
    "usedWith": [
      "invoice-01",
      "billing-02"
    ],
    "component": "Invoice2",
    "props": "{ brand: { name: string; website: string }; currency?: string; email: string; footer: string[]; lines?: { detail?: string; description: string; id: string; optional?: boolean; quantity: number; sku?: string; taxRate?: number; unit?: string; unitPrice: number }[]; number: string; onDownload?: () => void; onEmail?: () => Promise<void>; orderNumber: string; paidAt: Date; paymentMethod: string; refunds: { amount: number; date: Date; reason: string }[]; shipping?: number; shippingMethod: string; supportEmail: string; taxRate?: number; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
