{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billing-05",
  "description": "Plans side by side, monthly or yearly, with seats, what is due today and what a downgrade takes away.",
  "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/format.json",
    "https://www.dashboardblocks.com/r/radix/number-field.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/billing/billing-05.tsx",
      "content": "'use client'\n\nimport { formatBillingDate } from '@/registry/components/dashboardblocks/billing'\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { NumberField } from '@/registry/components/dashboardblocks/number-field'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCurrency, formatPercent } from '@/registry/lib/dashboardblocks/format'\nimport { useId, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\n\ntype BillingInterval = 'month' | 'year'\n\ninterface Plan {\n  description: string\n  features: string[]\n  highlight?: string\n  id: string\n  name: string\n  /** The price per seat per month, billed monthly and billed yearly. */\n  price?: Record<BillingInterval, number>\n}\n\ninterface PlanChange {\n  interval: BillingInterval\n  planId: string\n  seats: number\n}\n\ninterface Billing5Props extends BlockStateProps {\n  /** @default 'USD' */\n  currency?: string\n  current: PlanChange\n  description: string\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  onConfirm?: (change: PlanChange) => void\n  onContactSales?: (planId: string) => void\n  periodStart: Date\n  /** Leave out, or pass none, to show the empty state. */\n  plans?: Plan[]\n  renewsAt: Date\n  seatsInUse: number\n  title: string\n}\n\nconst exampleProps: Billing5Props = {\n  current: { interval: 'month', planId: 'growth', seats: 12 },\n  description: 'Pick a plan and the number of seats. Upgrades start today.',\n  now: new Date(Date.UTC(2026, 8, 26, 12, 0)),\n  periodStart: new Date(Date.UTC(2026, 8, 14)),\n  plans: [\n    {\n      description: 'For small teams getting started.',\n      features: ['5 dashboards', '3 data sources', '30 days of history', 'Email support'],\n      id: 'starter',\n      name: 'Starter',\n      price: { month: 19, year: 15 },\n    },\n    {\n      description: 'For teams that run on their data.',\n      features: [\n        'Unlimited dashboards',\n        '20 data sources',\n        '2 years of history',\n        'Scheduled reports',\n        'Email support',\n      ],\n      highlight: 'Most popular',\n      id: 'growth',\n      name: 'Growth',\n      price: { month: 49, year: 39 },\n    },\n    {\n      description: 'For companies with many teams.',\n      features: [\n        'Unlimited dashboards',\n        'Unlimited data sources',\n        'Unlimited history',\n        'Scheduled reports',\n        'SSO and audit log',\n        'Priority support',\n      ],\n      id: 'scale',\n      name: 'Scale',\n      price: { month: 89, year: 72 },\n    },\n    {\n      description: 'Custom contracts, security reviews and an account manager.',\n      features: ['Everything in Scale', 'Custom data retention', 'Uptime SLA'],\n      id: 'enterprise',\n      name: 'Enterprise',\n    },\n  ],\n  renewsAt: new Date(Date.UTC(2026, 9, 14)),\n  seatsInUse: 11,\n  title: 'Change plan',\n}\n\nfunction periodTotal(plan: Plan | undefined, interval: BillingInterval, seats: number) {\n  if (!plan?.price) return 0\n  return plan.price[interval] * seats * (interval === 'year' ? 12 : 1)\n}\n\nfunction addInterval(date: Date, interval: BillingInterval) {\n  const next = new Date(date)\n  if (interval === 'year') next.setUTCFullYear(next.getUTCFullYear() + 1)\n  else next.setUTCMonth(next.getUTCMonth() + 1)\n  return next\n}\n\nconst Billing5 = (props: Billing5Props) => {\n  const {\n    currency = 'USD',\n    current,\n    description,\n    now,\n    onConfirm,\n    onContactSales,\n    periodStart,\n    plans = [],\n    renewsAt,\n    seatsInUse,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, plans)\n  const id = useId()\n  const [active, setActive] = useState(current)\n  const [interval, setBillingInterval] = useState(current.interval)\n  const [planId, setPlanId] = useState(current.planId)\n  const [seats, setSeats] = useState(current.seats)\n  const [scheduled, setScheduled] = useState<PlanChange | null>(null)\n  const [confirmed, setConfirmed] = useState('')\n\n  const money = (value: number) => formatCurrency(value, { currency, precision: 'exact' })\n\n  const plan = plans.find((item) => item.id === planId)\n  const activePlan = plans.find((item) => item.id === active.planId)\n  const currentTotal = periodTotal(activePlan, active.interval, active.seats)\n  const nextTotal = periodTotal(plan, interval, seats)\n\n  const unchanged =\n    planId === active.planId && interval === active.interval && seats === active.seats\n  const remaining = Math.min(\n    1,\n    Math.max(\n      0,\n      (renewsAt.getTime() - now.getTime()) / (renewsAt.getTime() - periodStart.getTime()),\n    ),\n  )\n  const switchesToYearly = interval === 'year' && active.interval === 'month'\n  const upgrade =\n    !unchanged &&\n    (switchesToYearly || (interval === active.interval && nextTotal > currentTotal))\n  const dueToday = !upgrade\n    ? 0\n    : switchesToYearly\n      ? Math.max(0, nextTotal - currentTotal * remaining)\n      : (nextTotal - currentTotal) * remaining\n  const startsAt = upgrade ? now : renewsAt\n  const nextRenewal = switchesToYearly ? addInterval(now, 'year') : renewsAt\n  const isDowngrade =\n    !!plan?.price && !!activePlan?.price && plan.price.month < activePlan.price.month\n  const lost = isDowngrade\n    ? activePlan.features.filter((feature) => !plan.features.includes(feature))\n    : []\n  const isScheduled =\n    scheduled?.planId === planId &&\n    scheduled.interval === interval &&\n    scheduled.seats === seats\n\n  const setSeatCount = (value: number) => {\n    setSeats(Math.round(value))\n    setConfirmed('')\n  }\n\n  const action = unchanged\n    ? 'No changes'\n    : isScheduled\n      ? 'Scheduled'\n      : planId === active.planId\n        ? 'Update subscription'\n        : upgrade\n          ? `Upgrade to ${plan?.name}`\n          : `Switch to ${plan?.name}`\n\n  const yearlySaving = plan?.price\n    ? 1 - plan.price.year / plan.price.month\n    : plans.reduce(\n        (best, item) =>\n          item.price ? Math.max(best, 1 - item.price.year / item.price.month) : best,\n        0,\n      )\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\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-col gap-0.5'>\n            <h2 className='font-semibold tracking-tight'>{title}</h2>\n            <p className='text-muted-foreground text-sm'>{description}</p>\n          </div>\n          <fieldset\n            disabled={!!state}\n            className='bg-muted inline-flex w-fit shrink-0 gap-1 rounded-lg p-1 disabled:opacity-50'\n          >\n            <legend className='sr-only'>Billing period</legend>\n            {(['month', 'year'] as const).map((value) => (\n              <label\n                key={value}\n                className='has-checked:bg-background has-checked:text-foreground text-foreground/70 has-focus-visible:ring-ring/50 flex cursor-pointer items-center gap-1.5 rounded-md px-3 py-1 text-sm font-medium has-checked:shadow-sm has-focus-visible:ring-3'\n              >\n                <input\n                  type='radio'\n                  name={`${id}-interval`}\n                  value={value}\n                  checked={interval === value}\n                  onChange={() => {\n                    setBillingInterval(value)\n                    setConfirmed('')\n                  }}\n                  className='sr-only'\n                />\n                {value === 'month' ? 'Monthly' : 'Yearly'}\n                {value === 'year' && yearlySaving > 0 && (\n                  <span className='text-xs font-medium whitespace-nowrap text-emerald-700 dark:text-emerald-400'>\n                    Save {!plan?.price && 'up to '}\n                    {formatPercent(yearlySaving, { maximumFractionDigits: 0 })}\n                  </span>\n                )}\n              </label>\n            ))}\n          </fieldset>\n        </header>\n\n        {state ? (\n          <BlockStateRows className='border-t' rows={4} />\n        ) : (\n          <>\n            <fieldset className='border-t pt-4'>\n              <legend className='sr-only'>Plan</legend>\n              <div className='grid gap-3 @lg:grid-cols-2 @4xl:grid-cols-4'>\n                {plans.map((item) => {\n                  const isCurrent = item.id === active.planId\n                  return (\n                    <label\n                      key={item.id}\n                      className='has-checked:border-primary has-checked:ring-primary has-focus-visible:ring-ring/50 relative flex cursor-pointer flex-col gap-3 rounded-xl border p-4 has-checked:ring-1 has-focus-visible:ring-3'\n                    >\n                      <input\n                        type='radio'\n                        name={`${id}-plan`}\n                        value={item.id}\n                        checked={planId === item.id}\n                        onChange={() => {\n                          setPlanId(item.id)\n                          setConfirmed('')\n                        }}\n                        aria-describedby={`${id}-${item.id}-description`}\n                        className='sr-only'\n                      />\n                      <span className='flex flex-wrap items-baseline justify-between gap-x-2'>\n                        <span className='font-medium'>{item.name}</span>\n                        {isCurrent ? (\n                          <span className='text-muted-foreground text-xs'>\n                            Current plan\n                          </span>\n                        ) : scheduled?.planId === item.id ? (\n                          <span className='text-muted-foreground text-xs'>\n                            From {formatBillingDate(renewsAt)}\n                          </span>\n                        ) : (\n                          item.highlight && (\n                            <span className='text-muted-foreground text-xs'>\n                              {item.highlight}\n                            </span>\n                          )\n                        )}\n                      </span>\n                      <span className='flex items-baseline gap-1'>\n                        {item.price ? (\n                          <>\n                            <span className='text-3xl font-light tracking-tight tabular-nums'>\n                              {money(item.price[interval])}\n                            </span>\n                            <span className='text-muted-foreground text-xs'>\n                              per seat / month\n                              {interval === 'year' && ', billed yearly'}\n                            </span>\n                          </>\n                        ) : (\n                          <span className='text-3xl font-light tracking-tight'>\n                            Custom\n                          </span>\n                        )}\n                      </span>\n                      <span\n                        id={`${id}-${item.id}-description`}\n                        className='text-muted-foreground text-sm'\n                      >\n                        {item.description}\n                      </span>\n                      <ul className='flex flex-col gap-1.5 border-t pt-3 text-sm'>\n                        {item.features.map((feature) => (\n                          <li key={feature} className='flex items-start gap-2'>\n                            <IconPlaceholder\n                              lucide='CheckIcon'\n                              tabler='IconCheck'\n                              hugeicons='Tick02Icon'\n                              phosphor='CheckIcon'\n                              remixicon='RiCheckLine'\n                              aria-hidden\n                              className='text-muted-foreground mt-0.5 size-4 shrink-0'\n                            />\n                            {feature}\n                          </li>\n                        ))}\n                      </ul>\n                    </label>\n                  )\n                })}\n              </div>\n            </fieldset>\n\n            {plan?.price ? (\n              <div className='grid gap-6 border-t pt-4 @lg:grid-cols-2'>\n                <div className='flex flex-col gap-2'>\n                  <label htmlFor={`${id}-seats`} className='text-sm font-medium'>\n                    Seats\n                  </label>\n                  <NumberField\n                    id={`${id}-seats`}\n                    className='w-44'\n                    decrementLabel='Remove a seat'\n                    incrementLabel='Add a seat'\n                    min={seatsInUse}\n                    stepper\n                    unit='seats'\n                    value={seats}\n                    onValueChange={(value) => {\n                      if (value !== null) setSeatCount(value)\n                    }}\n                    aria-describedby={`${id}-seats-hint`}\n                  />\n                  <p id={`${id}-seats-hint`} className='text-muted-foreground text-sm'>\n                    {seatsInUse} in use by members and invites.\n                  </p>\n                </div>\n\n                <div className='flex flex-col gap-2'>\n                  <dl className='flex flex-col gap-2 text-sm'>\n                    <div className='flex justify-between gap-4'>\n                      <dt className='text-muted-foreground'>\n                        {plan.name}, {seats} {seats === 1 ? 'seat' : 'seats'}\n                      </dt>\n                      <dd className='font-medium tabular-nums'>\n                        {money(nextTotal)} / {interval}\n                      </dd>\n                    </div>\n                    {!unchanged && (\n                      <>\n                        <div className='flex justify-between gap-4'>\n                          <dt className='text-muted-foreground'>Now</dt>\n                          <dd className='tabular-nums'>\n                            {money(currentTotal)} / {active.interval}\n                          </dd>\n                        </div>\n                        <div className='flex items-baseline justify-between gap-4 border-t pt-2'>\n                          <dt className='font-medium'>Due today</dt>\n                          <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                            {money(Math.round(dueToday * 100) / 100)}\n                          </dd>\n                        </div>\n                      </>\n                    )}\n                  </dl>\n                  {!unchanged && (\n                    <p className='text-muted-foreground text-xs'>\n                      {upgrade ? (\n                        <>\n                          Starts today, with credit for the unused part of this period.\n                          Then {money(nextTotal)} on{' '}\n                          <time dateTime={nextRenewal.toISOString()}>\n                            {formatBillingDate(nextRenewal)}\n                          </time>\n                          .\n                        </>\n                      ) : (\n                        <>\n                          Starts on{' '}\n                          <time dateTime={startsAt.toISOString()}>\n                            {formatBillingDate(startsAt)}\n                          </time>\n                          , when this period ends. Nothing changes until then.\n                        </>\n                      )}{' '}\n                      Before tax.\n                    </p>\n                  )}\n                </div>\n              </div>\n            ) : (\n              <p className='text-muted-foreground border-t pt-4 text-sm'>\n                {plan?.name} is priced for your team. Talk to us about seats, contract\n                length and security reviews.\n              </p>\n            )}\n\n            {plan?.price && lost.length > 0 && !unchanged && (\n              <div className='flex gap-3 rounded-lg border border-orange-500/30 bg-orange-500/5 p-4 text-sm'>\n                <IconPlaceholder\n                  lucide='TriangleAlertIcon'\n                  tabler='IconAlertTriangle'\n                  hugeicons='Alert02Icon'\n                  phosphor='WarningIcon'\n                  remixicon='RiErrorWarningLine'\n                  aria-hidden\n                  className='mt-0.5 size-4 shrink-0 text-orange-700 dark:text-orange-400'\n                />\n                <div className='flex flex-col gap-1'>\n                  <p className='font-medium'>{plan.name} doesn’t include:</p>\n                  <ul className='text-muted-foreground list-disc pl-4'>\n                    {lost.map((feature) => (\n                      <li key={feature}>{feature}</li>\n                    ))}\n                  </ul>\n                </div>\n              </div>\n            )}\n          </>\n        )}\n        <footer className='flex flex-wrap items-center justify-end gap-2 border-t pt-4'>\n          <p role='status' className='text-muted-foreground mr-auto text-sm'>\n            {confirmed}\n          </p>\n          {plan?.price || state ? (\n            <Button\n              disabled={unchanged || isScheduled || !!state}\n              onClick={() => {\n                const change = { interval, planId, seats }\n                if (!plan) return\n                if (upgrade) {\n                  setActive(change)\n                  setScheduled(null)\n                  setConfirmed(`You’re on ${plan.name}.`)\n                } else {\n                  setScheduled(change)\n                  setConfirmed(`Changes on ${formatBillingDate(startsAt)}.`)\n                }\n                onConfirm?.(change)\n              }}\n            >\n              {action}\n            </Button>\n          ) : (\n            <Button onClick={() => plan && onContactSales?.(plan.id)}>\n              Contact sales\n            </Button>\n          )}\n        </footer>\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Billing5,\n  exampleProps as billing5ExampleProps,\n  type BillingInterval,\n  type Billing5Props,\n  type Plan,\n  type PlanChange,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/billing/billing-05.tsx"
    }
  ],
  "meta": {
    "shows": "Plans side by side, monthly or yearly, with seats, what is due today and what a downgrade takes away.",
    "size": "full",
    "usedWith": [
      "billing-02",
      "billing-03",
      "usage-meter-01"
    ],
    "component": "Billing5",
    "props": "{ currency?: string; current: { interval: \"month\" | \"year\"; planId: string; seats: number }; description: string; now: Date; onConfirm?: (change: { interval: \"month\" | \"year\"; planId: string; seats: number }) => void; onContactSales?: (planId: string) => void; periodStart: Date; plans?: { description: string; features: string[]; highlight?: string; id: string; name: string; price?: { month: number; year: number } }[]; renewsAt: Date; seatsInUse: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
