{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billing-summary-card",
  "title": "Billing Summary Card",
  "description": "A subscription billing card: plan and renewal date, a monthly or annual switch with the yearly saving, a seat stepper that cannot drop below seats in use, usage meters that warn near their limits, a live next-invoice breakdown with VAT, saved payment cards, and a two-step cancel with undo.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/billing-summary-card/billing-summary-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, animate, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface UsageMeter {\n  label: string;\n  used: number;\n  limit: number;\n  unit?: string;\n}\n\nexport interface PaymentCard {\n  id: string;\n  brand: string;\n  last4: string;\n  expires: string;\n}\n\nexport interface BillingSummaryCardProps {\n  plan?: string;\n  /** Price per seat per month on monthly billing. */\n  seatPrice?: number;\n  /** Discount for annual billing, 0–1. */\n  annualDiscount?: number;\n  seats?: number;\n  /** Seats included before extra seats are charged (shown as used in the seats meter). */\n  seatsUsed?: number;\n  usage?: UsageMeter[];\n  /** Usage-based charge on the next invoice. */\n  usageCharge?: number;\n  renews?: string;\n  cards?: PaymentCard[];\n  currency?: string;\n  onChange?: (state: { cycle: \"monthly\" | \"annual\"; seats: number; card: string }) => void;\n  onCancel?: () => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", inner: \"#171717\", border: \"rgba(255,255,255,0.09)\", chip: \"rgba(255,255,255,0.06)\", track: \"rgba(255,255,255,0.08)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", green: \"#4ADE80\", amber: \"#FBBF24\", red: \"#F87171\", accent: \"#FB923C\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", card: \"#FFFFFF\", inner: \"#FAFAF8\", border: \"rgba(10,10,10,0.09)\", chip: \"rgba(10,10,10,0.05)\", track: \"rgba(10,10,10,0.07)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", green: \"#15803D\", amber: \"#B45309\", red: \"#DC2626\", accent: \"#EA580C\", ring: \"rgba(10,10,10,0.5)\" },\n};\n\nconst DEFAULT_USAGE: UsageMeter[] = [\n  { label: \"Storage\", used: 412, limit: 500, unit: \"GB\" },\n  { label: \"API requests\", used: 2.84, limit: 5, unit: \"M\" },\n  { label: \"Automation runs\", used: 9640, limit: 10000 },\n];\nconst DEFAULT_CARDS: PaymentCard[] = [\n  { id: \"visa\", brand: \"Visa\", last4: \"4242\", expires: \"08/28\" },\n  { id: \"mc\", brand: \"Mastercard\", last4: \"5100\", expires: \"02/27\" },\n];\n\nfunction Num({ value, currency, reduce }: { value: number; currency: string; reduce: boolean }) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const from = React.useRef(value);\n  const fmt = (v: number) => `${currency}${v.toLocaleString(\"en-US\", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;\n  React.useEffect(() => {\n    const fmt = (v: number) => `${currency}${v.toLocaleString(\"en-US\", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;\n    const el = ref.current;\n    if (!el) return;\n    if (reduce) {\n      el.textContent = fmt(value);\n      from.current = value;\n      return;\n    }\n    const c = animate(from.current, value, { duration: 0.5, ease: [0.22, 1, 0.36, 1], onUpdate: (v) => (el.textContent = fmt(v)) });\n    from.current = value;\n    return () => c.stop();\n  }, [value, currency, reduce]);\n  return <span ref={ref}>{fmt(value)}</span>;\n}\n\n// A neutral card glyph; the brand is shown as text, never as a logo.\nfunction brandMark(brand: string) {\n  return (\n    <span className=\"relative flex h-6 w-9 shrink-0 flex-col justify-between overflow-hidden rounded-[5px] p-1\" style={{ background: \"linear-gradient(135deg,#3a3a3a,#1f1f1f)\" }} aria-hidden=\"true\">\n      <span className=\"h-1.5 w-2.5 rounded-[2px]\" style={{ background: \"#d9b26a\" }} />\n      <span className=\"self-end text-[6.5px] leading-none font-bold tracking-wide text-white/80 uppercase\">{brand.slice(0, 4)}</span>\n    </span>\n  );\n}\n\nexport function BillingSummaryCard({ plan = \"Business\", seatPrice = 24, annualDiscount = 0.2, seats: seatsProp = 20, seatsUsed = 18, usage = DEFAULT_USAGE, usageCharge = 38.4, renews = \"1 Dec 2026\", cards = DEFAULT_CARDS, currency = \"$\", onChange, onCancel, theme = \"dark\", className }: BillingSummaryCardProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [cycle, setCycle] = React.useState<\"monthly\" | \"annual\">(\"monthly\");\n  const [seats, setSeats] = React.useState(seatsProp);\n  const [card, setCard] = React.useState(cards[0]?.id ?? \"\");\n  const [cardsOpen, setCardsOpen] = React.useState(false);\n  const [cancelStep, setCancelStep] = React.useState<0 | 1 | 2>(0);\n  const [saved, setSaved] = React.useState<string | null>(null);\n\n  const perSeat = cycle === \"annual\" ? seatPrice * (1 - annualDiscount) : seatPrice;\n  const base = perSeat * seats * (cycle === \"annual\" ? 12 : 1);\n  const subtotal = base + usageCharge;\n  const tax = subtotal * 0.19;\n  const totalDue = subtotal + tax;\n  const yearlySaving = seatPrice * annualDiscount * seats * 12;\n  const changed = cycle !== \"monthly\" || seats !== seatsProp || card !== cards[0]?.id;\n  const stateKey = `${cycle}-${seats}-${card}`;\n  const current = cards.find((c) => c.id === card) ?? cards[0];\n  const money = (n: number) => `${currency}${n.toLocaleString(\"en-US\", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;\n  const focusFirst = React.useCallback((el: HTMLButtonElement | null) => el?.focus({ preventScroll: true }), []);\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const meter = (m: UsageMeter) => {\n    const pct = Math.min(100, (m.used / m.limit) * 100);\n    const color = pct >= 95 ? p.red : pct >= 80 ? p.amber : p.on;\n    const fmt = (n: number) => (Number.isInteger(n) ? n.toLocaleString(\"en-US\") : n.toFixed(2));\n    return (\n      <li key={m.label}>\n        <div className=\"flex items-baseline justify-between gap-3 text-[13px]\">\n          <span style={{ color: p.muted }}>{m.label}</span>\n          <span className=\"tabular-nums\">\n            {fmt(m.used)}\n            {m.unit ? ` ${m.unit}` : \"\"} <span style={{ color: p.faint }}>/ {fmt(m.limit)}{m.unit ? ` ${m.unit}` : \"\"}</span>\n          </span>\n        </div>\n        <div className=\"mt-1.5 h-1.5 overflow-hidden rounded-full\" style={{ background: p.track }} role=\"progressbar\" aria-label={m.label} aria-valuenow={Math.round(pct)} aria-valuemin={0} aria-valuemax={100}>\n          <motion.div className=\"h-full rounded-full\" style={{ background: color }} initial={reduce ? false : { width: 0 }} animate={{ width: `${pct}%` }} transition={{ duration: reduce ? 0 : 0.8, ease: [0.22, 1, 0.36, 1] }} />\n        </div>\n        {pct >= 80 && (\n          <p className=\"m-0 mt-1 text-[11.5px]\" style={{ color }}>\n            {pct >= 95 ? \"Almost at your limit. Extra usage is billed per unit.\" : `${Math.round(pct)}% used`}\n          </p>\n        )}\n      </li>\n    );\n  };\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-4xl px-4 py-10 @[640px]:px-6 @[640px]:py-14\">\n        <div className=\"overflow-hidden rounded-2xl border\" style={{ background: p.card, borderColor: p.border }}>\n          <div className=\"grid @[720px]:grid-cols-[minmax(0,1fr)_340px]\">\n            {/* Plan + usage */}\n            <div className=\"p-5 @[640px]:p-6\">\n              <div className=\"flex flex-wrap items-start justify-between gap-3\">\n                <div>\n                  <p className=\"m-0 text-[12.5px]\" style={{ color: p.faint }}>\n                    Current plan\n                  </p>\n                  <h2 className=\"m-0 mt-1 flex items-center gap-2 text-[22px] font-semibold tracking-[-0.02em]\">\n                    {plan}\n                    <span className=\"rounded-full px-2 py-0.5 text-[11px] font-semibold\" style={{ background: p.chip, color: p.green }}>\n                      Active\n                    </span>\n                  </h2>\n                  <p className=\"m-0 mt-1 text-[13px]\" style={{ color: p.muted }}>\n                    Renews on {renews}\n                  </p>\n                </div>\n                <div role=\"radiogroup\" aria-label=\"Billing cycle\" className=\"flex rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n                  {([\"monthly\", \"annual\"] as const).map((c) => (\n                    <button key={c} type=\"button\" role=\"radio\" aria-checked={cycle === c} onClick={() => setCycle(c)} className={cn(\"relative flex h-7 cursor-pointer items-center gap-1.5 rounded-md border-0 bg-transparent px-3 text-[12.5px] capitalize\", focus)} style={{ color: cycle === c ? p.text : p.faint, ...ring }}>\n                      {cycle === c && <motion.span layoutId={`${uid}-cycle`} className=\"absolute inset-0 rounded-md\" style={{ background: p.chip }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n                      <span className=\"relative\">{c}</span>\n                      {c === \"annual\" && (\n                        <span className=\"relative rounded px-1 text-[10px] font-semibold\" style={{ color: p.accent }}>\n                          −{Math.round(annualDiscount * 100)}%\n                        </span>\n                      )}\n                    </button>\n                  ))}\n                </div>\n              </div>\n\n              <div className=\"mt-5 flex flex-wrap items-end gap-x-6 gap-y-3\">\n                <p className=\"m-0 text-[32px] leading-none font-semibold tracking-[-0.03em] tabular-nums\">\n                  <Num value={perSeat} currency={currency} reduce={reduce} />\n                  <span className=\"ml-1 text-[13px] font-normal tracking-normal\" style={{ color: p.faint }}>\n                    per seat / month\n                  </span>\n                </p>\n                <AnimatePresence>\n                  {cycle === \"annual\" && (\n                    <motion.span initial={reduce ? false : { opacity: 0, x: -6 }} animate={{ opacity: 1, x: 0 }} exit={reduce ? undefined : { opacity: 0, x: -6 }} className=\"rounded-full px-2.5 py-1 text-[12px] font-medium tabular-nums\" style={{ background: p.chip, color: p.green }}>\n                      You save {money(yearlySaving)} a year\n                    </motion.span>\n                  )}\n                </AnimatePresence>\n              </div>\n\n              {/* Seats */}\n              <div className=\"mt-6 flex items-center justify-between gap-3 rounded-xl border p-3.5\" style={{ borderColor: p.border, background: p.inner }}>\n                <div>\n                  <p className=\"m-0 text-[13.5px] font-medium\">Seats</p>\n                  <p className=\"m-0 text-[12px] tabular-nums\" style={{ color: seatsUsed > seats ? p.red : p.faint }}>\n                    {seatsUsed} in use{seatsUsed > seats ? ` · remove ${seatsUsed - seats} members first` : ` · ${seats - seatsUsed} free`}\n                  </p>\n                </div>\n                <div className=\"flex items-center gap-1\" role=\"group\" aria-label=\"Seats\">\n                  <button type=\"button\" aria-label=\"Remove a seat\" disabled={seats <= seatsUsed} onClick={() => setSeats((s) => s - 1)} className={cn(\"flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg border bg-transparent text-[16px] disabled:cursor-not-allowed disabled:opacity-35\", focus)} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                    −\n                  </button>\n                  <span className=\"w-10 text-center text-[15px] font-semibold tabular-nums\" aria-live=\"polite\">\n                    {seats}\n                  </span>\n                  <button type=\"button\" aria-label=\"Add a seat\" onClick={() => setSeats((s) => s + 1)} className={cn(\"flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg border bg-transparent text-[16px]\", focus)} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                    +\n                  </button>\n                </div>\n              </div>\n\n              <h3 className=\"m-0 mt-6 mb-3 text-[13px] font-medium\" style={{ color: p.muted }}>\n                Usage this cycle\n              </h3>\n              <ul className=\"m-0 flex list-none flex-col gap-4 p-0\">{usage.map(meter)}</ul>\n            </div>\n\n            {/* Invoice + payment */}\n            <aside className=\"flex flex-col border-t p-5 @[640px]:p-6 @[720px]:border-t-0 @[720px]:border-l\" style={{ borderColor: p.border, background: p.inner }} aria-label=\"Next invoice\">\n              <p className=\"m-0 text-[12.5px]\" style={{ color: p.faint }}>\n                Next invoice · {renews}\n              </p>\n              <p className=\"m-0 mt-1 text-[28px] leading-tight font-semibold tracking-[-0.02em] tabular-nums\" aria-live=\"polite\">\n                <Num value={totalDue} currency={currency} reduce={reduce} />\n              </p>\n              <dl className=\"m-0 mt-4 grid grid-cols-[1fr_auto] gap-y-2 text-[13px] tabular-nums\">\n                <dt style={{ color: p.muted }}>\n                  {seats} seats × {money(perSeat)}\n                  {cycle === \"annual\" ? \" × 12\" : \"\"}\n                </dt>\n                <dd className=\"m-0 text-right\">{money(base)}</dd>\n                <dt style={{ color: p.muted }}>Usage overage</dt>\n                <dd className=\"m-0 text-right\">{money(usageCharge)}</dd>\n                <dt style={{ color: p.muted }}>VAT 19%</dt>\n                <dd className=\"m-0 text-right\">{money(tax)}</dd>\n                <dt className=\"border-t pt-2 font-semibold\" style={{ borderColor: p.border }}>\n                  Total\n                </dt>\n                <dd className=\"m-0 border-t pt-2 text-right font-semibold\" style={{ borderColor: p.border }}>\n                  {money(totalDue)}\n                </dd>\n              </dl>\n\n              <div className=\"mt-5\">\n                <p className=\"m-0 mb-2 text-[12.5px]\" style={{ color: p.faint }}>\n                  Payment method\n                </p>\n                <button type=\"button\" aria-expanded={cardsOpen} aria-controls={`${uid}-cards`} onClick={() => setCardsOpen((o) => !o)} className={cn(\"flex w-full cursor-pointer items-center gap-3 rounded-xl border px-3 py-2.5 text-left\", focus)} style={{ borderColor: p.border, background: p.card, color: p.text, ...ring }}>\n                  {current && brandMark(current.brand)}\n                  <span className=\"min-w-0 flex-1\">\n                    <span className=\"block text-[13.5px] font-medium\">\n                      {current?.brand} •••• {current?.last4}\n                    </span>\n                    <span className=\"block text-[12px]\" style={{ color: p.faint }}>\n                      Expires {current?.expires}\n                    </span>\n                  </span>\n                  <span className=\"text-[12.5px]\" style={{ color: p.muted }}>\n                    {cardsOpen ? \"Done\" : \"Change\"}\n                  </span>\n                </button>\n                <AnimatePresence initial={false}>\n                  {cardsOpen && (\n                    <motion.fieldset id={`${uid}-cards`} initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} className=\"m-0 overflow-hidden border-0 p-0\">\n                      <legend className=\"sr-only\">Choose a card</legend>\n                      <div className=\"flex flex-col gap-1.5 pt-2\">\n                        {cards.map((c) => (\n                          <label key={c.id} className=\"flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-2 text-[13px]\" style={{ borderColor: card === c.id ? p.text : p.border }}>\n                            <input type=\"radio\" name={`${uid}-card`} checked={card === c.id} onChange={() => setCard(c.id)} className=\"h-3.5 w-3.5\" style={{ accentColor: p.on }} />\n                            {brandMark(c.brand)}\n                            <span className=\"flex-1\">\n                              •••• {c.last4} <span style={{ color: p.faint }}>· {c.expires}</span>\n                            </span>\n                          </label>\n                        ))}\n                      </div>\n                    </motion.fieldset>\n                  )}\n                </AnimatePresence>\n              </div>\n\n              <div className=\"mt-auto flex flex-col gap-2 pt-6\">\n                <button\n                  type=\"button\"\n                  disabled={!changed || saved === stateKey}\n                  onClick={() => {\n                    onChange?.({ cycle, seats, card });\n                    setSaved(stateKey);\n                  }}\n                  className={cn(\"h-10 cursor-pointer rounded-xl border-0 text-[14px] font-medium disabled:cursor-not-allowed disabled:opacity-40\", focus)}\n                  style={{ background: p.on, color: p.onText, ...ring }}\n                >\n                  {saved === stateKey ? \"Changes saved\" : changed ? \"Update subscription\" : \"No changes\"}\n                </button>\n                <AnimatePresence mode=\"wait\" initial={false}>\n                  {cancelStep === 0 ? (\n                    <motion.button key=\"c0\" type=\"button\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} onClick={() => setCancelStep(1)} className={cn(\"h-9 cursor-pointer rounded-lg border-0 bg-transparent text-[13px]\", focus)} style={{ color: p.muted, ...ring }}>\n                      Cancel subscription\n                    </motion.button>\n                  ) : cancelStep === 1 ? (\n                    <motion.div key=\"c1\" initial={reduce ? false : { opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"rounded-xl border p-3.5\" style={{ borderColor: p.red }} role=\"alertdialog\" aria-labelledby={`${uid}-cx`}>\n                      <p id={`${uid}-cx`} className=\"m-0 text-[13px]\">\n                        Your team keeps access until {renews}. After that, {seatsUsed} members lose access and data is kept for 30 days.\n                      </p>\n                      <div className=\"mt-3 flex gap-2\">\n                        <button ref={focusFirst} type=\"button\" onClick={() => setCancelStep(0)} className={cn(\"h-8 flex-1 cursor-pointer rounded-lg border bg-transparent text-[12.5px]\", focus)} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                          Keep plan\n                        </button>\n                        <button\n                          type=\"button\"\n                          onClick={() => {\n                            setCancelStep(2);\n                            onCancel?.();\n                          }}\n                          className={cn(\"h-8 flex-1 cursor-pointer rounded-lg border-0 text-[12.5px] font-medium\", focus)}\n                          style={{ background: p.red, color: \"#fff\", ...ring }}\n                        >\n                          Cancel plan\n                        </button>\n                      </div>\n                    </motion.div>\n                  ) : (\n                    <motion.p key=\"c2\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} className=\"m-0 text-center text-[12.5px]\" style={{ color: p.muted }} role=\"status\">\n                      Cancelled. Access ends on {renews}.{\" \"}\n                      <button type=\"button\" onClick={() => setCancelStep(0)} className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 text-[12.5px] underline\", focus)} style={{ color: p.text, ...ring }}>\n                        Undo\n                      </button>\n                    </motion.p>\n                  )}\n                </AnimatePresence>\n              </div>\n            </aside>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default BillingSummaryCard;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}