{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "invoice-03",
  "description": "A quote with optional items to tick before accepting, totals that follow and an expiry date.",
  "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/invoice.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/invoice/invoice-03.tsx",
      "content": "'use client'\n\nimport {\n  formatBillingDate,\n  getDaysUntil,\n} from '@/registry/components/dashboardblocks/billing'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  DocumentBrand,\n  DocumentFooter,\n  DocumentHeader,\n  DocumentHeadline,\n  DocumentLayout,\n  DocumentMeta,\n  DocumentPage,\n  DocumentParties,\n  DocumentSection,\n  DocumentSummary,\n  DocumentToolbar,\n  DocumentTotals,\n  type DocumentLine,\n  type DocumentParty,\n  LineItemsTable,\n  PrintButton,\n  formatDocumentAmount,\n  formatRate,\n  getDocumentTotals,\n  getTotalRows,\n} from '@/registry/components/dashboardblocks/invoice'\nimport {\n  StatusLabel,\n  type StatusTone,\n} 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\ntype QuoteDecision = 'accepted' | 'declined'\n\ntype QuoteStatus = QuoteDecision | 'expired' | 'open'\n\nconst quoteStatusConfig: Record<QuoteStatus, { label: string; tone: StatusTone }> = {\n  accepted: { label: 'Accepted', tone: 'good' },\n  declined: { label: 'Declined', tone: 'neutral' },\n  expired: { label: 'Expired', tone: 'neutral' },\n  open: { label: 'Awaiting response', tone: 'info' },\n}\n\ninterface Invoice3Props extends BlockStateProps {\n  brand: { name: string; website: string }\n  /** @default 'USD' */\n  currency?: string\n  defaultSelected?: string[]\n  /** A share off the subtotal, 0.1 for 10%. */\n  discountRate?: number\n  expiresAt: Date\n  /** Facts about the sender, printed at the foot of the page. */\n  footer: string[]\n  from: DocumentParty\n  issueDate: Date\n  /** Lines marked `optional` get a checkbox to include them. Leave out, or pass none, to show the empty state. */\n  lines?: DocumentLine[]\n  notes: string\n  /** Pass a fixed date, so the days left render the same on the server and in the browser. */\n  now: Date\n  number: string\n  onAccept?: (selected: string[]) => Promise<void>\n  onDecline?: () => Promise<void>\n  preparedBy: string\n  preparedFor: DocumentParty\n  terms: string\n}\n\nconst exampleProps: Invoice3Props = {\n  brand: { name: 'Kestrel Analytics', website: 'kestrel.io' },\n  defaultSelected: ['migration'],\n  discountRate: 0.1,\n  expiresAt: new Date(Date.UTC(2026, 9, 12)),\n  footer: ['Kestrel Analytics, Inc.', '88 Pine Street, Suite 1400, New York, NY 10005'],\n  from: {\n    label: 'From',\n    lines: ['88 Pine Street, Suite 1400', 'New York, NY 10005', 'sales@kestrel.io'],\n    name: 'Kestrel Analytics, Inc.',\n  },\n  issueDate: new Date(Date.UTC(2026, 8, 12)),\n  lines: [\n    {\n      description: 'Kestrel Business, annual licence',\n      detail: 'Oct 1, 2026 – Sep 30, 2027',\n      id: 'licence',\n      quantity: 25,\n      unit: 'seats',\n      unitPrice: 540,\n    },\n    {\n      description: 'Implementation and onboarding',\n      detail: 'Six weeks with a named solutions engineer',\n      id: 'implementation',\n      quantity: 1,\n      unitPrice: 4800,\n    },\n    {\n      description: 'Salesforce and NetSuite connectors',\n      id: 'connectors',\n      quantity: 2,\n      unitPrice: 1200,\n    },\n    {\n      description: 'Historical data migration',\n      detail: 'Up to five years of shipment and billing data',\n      id: 'migration',\n      optional: true,\n      quantity: 1,\n      unitPrice: 2200,\n    },\n    {\n      description: 'Admin training',\n      detail: 'Remote sessions for up to 12 people',\n      id: 'training',\n      optional: true,\n      quantity: 2,\n      unit: 'sessions',\n      unitPrice: 650,\n    },\n    {\n      description: 'Premium support, annual',\n      detail: '1-hour response around the clock',\n      id: 'support',\n      optional: true,\n      quantity: 1,\n      unitPrice: 3000,\n    },\n  ],\n  notes:\n    'Prices include the 10% discount for paying the first year up front. Seats can be added at any time at the same rate, prorated.',\n  now: new Date(Date.UTC(2026, 8, 27, 12)),\n  number: 'Q-2026-0318',\n  preparedBy: 'Daniel Osei',\n  preparedFor: {\n    label: 'Prepared for',\n    lines: ['Attn: Hannah Lindqvist, COO', '410 Terminal Way', 'Savannah, GA 31401'],\n    name: 'Marlow Freight Co.',\n  },\n  terms:\n    'Tax is added at invoicing. The licence is invoiced on acceptance, services when they start. Net 30.',\n}\n\nfunction respond() {\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    <path\n      d='M4 26 18 6l14 20H4Z'\n      stroke='currentColor'\n      strokeWidth='2'\n      strokeLinejoin='round'\n    />\n    <path d='M11 26 18 16l7 10' stroke='currentColor' strokeWidth='2' />\n  </svg>\n)\n\nconst Invoice3 = (props: Invoice3Props) => {\n  const {\n    brand,\n    currency = 'USD',\n    defaultSelected = [],\n    discountRate,\n    expiresAt,\n    footer,\n    from,\n    issueDate,\n    lines = [],\n    notes,\n    now,\n    number,\n    onAccept = respond,\n    onDecline = respond,\n    preparedBy,\n    preparedFor,\n    errorMessage,\n    status: blockStatus,\n    terms,\n  } = props\n  const state = getBlockState(blockStatus, lines)\n  const [selected, setSelected] = useState(defaultSelected)\n  const [decision, setDecision] = useState<QuoteDecision | null>(null)\n  const [pending, setPending] = useState<QuoteDecision | null>(null)\n\n  const included = lines.filter((line) => !line.optional || selected.includes(line.id))\n  const amounts = getDocumentTotals(included, { currency, discountRate })\n  const total = formatDocumentAmount(amounts.total, currency)\n  const options = lines.filter((line) => line.optional)\n  const daysLeft = getDaysUntil(expiresAt, now)\n  const expired = daysLeft < 0\n  const status: QuoteStatus = decision ?? (expired ? 'expired' : 'open')\n\n  const decide = async (next: QuoteDecision) => {\n    setPending(next)\n    try {\n      await (next === 'accepted' ? onAccept(selected) : onDecline())\n      startTransition(() => {\n        setDecision(next)\n        setPending(null)\n      })\n    } catch {\n      startTransition(() => {\n        setDecision(null)\n        setPending(null)\n      })\n    }\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <DocumentLayout>\n        <DocumentToolbar\n          description={\n            <p role='status'>\n              <BlockReady className='text-sm'>\n                {decision === 'accepted'\n                  ? `Accepted with ${selected.length} of ${options.length} options, ${total} in total`\n                  : decision === 'declined'\n                    ? 'Quote declined. We’ll let the sender know.'\n                    : `${selected.length} of ${options.length} options included`}\n              </BlockReady>\n            </p>\n          }\n        >\n          <PrintButton />\n          {decision ? (\n            <Button variant='outline' size='sm' onClick={() => setDecision(null)}>\n              <IconPlaceholder\n                lucide='Undo2Icon'\n                tabler='IconArrowBackUp'\n                hugeicons='Undo02Icon'\n                phosphor='ArrowUUpLeftIcon'\n                remixicon='RiArrowGoBackLine'\n                aria-hidden\n              />\n              Undo\n            </Button>\n          ) : (\n            !expired && (\n              <>\n                <Button\n                  variant='outline'\n                  size='sm'\n                  disabled={!!state || pending !== null}\n                  onClick={() => decide('declined')}\n                >\n                  {pending === 'declined' ? 'Declining' : 'Decline'}\n                </Button>\n                <Button\n                  size='sm'\n                  disabled={!!state || pending !== null}\n                  onClick={() => decide('accepted')}\n                >\n                  <IconPlaceholder\n                    lucide='CheckIcon'\n                    tabler='IconCheck'\n                    hugeicons='Tick02Icon'\n                    phosphor='CheckIcon'\n                    remixicon='RiCheckLine'\n                    aria-hidden\n                  />\n                  {pending === 'accepted'\n                    ? 'Accepting'\n                    : state\n                      ? 'Accept'\n                      : `Accept for ${total}`}\n                </Button>\n              </>\n            )\n          )}\n        </DocumentToolbar>\n        <DocumentPage>\n          <DocumentHeader\n            brand={<DocumentBrand logo={logo} name={brand.name} detail={brand.website} />}\n            title='Quote'\n            number={number}\n            status={\n              <StatusLabel tone={quoteStatusConfig[status].tone}>\n                {quoteStatusConfig[status].label}\n              </StatusLabel>\n            }\n          />\n          <DocumentSummary>\n            <DocumentHeadline label='Total' value={total}>\n              {discountRate ? `After the ${formatRate(discountRate)} discount. ` : null}\n              {expired\n                ? `Expired on ${formatBillingDate(expiresAt)}.`\n                : daysLeft === 0\n                  ? 'Expires today.'\n                  : `Valid for ${daysLeft} more ${daysLeft === 1 ? 'day' : 'days'}.`}\n            </DocumentHeadline>\n            <DocumentMeta\n              items={[\n                { label: 'Issued', value: formatBillingDate(issueDate) },\n                { label: 'Valid until', value: formatBillingDate(expiresAt) },\n                { label: 'Prepared by', value: preparedBy },\n              ]}\n            />\n          </DocumentSummary>\n          {state !== 'empty' && state !== 'error' && (\n            <>\n              <DocumentParties parties={[from, preparedFor]} />\n              <div className='flex flex-col gap-6'>\n                <LineItemsTable\n                  currency={currency}\n                  lines={decision ? included : lines}\n                  selection={\n                    decision\n                      ? undefined\n                      : {\n                          isSelectable: (line) => Boolean(line.optional),\n                          label: (line) => `Include ${line.description}`,\n                          onChange: (id, isSelected) =>\n                            setSelected((current) =>\n                              isSelected\n                                ? [...current, id]\n                                : current.filter((item) => item !== id),\n                            ),\n                          selected,\n                        }\n                  }\n                />\n                <DocumentTotals\n                  currency={currency}\n                  rows={getTotalRows(amounts, {\n                    discount: discountRate\n                      ? `Prepay discount (${formatRate(discountRate)})`\n                      : undefined,\n                  })}\n                />\n              </div>\n              <div className='grid gap-8 border-t pt-8 @xl/document:grid-cols-2 print:grid-cols-2'>\n                <DocumentSection title='Notes'>\n                  <BlockReady>\n                    <p className='text-muted-foreground text-pretty'>{notes}</p>\n                  </BlockReady>\n                </DocumentSection>\n                <DocumentSection title='Terms'>\n                  <BlockReady>\n                    <p className='text-muted-foreground text-pretty'>{terms}</p>\n                  </BlockReady>\n                </DocumentSection>\n              </div>\n              {!decision && (\n                <DocumentSection title='Acceptance' className='hidden print:flex'>\n                  <p className='text-muted-foreground'>\n                    Sign and return to accept this quote with the options ticked above.\n                  </p>\n                  <div className='mt-8 grid grid-cols-3 gap-6'>\n                    {['Name', 'Signature', 'Date'].map((label) => (\n                      <span\n                        key={label}\n                        className='border-foreground border-t pt-1.5 text-xs'\n                      >\n                        {label}\n                      </span>\n                    ))}\n                  </div>\n                </DocumentSection>\n              )}\n            </>\n          )}\n          <DocumentFooter parts={footer} />\n        </DocumentPage>\n      </DocumentLayout>\n    </BlockStateProvider>\n  )\n}\n\nexport { Invoice3, exampleProps as invoice3ExampleProps, type Invoice3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/invoice/invoice-03.tsx"
    }
  ],
  "meta": {
    "shows": "A quote with optional items to tick before accepting, totals that follow and an expiry date.",
    "size": "full",
    "usedWith": [
      "invoice-01",
      "billing-01"
    ],
    "component": "Invoice3",
    "props": "{ brand: { name: string; website: string }; currency?: string; defaultSelected?: string[]; discountRate?: number; expiresAt: Date; footer: string[]; from: { label: string; lines: string[]; name: string }; issueDate: Date; lines?: { detail?: string; description: string; id: string; optional?: boolean; quantity: number; sku?: string; taxRate?: number; unit?: string; unitPrice: number }[]; notes: string; now: Date; number: string; onAccept?: (selected: string[]) => Promise<void>; onDecline?: () => Promise<void>; preparedBy: string; preparedFor: { label: string; lines: string[]; name: string }; terms: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
