{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billing-01",
  "title": "Usage with a spending cap",
  "description": "Plan meters that turn amber near their limit, on-demand spending against a cap whose marker follows the slider, a card that grows into its editor, and a next invoice that rolls to its new total once the cap is saved.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/slider.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/billing/billing-01/index.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport {\n  MONEY_FORMAT,\n  MONEY_LOCALE,\n  daysLabelOf,\n  formatWholeMoney,\n  onDemandTotal,\n  type SpendCap,\n} from './billing-model';\nimport { INITIAL_CAP, PLAN } from './data';\nimport { SpendCapCard } from './spend-cap';\nimport { UsageMeters } from './usage-meters';\n\nconst CARD_SURFACE =\n  'bg-card hairline-ring ring-border rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-foreground/[0.03]';\n\n/** What the next invoice adds on top of the plan: everything spent, or the cap when it is lower. */\nfunction chargedOnDemandOf(cap: SpendCap, spent: number) {\n  if (!cap.isCapped) {\n    return spent;\n  }\n  return Math.min(spent, cap.amount);\n}\n\nexport default function Billing01() {\n  const [cap, setCap] = useState<SpendCap>(INITIAL_CAP);\n  const spent = onDemandTotal();\n  const chargedOnDemand = chargedOnDemandOf(cap, spent);\n  const estimate = PLAN.monthlyPrice + chargedOnDemand;\n  const planPrice = formatWholeMoney(PLAN.monthlyPrice);\n  const resetsIn = daysLabelOf(PLAN.resetsInDays);\n\n  return (\n    <div className='bg-background text-foreground min-h-dvh w-full'>\n      <div className='mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6 md:py-10'>\n        <header className='flex flex-col gap-1'>\n          <p className='text-muted-foreground text-xs'>{PLAN.workspace}</p>\n          <h1 className='text-lg font-semibold text-balance'>\n            Usage and billing\n          </h1>\n        </header>\n        <section\n          aria-label='Next invoice'\n          className={cn(\n            CARD_SURFACE,\n            'flex flex-wrap items-end justify-between gap-x-6 gap-y-3 p-4 sm:p-5'\n          )}\n        >\n          <div className='flex flex-col gap-1'>\n            <p className='text-muted-foreground text-xs'>\n              Next invoice, {PLAN.renewsOn}\n            </p>\n            <MotionNumber\n              value={estimate}\n              locale={MONEY_LOCALE}\n              format={MONEY_FORMAT}\n              className='text-2xl leading-8 font-semibold'\n            />\n            <p className='text-muted-foreground text-xs tabular-nums'>\n              {PLAN.name} {planPrice}, on demand{' '}\n              <MotionNumber\n                value={chargedOnDemand}\n                locale={MONEY_LOCALE}\n                format={MONEY_FORMAT}\n              />\n            </p>\n          </div>\n          <p className='text-muted-foreground text-xs'>\n            Usage resets in {resetsIn} · Illustrative figures\n          </p>\n        </section>\n        <section\n          aria-labelledby='billing-01-usage'\n          className={cn(CARD_SURFACE, 'flex flex-col gap-5 p-4 sm:p-5')}\n        >\n          <h2 id='billing-01-usage' className='text-sm font-medium'>\n            This month\n          </h2>\n          <UsageMeters />\n        </section>\n        <section\n          aria-label='On-demand spending'\n          className={cn(CARD_SURFACE, 'p-4 sm:p-5')}\n        >\n          <SpendCapCard cap={cap} spent={spent} onCapChange={setCap} />\n        </section>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/billing-01/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/billing/billing-01/spend-cap.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type MotionProps,\n  type Transition,\n} from 'motion/react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll, type WordRollWord } from '@/components/core/word-roll';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Slider, SliderThumbValue } from '@/registry/ndeko/ui/slider';\nimport { Switch } from '@/registry/ndeko/ui/switch';\n\nimport {\n  MONEY_FORMAT,\n  MONEY_LOCALE,\n  WHOLE_MONEY_FORMAT,\n  formatWholeMoney,\n  isCapReached,\n  sameCap,\n  shareOfCapRange,\n  type SpendCap,\n} from './billing-model';\nimport { CAP_BOUNDS, PLAN } from './data';\nimport { SaveButton, type SaveStatus } from './save-button';\n\nconst SAVING_MS = 700;\n\nconst SAVED_HOLD_MS = 900;\n\nconst EASE_OUT_STRONG: [number, number, number, number] = [0.23, 1, 0.32, 1];\n\nconst ENTER: Transition = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nconst EXIT: Transition = { duration: 0.14, ease: EASE_OUT_STRONG };\n\ntype PresenceProps = Pick<\n  MotionProps,\n  'initial' | 'animate' | 'exit' | 'transition'\n>;\n\nconst HEIGHT_PRESENCE: PresenceProps = {\n  initial: { height: 0, opacity: 0 },\n  animate: { height: 'auto', opacity: 1 },\n  exit: { height: 0, opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\nconst FADE_PRESENCE: PresenceProps = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\nfunction heightPresenceOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_PRESENCE;\n  }\n  return HEIGHT_PRESENCE;\n}\n\nfunction delayOf(status: SaveStatus) {\n  if (status === 'saving') {\n    return SAVING_MS;\n  }\n  return SAVED_HOLD_MS;\n}\n\nfunction amountOf(value: number | readonly number[]) {\n  if (typeof value === 'number') {\n    return value;\n  }\n  return value[0];\n}\n\nfunction capAriaTextOf(_formatted: string, value: number) {\n  return `${formatWholeMoney(value)} a month`;\n}\n\nfunction fillToneOf(isReached: boolean) {\n  if (isReached) {\n    return 'bg-warning';\n  }\n  return 'bg-primary';\n}\n\nfunction markerOpacityOf(isCapped: boolean) {\n  if (isCapped) {\n    return 'opacity-100';\n  }\n  return 'opacity-0';\n}\n\ntype SpendBarProps = {\n  spent: number;\n  cap: SpendCap;\n};\n\n/** Spending so far against the whole range of caps, with a marker where the cap sits. */\nfunction SpendBar({ spent, cap }: SpendBarProps) {\n  const isReached = isCapReached(cap, spent);\n  const spentShare = shareOfCapRange(spent);\n  const capShare = shareOfCapRange(cap.amount);\n  const fillStyle = { transform: `scaleX(${spentShare})` };\n  const capPercent = capShare * 100;\n  const markerTrackStyle = { transform: `translateX(${capPercent}%)` };\n\n  return (\n    <div aria-hidden='true' className='relative py-1'>\n      <div className='bg-foreground/10 h-1.5 overflow-hidden rounded-full'>\n        <span\n          style={fillStyle}\n          className={cn(\n            'block h-full origin-left rounded-full transition-colors duration-150 rtl:origin-right',\n            fillToneOf(isReached)\n          )}\n        />\n      </div>\n      <span\n        style={markerTrackStyle}\n        className='pointer-events-none absolute inset-0 transition-transform duration-150 ease-(--ease-out-strong) rtl:-scale-x-100'\n      >\n        <span\n          className={cn(\n            'bg-foreground absolute top-0 left-0 h-3.5 w-0.5 -translate-x-1/2 rounded-full transition-opacity duration-150',\n            markerOpacityOf(cap.isCapped)\n          )}\n        />\n      </span>\n    </div>\n  );\n}\n\ntype CapEditorProps = {\n  draft: SpendCap;\n  status: SaveStatus;\n  hasChanges: boolean;\n  onDraftChange: (draft: SpendCap) => void;\n  onCancel: () => void;\n  onSave: () => void;\n};\n\nfunction CapEditor({\n  draft,\n  status,\n  hasChanges,\n  onDraftChange,\n  onCancel,\n  onSave,\n}: CapEditorProps) {\n  const isBusy = status !== 'idle';\n  const isSliderOff = !draft.isCapped;\n\n  function changeAmount(value: number | readonly number[]) {\n    const amount = amountOf(value);\n    onDraftChange({ ...draft, amount });\n  }\n\n  function changeCapped(isCapped: boolean) {\n    onDraftChange({ ...draft, isCapped });\n  }\n\n  return (\n    <div className='flex flex-col gap-4 pt-5'>\n      <label className='flex cursor-pointer items-center justify-between gap-3 text-[13px]'>\n        Stop on-demand charges at a monthly cap\n        <Switch checked={draft.isCapped} onCheckedChange={changeCapped} />\n      </label>\n      <div className='flex flex-col gap-1'>\n        <Slider\n          value={draft.amount}\n          min={CAP_BOUNDS.min}\n          max={CAP_BOUNDS.max}\n          step={CAP_BOUNDS.step}\n          disabled={isSliderOff}\n          thumbLabels={['Monthly cap']}\n          getAriaValueText={capAriaTextOf}\n          thumbContent={() => (\n            <SliderThumbValue>\n              {formatWholeMoney(draft.amount)}\n            </SliderThumbValue>\n          )}\n          onValueChange={changeAmount}\n        />\n        <div className='text-muted-foreground flex justify-between text-xs tabular-nums'>\n          <span>{formatWholeMoney(CAP_BOUNDS.min)}</span>\n          <span>{formatWholeMoney(CAP_BOUNDS.max)}</span>\n        </div>\n      </div>\n      <div className='flex items-center justify-end gap-2'>\n        <Button variant='ghost' disabled={isBusy} onClick={onCancel}>\n          Cancel\n        </Button>\n        <SaveButton\n          status={status}\n          idleLabel='Save cap'\n          disabled={!hasChanges}\n          onSave={onSave}\n        />\n      </div>\n    </div>\n  );\n}\n\ntype CapFigureProps = {\n  cap: SpendCap;\n};\n\nconst NO_CAP_WORD: WordRollWord = {\n  key: 'no-cap',\n  text: 'No cap',\n  node: <span className='font-medium'>No cap</span>,\n};\n\n/** The amount keeps its slot while it changes, so a new cap rolls its digits and only a switch rolls the words. */\nfunction capWordsOf(cap: SpendCap): WordRollWord[] {\n  if (!cap.isCapped) {\n    return [NO_CAP_WORD];\n  }\n  const amount: WordRollWord = {\n    key: 'amount',\n    text: formatWholeMoney(cap.amount),\n    node: (\n      <MotionNumber\n        value={cap.amount}\n        locale={MONEY_LOCALE}\n        format={WHOLE_MONEY_FORMAT}\n        className='font-medium'\n      />\n    ),\n  };\n  return [amount, 'a', 'month'];\n}\n\nfunction CapFigure({ cap }: CapFigureProps) {\n  const words = capWordsOf(cap);\n  return <WordRoll words={words} />;\n}\n\nfunction shownCapOf(isEditing: boolean, draft: SpendCap, cap: SpendCap) {\n  if (isEditing) {\n    return draft;\n  }\n  return cap;\n}\n\ntype SpendCapCardProps = {\n  cap: SpendCap;\n  spent: number;\n  onCapChange: (cap: SpendCap) => void;\n};\n\nexport function SpendCapCard({ cap, spent, onCapChange }: SpendCapCardProps) {\n  const [isEditing, setIsEditing] = useState(false);\n  const [draft, setDraft] = useState<SpendCap>(cap);\n  const [status, setStatus] = useState<SaveStatus>('idle');\n  const changeButtonRef = useRef<HTMLButtonElement>(null);\n  const editorRef = useRef<HTMLDivElement>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const heightPresence = heightPresenceOf(shouldReduceMotion);\n  const shownCap = shownCapOf(isEditing, draft, cap);\n  const isReached = isCapReached(shownCap, spent);\n  const hasChanges = !sameCap(draft, cap);\n\n  useEffect(() => {\n    if (status === 'idle') {\n      return;\n    }\n    function advance() {\n      if (status === 'saving') {\n        onCapChange(draft);\n        setStatus('saved');\n        return;\n      }\n      setStatus('idle');\n      setIsEditing(false);\n      window.requestAnimationFrame(() => changeButtonRef.current?.focus());\n    }\n    const delay = delayOf(status);\n    const timer = window.setTimeout(advance, delay);\n    return () => window.clearTimeout(timer);\n  }, [status, draft, onCapChange]);\n\n  function startEditing() {\n    setDraft(cap);\n    setIsEditing(true);\n    window.requestAnimationFrame(() => {\n      const firstControl =\n        editorRef.current?.querySelector<HTMLElement>('button, input');\n      firstControl?.focus();\n    });\n  }\n\n  function cancel() {\n    setIsEditing(false);\n    setDraft(cap);\n    window.requestAnimationFrame(() => changeButtonRef.current?.focus());\n  }\n\n  function save() {\n    setStatus('saving');\n  }\n\n  return (\n    <div className='flex flex-col gap-4'>\n      <div className='flex flex-wrap items-start justify-between gap-x-4 gap-y-2'>\n        <div className='flex flex-col gap-0.5'>\n          <h2 className='text-sm font-medium'>On-demand spending</h2>\n          <p className='text-muted-foreground text-xs text-pretty'>\n            Use beyond the plan, added to the invoice of {PLAN.renewsOn}\n          </p>\n        </div>\n        <AnimatePresence initial={false}>\n          {!isEditing && (\n            <motion.div key='change' {...FADE_PRESENCE}>\n              <Button\n                ref={changeButtonRef}\n                variant='outline'\n                size='sm'\n                onClick={startEditing}\n              >\n                Change cap\n              </Button>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n      <SpendBar spent={spent} cap={shownCap} />\n      <div className='flex flex-wrap justify-between gap-x-4 gap-y-1 text-[13px]'>\n        <span className='text-muted-foreground'>\n          <MotionNumber\n            value={spent}\n            locale={MONEY_LOCALE}\n            format={MONEY_FORMAT}\n            className='text-foreground font-medium'\n          />{' '}\n          spent so far\n        </span>\n        <span className='text-muted-foreground'>\n          Cap: <CapFigure cap={cap} />\n        </span>\n      </div>\n      <AnimatedSize>\n        <AnimatePresence initial={false}>\n          {isReached && (\n            <motion.p\n              key='reached'\n              {...heightPresence}\n              className='text-warning-foreground overflow-hidden text-xs text-pretty'\n            >\n              <span className='block pb-1'>\n                The cap is at or below what is already spent. Runs over the plan\n                and new guest viewers pause until {PLAN.renewsOn}.\n              </span>\n            </motion.p>\n          )}\n        </AnimatePresence>\n        {isEditing && (\n          <motion.div\n            ref={editorRef}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1, transition: ENTER }}\n          >\n            <CapEditor\n              draft={draft}\n              status={status}\n              hasChanges={hasChanges}\n              onDraftChange={setDraft}\n              onCancel={cancel}\n              onSave={save}\n            />\n          </motion.div>\n        )}\n      </AnimatedSize>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/billing-01/spend-cap.tsx"
    },
    {
      "path": "registry/ndeko/blocks/billing/billing-01/usage-meters.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\n\nimport {\n  fillOf,\n  formatMoney,\n  formatQuantity,\n  overageCostOf,\n  overageOf,\n  toneOf,\n  type MeterTone,\n} from './billing-model';\nimport { METERS, type Meter } from './data';\n\nconst FILL_TONE: Record<MeterTone, string> = {\n  calm: 'bg-primary',\n  near: 'bg-warning',\n  over: 'bg-warning',\n};\n\nconst NOTE_TONE: Record<MeterTone, string> = {\n  calm: 'text-muted-foreground',\n  near: 'text-warning-foreground',\n  over: 'text-warning-foreground',\n};\n\nfunction noteOf(meter: Meter, tone: MeterTone) {\n  if (tone === 'over') {\n    const overage = overageOf(meter);\n    const extra = formatQuantity(overage, meter.decimals);\n    if (meter.overagePrice === null) {\n      return `${extra} ${meter.unit} over the plan`;\n    }\n    const overageCost = overageCostOf(meter);\n    const cost = formatMoney(overageCost);\n    return `${extra} ${meter.unit} over the plan, ${cost} on demand`;\n  }\n  const left = meter.included - meter.used;\n  const leftText = formatQuantity(left, meter.decimals);\n  return `${leftText} ${meter.unit} left`;\n}\n\nfunction MeterRow({ meter }: { meter: Meter }) {\n  const tone = toneOf(meter);\n  const fill = fillOf(meter);\n  const used = formatQuantity(meter.used, meter.decimals);\n  const included = formatQuantity(meter.included, 0);\n  const note = noteOf(meter, tone);\n  const valueNow = Math.min(meter.used, meter.included);\n  const fillStyle = { transform: `scaleX(${fill})` };\n\n  return (\n    <li className='flex flex-col gap-2'>\n      <div className='flex items-baseline justify-between gap-3'>\n        <span className='text-[13px] font-medium'>{meter.label}</span>\n        <span className='text-[13px] tabular-nums'>\n          {used}{' '}\n          <span className='text-muted-foreground'>\n            of {included} {meter.unit}\n          </span>\n        </span>\n      </div>\n      <div\n        role='meter'\n        aria-label={meter.label}\n        aria-valuemin={0}\n        aria-valuemax={meter.included}\n        aria-valuenow={valueNow}\n        aria-valuetext={`${used} of ${included} ${meter.unit}`}\n        className='bg-foreground/10 h-1.5 overflow-hidden rounded-full'\n      >\n        <span\n          style={fillStyle}\n          className={cn(\n            'block h-full origin-left rounded-full rtl:origin-right',\n            FILL_TONE[tone]\n          )}\n        />\n      </div>\n      <p className={cn('text-xs tabular-nums', NOTE_TONE[tone])}>{note}</p>\n    </li>\n  );\n}\n\nexport function UsageMeters() {\n  return (\n    <ul className='flex flex-col gap-5'>\n      {METERS.map((meter) => (\n        <MeterRow key={meter.id} meter={meter} />\n      ))}\n    </ul>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/billing-01/usage-meters.tsx"
    },
    {
      "path": "registry/ndeko/blocks/billing/billing-01/billing-model.ts",
      "content": "import { CAP_BOUNDS, METERS, type Meter } from './data';\n\nexport type MeterTone = 'calm' | 'near' | 'over';\n\nexport type SpendCap = { amount: number; isCapped: boolean };\n\nexport const MONEY_LOCALE = 'en-IE';\n\nexport const MONEY_FORMAT: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'EUR',\n  minimumFractionDigits: 2,\n  maximumFractionDigits: 2,\n};\n\nexport const WHOLE_MONEY_FORMAT: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'EUR',\n  maximumFractionDigits: 0,\n};\n\nconst MONEY = new Intl.NumberFormat(MONEY_LOCALE, MONEY_FORMAT);\n\nconst WHOLE_MONEY = new Intl.NumberFormat(MONEY_LOCALE, WHOLE_MONEY_FORMAT);\n\nconst NEAR_LIMIT_SHARE = 0.8;\n\nexport function formatMoney(amount: number) {\n  return MONEY.format(amount);\n}\n\nexport function formatWholeMoney(amount: number) {\n  return WHOLE_MONEY.format(amount);\n}\n\nexport function formatQuantity(value: number, decimals: number) {\n  const formatter = new Intl.NumberFormat('en-US', {\n    minimumFractionDigits: decimals,\n    maximumFractionDigits: decimals,\n  });\n  return formatter.format(value);\n}\n\nexport function overageOf(meter: Meter) {\n  const extra = meter.used - meter.included;\n  return Math.max(extra, 0);\n}\n\nexport function overageCostOf(meter: Meter) {\n  if (meter.overagePrice === null) {\n    return 0;\n  }\n  const extra = overageOf(meter);\n  return extra * meter.overagePrice;\n}\n\nexport function onDemandTotal() {\n  let total = 0;\n  for (const meter of METERS) {\n    total += overageCostOf(meter);\n  }\n  return total;\n}\n\nexport function toneOf(meter: Meter): MeterTone {\n  const share = meter.used / meter.included;\n  if (share > 1) {\n    return 'over';\n  }\n  if (share >= NEAR_LIMIT_SHARE) {\n    return 'near';\n  }\n  return 'calm';\n}\n\n/** The share of the bar to fill, never past its end: the overage is told in words beside it. */\nexport function fillOf(meter: Meter) {\n  const share = meter.used / meter.included;\n  return Math.min(share, 1);\n}\n\nexport function shareOfCapRange(amount: number) {\n  const span = CAP_BOUNDS.max - CAP_BOUNDS.min;\n  const share = (amount - CAP_BOUNDS.min) / span;\n  const atMost = Math.min(share, 1);\n  return Math.max(atMost, 0);\n}\n\nexport function capLabelOf(cap: SpendCap) {\n  if (!cap.isCapped) {\n    return 'No cap';\n  }\n  return `${formatWholeMoney(cap.amount)} a month`;\n}\n\nexport function isCapReached(cap: SpendCap, spent: number) {\n  if (!cap.isCapped) {\n    return false;\n  }\n  return spent >= cap.amount;\n}\n\nexport function sameCap(first: SpendCap, second: SpendCap) {\n  const sameAmount = first.amount === second.amount;\n  const sameSwitch = first.isCapped === second.isCapped;\n  return sameAmount && sameSwitch;\n}\n\nexport function daysLabelOf(days: number) {\n  if (days === 1) {\n    return '1 day';\n  }\n  return `${days} days`;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/billing-01/billing-model.ts"
    },
    {
      "path": "registry/ndeko/blocks/billing/billing-01/save-button.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { CheckIcon, LoaderCircleIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nexport type SaveStatus = 'idle' | 'saving' | 'saved';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction labelOf(status: SaveStatus, idleLabel: string) {\n  if (status === 'saving') {\n    return 'Saving';\n  }\n  if (status === 'saved') {\n    return 'Saved';\n  }\n  return idleLabel;\n}\n\n/** While saving, the pill keeps its full colour: it is working, not unavailable. */\nfunction busyClassOf(isBusy: boolean) {\n  if (isBusy) {\n    return 'data-disabled:opacity-100 disabled:opacity-100';\n  }\n  return undefined;\n}\n\nfunction glyphOf(status: SaveStatus) {\n  if (status === 'saving') {\n    return {\n      key: 'saving',\n      icon: <LoaderCircleIcon className='animate-spin' />,\n    };\n  }\n  if (status === 'saved') {\n    return { key: 'saved', icon: <CheckIcon /> };\n  }\n  return null;\n}\n\ntype SaveButtonProps = {\n  status: SaveStatus;\n  idleLabel: string;\n  disabled?: boolean;\n  onSave: () => void;\n};\n\n/** The label becomes its next state and the pill resizes to it. */\nexport function SaveButton({\n  status,\n  idleLabel,\n  disabled = false,\n  onSave,\n}: SaveButtonProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion);\n  const label = labelOf(status, idleLabel);\n  const glyph = glyphOf(status);\n  const isBusy = status !== 'idle';\n  const isDisabled = disabled || isBusy;\n  const busyClass = busyClassOf(isBusy);\n\n  return (\n    <Button\n      disabled={isDisabled}\n      focusableWhenDisabled\n      onClick={onSave}\n      className={busyClass}\n    >\n      <AnimatedSize\n        as='span'\n        axis='width'\n        contentClassName='relative flex items-center gap-1.5'\n      >\n        <AnimatePresence mode='popLayout' initial={false}>\n          {glyph && (\n            <motion.span\n              key={glyph.key}\n              variants={variants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n              className='flex'\n            >\n              {glyph.icon}\n            </motion.span>\n          )}\n        </AnimatePresence>\n        <AnimatePresence mode='popLayout' initial={false}>\n          <motion.span\n            key={label}\n            variants={variants}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            transition={SWAP_TRANSITION}\n          >\n            {label}\n          </motion.span>\n        </AnimatePresence>\n      </AnimatedSize>\n    </Button>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/billing-01/save-button.tsx"
    },
    {
      "path": "registry/ndeko/blocks/billing/billing-01/data.ts",
      "content": "export type Meter = {\n  id: string;\n  label: string;\n  used: number;\n  included: number;\n  unit: string;\n  /** Price of each unit beyond the plan, or null when the plan stops at its limit. */\n  overagePrice: number | null;\n  /** How many decimals the figures of this meter keep. */\n  decimals: number;\n};\n\nexport const PLAN = {\n  name: 'Growth plan',\n  workspace: 'Fernhollow Studio',\n  monthlyPrice: 99,\n  renewsOn: 'Nov 30',\n  resetsInDays: 12,\n};\n\nexport const CAP_BOUNDS = {\n  min: 0,\n  max: 500,\n  step: 10,\n};\n\nexport const INITIAL_CAP = { amount: 100, isCapped: true };\n\nexport const METERS: Meter[] = [\n  {\n    id: 'seats',\n    label: 'Seats',\n    used: 18,\n    included: 25,\n    unit: 'seats',\n    overagePrice: null,\n    decimals: 0,\n  },\n  {\n    id: 'storage',\n    label: 'File storage',\n    used: 61.4,\n    included: 100,\n    unit: 'GB',\n    overagePrice: null,\n    decimals: 1,\n  },\n  {\n    id: 'runs',\n    label: 'Automation runs',\n    used: 13450,\n    included: 10000,\n    unit: 'runs',\n    overagePrice: 0.01,\n    decimals: 0,\n  },\n  {\n    id: 'guests',\n    label: 'Guest viewers',\n    used: 54,\n    included: 50,\n    unit: 'guests',\n    overagePrice: 3.5,\n    decimals: 0,\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/billing-01/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "billing"
  ],
  "type": "registry:block"
}