{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billing-02",
  "description": "The current plan and its price, when it renews, the next invoice and the payment method on file, with actions to manage them.",
  "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/kpi.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/billing/billing-02.tsx",
      "content": "'use client'\n\nimport {\n  formatBillingDate,\n  formatDaysUntil,\n  getDaysUntil,\n} from '@/registry/components/dashboardblocks/billing'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  SkeletonText,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCurrency } from '@/registry/lib/dashboardblocks/format'\nimport { type ReactNode, useTransition } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface PaymentMethod {\n  brand: string\n  expires: string\n  last4: string\n}\n\ninterface Billing2Props extends BlockStateProps {\n  cancelsAtPeriodEnd?: boolean\n  /** @default 'USD' */\n  currency?: string\n  interval: 'month' | 'year'\n  nextInvoiceAmount?: number\n  now: Date\n  /** Opens where the plan is changed, such as your payment provider's billing page. A promise shows Opening until it settles; show its errors yourself. */\n  onManage?: () => void | Promise<void>\n  /** Opens where the card is changed. A promise shows Opening until it settles. */\n  onUpdatePaymentMethod?: () => void | Promise<void>\n  /** A renewal that wasn't paid, as your payment provider's `past_due`: what's owed and when the charge failed. */\n  pastDue?: { amount: number; failedOn: Date }\n  paymentMethod?: PaymentMethod\n  plan?: string\n  /** Leave out to show the empty state. */\n  price?: number\n  renewsAt: Date\n  summary?: string\n  title: string\n}\n\nconst NOW = Date.UTC(2026, 8, 26, 12, 0)\n\ninterface OpenButtonProps {\n  children: ReactNode\n  icon?: ReactNode\n  onOpen?: () => void | Promise<void>\n  unavailable?: boolean\n  variant: 'default' | 'ghost' | 'outline'\n}\n\nfunction OpenButton({ children, icon, onOpen, unavailable, variant }: OpenButtonProps) {\n  const [pending, startOpening] = useTransition()\n  return (\n    <Button\n      type='button'\n      variant={variant}\n      size='sm'\n      disabled={unavailable}\n      className='aria-disabled:opacity-50'\n      aria-disabled={pending ? true : undefined}\n      onClick={() => {\n        if (pending) return\n        startOpening(async () => {\n          try {\n            await onOpen?.()\n          } catch {\n            // React sends an error thrown in a transition to the error boundary, which replaces the page.\n          }\n        })\n      }}\n    >\n      {icon}\n      {pending ? 'Opening' : children}\n    </Button>\n  )\n}\n\nconst exampleProps: Billing2Props = {\n  interval: 'month',\n  nextInvoiceAmount: 612,\n  now: new Date(NOW),\n  paymentMethod: { brand: 'Visa', expires: '08/2028', last4: '4242' },\n  plan: 'Growth',\n  price: 588,\n  renewsAt: new Date(Date.UTC(2026, 9, 14)),\n  summary: '12 seats at $49 each, plus usage',\n  title: 'Current plan',\n}\n\nconst Billing2 = (props: Billing2Props) => {\n  const {\n    cancelsAtPeriodEnd = false,\n    currency = 'USD',\n    interval,\n    nextInvoiceAmount,\n    now,\n    onManage,\n    onUpdatePaymentMethod,\n    pastDue,\n    paymentMethod,\n    plan,\n    price = 0,\n    renewsAt,\n    errorMessage,\n    status,\n    summary,\n    title,\n  } = props\n  const state = getBlockState(status, props.price)\n  const unavailable = status !== undefined\n  const days = getDaysUntil(renewsAt, now)\n  const renewal = formatBillingDate(renewsAt)\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-wrap items-start justify-between gap-3'>\n              <div className='flex min-w-0 flex-1 basis-56 flex-col gap-0.5'>\n                <h2 className='font-semibold tracking-tight'>{title}</h2>\n                <BlockReady className='text-sm'>\n                  <Details className='text-muted-foreground block text-sm'>\n                    <StatusLabel\n                      variant='text'\n                      tone={pastDue ? 'bad' : cancelsAtPeriodEnd ? 'warning' : 'good'}\n                    >\n                      {pastDue ? 'Past due' : cancelsAtPeriodEnd ? 'Cancels' : 'Active'}\n                    </StatusLabel>\n                    {pastDue ? (\n                      <span>Payment failed {formatBillingDate(pastDue.failedOn)}</span>\n                    ) : (\n                      <span>\n                        {cancelsAtPeriodEnd ? 'Ends' : 'Renews'} {formatDaysUntil(days)}\n                      </span>\n                    )}\n                  </Details>\n                </BlockReady>\n              </div>\n              <div className='flex shrink-0 gap-2'>\n                <OpenButton\n                  variant={pastDue && !unavailable ? 'default' : 'ghost'}\n                  unavailable={unavailable}\n                  icon={\n                    <IconPlaceholder\n                      lucide='CreditCardIcon'\n                      tabler='IconCreditCard'\n                      hugeicons='CreditCardIcon'\n                      phosphor='CreditCardIcon'\n                      remixicon='RiBankCardLine'\n                      data-icon='inline-start'\n                    />\n                  }\n                  onOpen={onUpdatePaymentMethod}\n                >\n                  {paymentMethod ? 'Update card' : 'Add a card'}\n                </OpenButton>\n                <OpenButton variant='outline' unavailable={unavailable} onOpen={onManage}>\n                  Manage\n                </OpenButton>\n              </div>\n            </header>\n            <div className='flex flex-col gap-1 border-t pt-4'>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{plan}</p>\n              </BlockReady>\n              {state ? (\n                <KPIValue />\n              ) : (\n                <p className='text-4xl font-light tracking-tight tabular-nums'>\n                  {formatCurrency(price, { currency })}\n                  <span className='text-muted-foreground ml-1 text-base font-normal tracking-normal'>\n                    / {interval}\n                  </span>\n                </p>\n              )}\n              {summary && (\n                <BlockReady className='text-sm'>\n                  <p className='text-muted-foreground text-sm'>{summary}</p>\n                </BlockReady>\n              )}\n            </div>\n            {state !== 'empty' && state !== 'error' && (\n              <dl className='grid gap-x-6 gap-y-4 border-t pt-4 @md:grid-cols-3'>\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>\n                    {cancelsAtPeriodEnd ? 'Ends on' : 'Renews on'}\n                  </dt>\n                  <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                    {state ? (\n                      <SkeletonText className='w-[4em]' />\n                    ) : (\n                      <time dateTime={renewsAt.toISOString()}>{renewal}</time>\n                    )}\n                  </dd>\n                </div>\n                {!cancelsAtPeriodEnd && (\n                  <div className='flex flex-col gap-0.5'>\n                    <dt className='text-muted-foreground text-sm'>\n                      {pastDue ? 'Amount due' : 'Next invoice'}\n                    </dt>\n                    <dd>\n                      <KPIValue\n                        className='text-2xl'\n                        value={pastDue?.amount ?? nextInvoiceAmount ?? price}\n                        format={(value) =>\n                          formatCurrency(value, { currency, precision: 'exact' })\n                        }\n                      />\n                    </dd>\n                    {!pastDue && (\n                      <dd className='text-muted-foreground text-xs'>\n                        <BlockReady className='text-xs'>Before tax</BlockReady>\n                      </dd>\n                    )}\n                  </div>\n                )}\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>Payment method</dt>\n                  <dd className='text-2xl font-light tracking-tight whitespace-nowrap tabular-nums'>\n                    {state ? (\n                      <SkeletonText className='w-[5em]' />\n                    ) : paymentMethod ? (\n                      <>\n                        {paymentMethod.brand} <span aria-hidden>•••• </span>\n                        <span className='sr-only'>ending in </span>\n                        {paymentMethod.last4}\n                      </>\n                    ) : (\n                      'None on file'\n                    )}\n                  </dd>\n                  {paymentMethod && (\n                    <dd className='text-muted-foreground text-xs tabular-nums'>\n                      <BlockReady className='text-xs'>\n                        Expires {paymentMethod.expires}\n                      </BlockReady>\n                    </dd>\n                  )}\n                </div>\n              </dl>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Billing2, exampleProps as billing2ExampleProps, type Billing2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/billing/billing-02.tsx"
    }
  ],
  "meta": {
    "shows": "The current plan and its price, when it renews, the next invoice and the payment method on file, with actions to manage them.",
    "size": "half",
    "usedWith": [
      "billing-03",
      "billing-05",
      "usage-meter-01"
    ],
    "component": "Billing2",
    "props": "{ cancelsAtPeriodEnd?: boolean; currency?: string; interval: \"month\" | \"year\"; nextInvoiceAmount?: number; now: Date; onManage?: () => void | Promise<void>; onUpdatePaymentMethod?: () => void | Promise<void>; pastDue?: { amount: number; failedOn: Date }; paymentMethod?: { brand: string; expires: string; last4: string }; plan?: string; price?: number; renewsAt: Date; summary?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
