{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billing-desk",
  "title": "Meterline, Usage billing",
  "description": "A usage-based account page: the balance in a wallet, spend running on a meter, caps on breakers, the ledger, and API keys that expire on a library slip. A whole screen for a Next.js app, at /billing-desk.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://bevel-ui.vercel.app/r/bevel.json",
    "https://bevel-ui.vercel.app/r/amount.json",
    "https://bevel-ui.vercel.app/r/breaker.json",
    "https://bevel-ui.vercel.app/r/due-date-slip.json",
    "https://bevel-ui.vercel.app/r/ledger.json",
    "https://bevel-ui.vercel.app/r/meter.json",
    "https://bevel-ui.vercel.app/r/payment-card.json",
    "https://bevel-ui.vercel.app/r/receipt.json",
    "https://bevel-ui.vercel.app/r/stamp.json",
    "https://bevel-ui.vercel.app/r/ticket-sheet.json",
    "https://bevel-ui.vercel.app/r/wallet.json"
  ],
  "files": [
    {
      "path": "registry/bevel/blocks/billing-desk/meterline/header.tsx",
      "content": "\"use client\"\n\nimport { Pause, Play } from \"lucide-react\"\nimport { PanelKey } from \"../shared/environment\"\n\n/** The product's own line, printed along the top edge of the desk: name, account, the clock and the traffic key. */\nexport function MeterlineHeader({\n  clock,\n  running,\n  canStart,\n  onTraffic,\n}: {\n  clock: string\n  running: boolean\n  canStart: boolean\n  onTraffic: () => void\n}) {\n  return (\n    <header className=\"mx-auto font-[family-name:var(--font-ledger)] flex max-w-[1440px] flex-wrap items-center gap-x-6 gap-y-3 px-4 pt-6 pb-5 sm:px-8\">\n      <div className=\"flex min-w-0 flex-wrap items-baseline gap-x-4 gap-y-1\">\n        <p className=\"text-[26px] leading-none font-bold text-[#EADFC8] [text-shadow:0_1px_0_rgb(0_0_0/0.5)]\">\n          Meterline\n        </p>\n        <p className=\"text-[17px] text-[#B8AA8E]\">Halvorsen Labs, pay as you go</p>\n      </div>\n      <div className=\"ml-auto flex items-center gap-4\">\n        <p className=\"text-[17px] text-[#B8AA8E]\">\n          17 Oct, <span className=\"text-[#EADFC8] tabular-nums\">{clock}</span>\n        </p>\n        <PanelKey\n          tone={running ? \"plain\" : \"go\"}\n          onClick={onTraffic}\n          disabled={!running && !canStart}\n          className=\"gap-2 [&_svg]:size-4\"\n        >\n          {running ? <Pause aria-hidden /> : <Play aria-hidden />}\n          {running ? \"Pause traffic\" : \"Start traffic\"}\n        </PanelKey>\n      </div>\n    </header>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/bevel-demos/meterline/header.tsx"
    },
    {
      "path": "registry/bevel/blocks/billing-desk/meterline/meterline.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { demoMilestone } from \"../shared/events\"\nimport { ArrowDown, CreditCard } from \"lucide-react\"\nimport { Amount } from \"@/components/ui/amount\"\nimport { Breaker, BreakerPanel, BreakerRow } from \"@/components/ui/breaker\"\nimport { DueDateSlip, DueDateSlipRenew, DueDateSlipStatus } from \"@/components/ui/due-date-slip\"\nimport {\n  Ledger,\n  LedgerAmount,\n  LedgerBody,\n  LedgerCell,\n  LedgerHead,\n  LedgerHeader,\n  LedgerNumber,\n  LedgerRow,\n  LedgerTable,\n  LedgerTitle,\n} from \"@/components/ui/ledger\"\nimport { Meter, MeterButton, MeterFlag, MeterFooter, MeterHeader, MeterReading, MeterUnit } from \"@/components/ui/meter\"\nimport { PaymentCardBrand, PaymentCardNumber } from \"@/components/ui/payment-card\"\nimport {\n  Receipt,\n  ReceiptFooter,\n  ReceiptHeader,\n  ReceiptItem,\n  ReceiptItems,\n  ReceiptLabel,\n  ReceiptMark,\n  ReceiptMeta,\n  ReceiptSeparator,\n  ReceiptTitle,\n  ReceiptTotal,\n  ReceiptValue,\n} from \"@/components/ui/receipt\"\nimport { Stamp, StampDetail } from \"@/components/ui/stamp\"\nimport { Ticket, TicketLabel, TicketNote, TicketSheet, TicketValue } from \"@/components/ui/ticket-sheet\"\nimport {\n  Wallet,\n  WalletAction,\n  WalletAmount,\n  WalletBalance,\n  WalletCard,\n  WalletCards,\n  WalletDetail,\n  WalletDetailLabel,\n  WalletDetails,\n  WalletDetailValue,\n  WalletFooter,\n  WalletHeader,\n  WalletLabel,\n  WalletPocket,\n  WalletStatus,\n} from \"@/components/ui/wallet\"\nimport { cn } from \"@/lib/utils\"\nimport { Legend, PanelKey, StatusStrip } from \"../shared/environment\"\nimport { ledgerFace } from \"../shared/fonts\"\nimport { MeterlineHeader } from \"./header\"\nimport {\n  cardName,\n  cards,\n  clockText,\n  flowing,\n  formatUsd,\n  hourlyRate,\n  initialState,\n  keyInfo,\n  keyValid,\n  LOW_BALANCE,\n  MAX_STAMPS,\n  NOW,\n  packs,\n  reducer,\n  TICK_MS,\n  totalSpent,\n  trafficIds,\n  type CircuitId,\n  type State,\n} from \"./state\"\n\nconst CENTS = { minimumFractionDigits: 2, maximumFractionDigits: 2 }\nconst WHOLE = { maximumFractionDigits: 0 }\nconst statusTone = { Settled: \"black\", Received: \"green\", Bonus: \"blue\" } as const\n\nconst circuitLabel: Record<CircuitId, string> = {\n  main: \"Account\",\n  production: \"Production\",\n  staging: \"Staging\",\n  batch: \"Batch\",\n}\n\n/** Each key slip lies at its own angle in the card file, as if dropped there. */\nconst slipTilt = [\"-rotate-2\", \"rotate-1\", \"-rotate-1\"]\n\n/** The desk: walnut, lit from a lamp above, with the grain running across. */\nconst deskStyle: React.CSSProperties = {\n  backgroundColor: \"#4A3022\",\n  backgroundImage: [\n    \"radial-gradient(ellipse 75% 55% at 50% 0%, rgb(255 214 160 / 0.17), transparent 72%)\",\n    \"radial-gradient(ellipse 120% 80% at 50% 120%, rgb(0 0 0 / 0.35), transparent 70%)\",\n    \"repeating-linear-gradient(177deg, rgb(0 0 0 / 0.07) 0 1px, transparent 1px 6px)\",\n    \"repeating-linear-gradient(182deg, rgb(255 230 200 / 0.035) 0 2px, transparent 2px 29px)\",\n  ].join(\", \"),\n}\n\n/** A legend tooled in gold leaf into the blotter's leather. */\nfunction Tooled({ className, ...props }: React.ComponentProps<typeof Legend>) {\n  return (\n    <Legend\n      className={cn(\n        \"font-[family-name:var(--font-ledger)] text-[19px] font-bold tracking-normal text-[#C9A44A] [text-shadow:0_1px_0_rgb(0_0_0/0.6),0_-1px_0_rgb(255_236_180/0.14)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction runwayText(state: State) {\n  if (state.balance <= 0) return \"Out of credit\"\n  const rate = hourlyRate(state)\n  if (!state.running || rate === 0) return \"Not drawing\"\n  const minutes = Math.round((state.balance / rate) * 60)\n  const h = Math.floor(minutes / 60)\n  return h > 0 ? `About ${h} h ${minutes % 60} m` : `About ${minutes} m`\n}\n\nexport function Meterline() {\n  const [state, dispatch] = React.useReducer(reducer, initialState)\n  const topUpRef = React.useRef<HTMLParagraphElement>(null)\n\n  React.useEffect(() => {\n    if (!state.running) return\n    const timer = setInterval(() => {\n      dispatch({\n        type: \"tick\",\n        draws: { production: Math.random(), staging: Math.random(), batch: Math.random() },\n      })\n    }, TICK_MS)\n    return () => clearInterval(timer)\n  }, [state.running])\n\n  const spent = totalSpent(state.circuits)\n  const live = trafficIds.filter((id) => flowing(state, id))\n  const metering = state.running && live.length > 0\n  const walletStatus = state.balance <= 0 ? \"empty\" : state.balance < LOW_BALANCE ? \"low\" : \"default\"\n  const pack = packs.find((p) => p.id === state.pack)!\n  const expiringSoon = trafficIds.filter((id) => {\n    const last = new Date(state.keys[id].at(-1)!)\n    const days = (last.getTime() - NOW.getTime()) / 86_400_000\n    return days >= 0 && days <= 7\n  }).length\n  const expired = trafficIds.filter((id) => !keyValid(state.keys[id])).length\n  const keysNote = [expired > 0 && `${expired} expired`, expiringSoon > 0 && `${expiringSoon} due this week`]\n    .filter(Boolean)\n    .join(\", \")\n  const printed = state.receipt.no !== initialState.receipt.no\n\n  const goToTopUp = () => {\n    document.getElementById(\"top-up\")?.scrollIntoView({ behavior: \"smooth\", block: \"center\" })\n    topUpRef.current?.focus({ preventScroll: true })\n  }\n\n  const breakerDescription = (id: CircuitId) => {\n    const c = state.circuits[id]\n    if (id !== \"main\" && !keyValid(state.keys[id])) return \"Key expired\"\n    const used = id === \"main\" ? spent : c.spent\n    return `${formatUsd(used)} of ${formatUsd(c.cap)}`\n  }\n\n  return (\n    <div\n      style={deskStyle}\n      className={cn(ledgerFace.variable, \"min-h-svh overflow-x-clip text-[#EADFC8]\")}\n    >\n      <MeterlineHeader\n        clock={clockText(state.clock)}\n        running={state.running}\n        canStart={state.balance > 0}\n        onTraffic={() => dispatch({ type: state.running ? \"pause\" : \"start\" })}\n      />\n\n      <main className=\"mx-auto max-w-[1440px] px-2 pb-12 sm:px-8\">\n        {/* The blotter: green leather set into the walnut, stitched round its edge. */}\n        <div\n          className={cn(\n            \"bevel-leather relative rounded-[22px] px-4 py-7 sm:p-8 xl:p-12 [--bevel-material:#2E4A3B]\",\n            \"shadow-[inset_0_2px_3px_rgb(0_0_0/0.45),inset_0_0_0_1px_rgb(0_0_0/0.35),0_1px_0_rgb(255_230_190/0.12),0_24px_48px_-24px_rgb(0_0_0/0.7)]\"\n          )}\n        >\n          <span\n            aria-hidden\n            className=\"bevel-stitch pointer-events-none absolute inset-2.5 rounded-[14px] [--bevel-stitch:rgb(201_164_74/0.55)]\"\n          />\n\n          <div className=\"relative grid gap-x-12 gap-y-10 lg:grid-cols-[minmax(0,11fr)_minmax(0,13fr)] [&>*]:min-w-0\">\n            {/* The one line of news, on a small backlit display at the head of the desk. */}\n            <div role=\"status\" className=\"lg:col-start-2 lg:row-start-1\">\n              <StatusStrip className=\"font-[family-name:var(--font-ledger)] [&>p]:text-[16px] [&>p]:leading-snug [&>p]:tracking-normal sm:[&>p]:whitespace-normal\">\n                {state.event}\n              </StatusStrip>\n            </div>\n\n            {/* The hero: the wallet, open, with the latest receipt tucked under it. */}\n            <section aria-labelledby=\"ml-balance\" className=\"flex flex-col gap-4 lg:col-start-1 lg:row-span-2 lg:row-start-1\">\n              <Tooled id=\"ml-balance\">Balance</Tooled>\n              <div className=\"flex flex-col items-center lg:items-start\">\n                <div\n                  data-bevel-family=\"leather\"\n                  className=\"relative z-20 w-full max-w-sm -rotate-1 xl:[zoom:1.2] xl:min-[1400px]:[zoom:1.4]\"\n                >\n                  <Wallet variant=\"noir\" status={walletStatus} className=\"max-w-none\">\n                    <WalletCards value={state.card} onValueChange={(id) => dispatch({ type: \"card\", id })} aria-label=\"Card to charge\">\n                      {cards.map((card) => (\n                        <WalletCard key={card.id} value={card.id} tone={card.tone}>\n                          <PaymentCardBrand>{card.brand}</PaymentCardBrand>\n                          <PaymentCardNumber last4={card.last4} />\n                        </WalletCard>\n                      ))}\n                    </WalletCards>\n                    <WalletPocket>\n                      <WalletHeader>\n                        <WalletLabel>Credit balance</WalletLabel>\n                        <WalletStatus />\n                      </WalletHeader>\n                      <WalletBalance value={state.balance} currency=\"USD\" />\n                      <WalletDetails>\n                        <WalletDetail>\n                          <WalletDetailLabel>Spent today</WalletDetailLabel>\n                          <WalletDetailValue>\n                            <WalletAmount value={spent} currency=\"USD\" />\n                          </WalletDetailValue>\n                        </WalletDetail>\n                        <WalletDetail>\n                          <WalletDetailLabel>Not yet settled</WalletDetailLabel>\n                          <WalletDetailValue>\n                            <WalletAmount value={state.pending.amount} currency=\"USD\" />\n                          </WalletDetailValue>\n                        </WalletDetail>\n                        <WalletDetail>\n                          <WalletDetailLabel>Runway</WalletDetailLabel>\n                          <WalletDetailValue>{runwayText(state)}</WalletDetailValue>\n                        </WalletDetail>\n                      </WalletDetails>\n                      <WalletFooter>\n                        <WalletAction onClick={goToTopUp}>\n                          <ArrowDown /> Top up\n                        </WalletAction>\n                      </WalletFooter>\n                    </WalletPocket>\n                  </Wallet>\n                </div>\n\n                {/* Each top-up prints a fresh receipt that slides out from under the wallet. */}\n                <div\n                  key={state.receipt.no}\n                  data-bevel-family=\"paper\"\n                  className={cn(\n                    \"relative z-10 -mt-5 w-full max-w-[18.5rem] rotate-2 self-end sm:mr-6 lg:mr-0 lg:self-center lg:translate-x-16\",\n                    printed &&\n                      \"transition-[translate,opacity] duration-(--bevel-duration-move) ease-(--bevel-ease-out) starting:-translate-y-16 starting:opacity-0 motion-reduce:transition-none\"\n                  )}\n                >\n                  <Receipt aria-label={`Receipt ${state.receipt.no}`}>\n                    <ReceiptHeader>\n                      <ReceiptTitle>Meterline credits</ReceiptTitle>\n                      <ReceiptMeta>\n                        {state.receipt.no}, {state.receipt.time}\n                      </ReceiptMeta>\n                    </ReceiptHeader>\n                    <ReceiptSeparator />\n                    <ReceiptItems>\n                      {state.receipt.lines.map((line) => (\n                        <ReceiptItem key={line.label}>\n                          <ReceiptLabel>{line.label}</ReceiptLabel>\n                          <ReceiptValue>{line.amount === 0 ? \"Free\" : <Amount value={line.amount} currency=\"USD\" />}</ReceiptValue>\n                        </ReceiptItem>\n                      ))}\n                      <ReceiptItem>\n                        <ReceiptLabel>Card</ReceiptLabel>\n                        <ReceiptValue>{state.receipt.card}</ReceiptValue>\n                      </ReceiptItem>\n                    </ReceiptItems>\n                    <ReceiptSeparator />\n                    <ReceiptTotal>\n                      <ReceiptLabel>Charged</ReceiptLabel>\n                      <ReceiptValue>\n                        <Amount value={state.receipt.total} currency=\"USD\" />\n                      </ReceiptValue>\n                    </ReceiptTotal>\n                    <ReceiptMark>\n                      <Stamp tone=\"green\" animate={printed}>\n                        Paid\n                        <StampDetail>{state.receipt.stampDate}</StampDetail>\n                      </Stamp>\n                    </ReceiptMark>\n                    <ReceiptFooter>billing@halvorsen.example</ReceiptFooter>\n                  </Receipt>\n                </div>\n              </div>\n            </section>\n\n            {/* The instruments: the spend counter, and the breaker panel beside it. */}\n            <div className=\"flex flex-col gap-10 lg:col-start-2 lg:row-start-2\">\n              <div className=\"grid gap-x-10 gap-y-10 xl:grid-cols-[minmax(0,22rem)_minmax(0,1fr)] [&>*]:min-w-0\">\n                <section aria-labelledby=\"ml-spend\" className=\"flex flex-col gap-4\">\n                  <Tooled id=\"ml-spend\">Spend today</Tooled>\n                  <Meter\n                    state={metering ? \"running\" : spent > 0 ? \"stopped\" : \"idle\"}\n                    aria-labelledby=\"ml-spend\"\n                    className=\"mx-auto rotate-[0.6deg] sm:mx-0\"\n                  >\n                    <MeterHeader className=\"justify-end\">\n                      <MeterFlag>{metering ? \"Metering\" : state.running ? \"Blocked\" : \"Paused\"}</MeterFlag>\n                    </MeterHeader>\n                    <div className=\"flex flex-col gap-1\">\n                      <MeterReading value={spent} currency=\"USD\" format={CENTS} />\n                      <MeterUnit>of {formatUsd(state.circuits.main.cap)} account cap</MeterUnit>\n                    </div>\n                    <div className=\"flex flex-col gap-0.5\">\n                      <MeterUnit>\n                        <Amount value={state.requests} format={WHOLE} /> requests today\n                      </MeterUnit>\n                      <MeterUnit>\n                        <Amount value={state.refused} format={WHOLE} /> refused by caps\n                      </MeterUnit>\n                    </div>\n                    <MeterFooter>\n                      <MeterButton disabled={state.pending.calls === 0} onClick={() => dispatch({ type: \"settle\" })}>\n                        Settle now\n                      </MeterButton>\n                    </MeterFooter>\n                  </Meter>\n                </section>\n\n                <section aria-labelledby=\"ml-caps\" className=\"flex flex-col gap-4\">\n                  <Tooled id=\"ml-caps\">Daily caps</Tooled>\n                  <BreakerPanel aria-labelledby=\"ml-caps\" className=\"w-fit max-w-full self-center sm:self-start\">\n                    <BreakerRow className=\"justify-center\">\n                      {([\"main\", ...trafficIds] as CircuitId[]).map((id) => {\n                        const c = state.circuits[id]\n                        const keyOk = id === \"main\" || keyValid(state.keys[id])\n                        return (\n                          <Breaker\n                            key={id}\n                            label={circuitLabel[id]}\n                            description={breakerDescription(id)}\n                            checked={c.on && keyOk}\n                            tripped={c.tripped}\n                            disabled={!keyOk}\n                            onCheckedChange={(on) => dispatch({ type: \"breaker\", id, on })}\n                          />\n                        )\n                      })}\n                    </BreakerRow>\n                  </BreakerPanel>\n                </section>\n              </div>\n\n              {/* A sheet of credit tickets, and the key that pays for the one torn off. */}\n              <section id=\"top-up\" aria-labelledby=\"ml-top-up\" className=\"flex scroll-mt-6 flex-col gap-4\">\n                <Tooled id=\"ml-top-up\" ref={topUpRef} tabIndex={-1} className=\"rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-[#C9A44A]\">\n                  Top up\n                </Tooled>\n                <div className=\"flex flex-col items-center gap-6 sm:flex-row sm:gap-10 lg:flex-col lg:items-start xl:flex-row xl:items-center\">\n                  <div data-bevel-family=\"paper\" className=\"w-full max-w-[21rem] -rotate-1 sm:w-[21rem] sm:shrink-0\">\n                    <TicketSheet aria-label=\"Credit pack\" value={state.pack} onValueChange={(id) => dispatch({ type: \"pack\", id: id as string })}>\n                      {packs.map((p) => (\n                        <Ticket key={p.id} value={p.id} tone={p.tone}>\n                          <TicketLabel>Credits</TicketLabel>\n                          <TicketValue>${p.credits}</TicketValue>\n                          <TicketNote>{p.note}</TicketNote>\n                        </Ticket>\n                      ))}\n                    </TicketSheet>\n                  </div>\n                  <div className=\"flex w-full max-w-[21rem] flex-col gap-4 sm:w-auto\">\n                    <p className=\"font-[family-name:var(--font-ledger)] text-[17px] leading-relaxed text-[#B8AA8E]\">\n                      Adds{\" \"}\n                      <span className=\"text-[#EADFC8]\">\n                        <Amount value={pack.credits + pack.bonus} currency=\"USD\" />\n                      </span>{\" \"}\n                      to the balance, charged to <span className=\"text-[#EADFC8]\">{cardName(state.card)}</span> from the wallet.\n                    </p>\n                    <PanelKey tone=\"go\" onClick={() => {\n                      dispatch({ type: \"pay\" })\n                      demoMilestone(\"meterline\", \"top_up\")\n                    }} className=\"h-12 gap-2 self-start text-[16px] [&_svg]:size-4\">\n                      <CreditCard aria-hidden /> Pay {formatUsd(pack.credits)}\n                    </PanelKey>\n                  </div>\n                </div>\n              </section>\n            </div>\n\n            {/* The ledger book, open across the foot of the blotter, and the card file of key slips. */}\n            <div className=\"grid gap-x-10 gap-y-10 lg:col-span-2 xl:grid-cols-[minmax(0,1fr)_auto] [&>*]:min-w-0\">\n              <section aria-labelledby=\"ml-ledger\" className=\"flex flex-col gap-4\">\n                <Tooled id=\"ml-ledger\">Ledger</Tooled>\n                <div className=\"relative -rotate-[0.4deg]\">\n                  <div\n                    data-bevel-family=\"paper\"\n                    className=\"bevel-leather rounded-[10px] p-2.5 shadow-[0_18px_30px_-14px_rgb(0_0_0/0.75)] [--bevel-material:#5B2A22]\"\n                  >\n                    <Ledger>\n                      <LedgerTitle>October 2026</LedgerTitle>\n                      <LedgerTable>\n                        <LedgerHeader>\n                          <LedgerRow>\n                            <LedgerHead>No.</LedgerHead>\n                            <LedgerHead>Time</LedgerHead>\n                            <LedgerHead>Entry</LedgerHead>\n                            <LedgerHead className=\"text-right\">Amount</LedgerHead>\n                            <LedgerHead className=\"text-right\">Balance</LedgerHead>\n                            <LedgerHead>Status</LedgerHead>\n                          </LedgerRow>\n                        </LedgerHeader>\n                        <LedgerBody>\n                          {state.entries.map((entry) => (\n                            <LedgerRow key={entry.no}>\n                              <LedgerCell>\n                                <LedgerNumber value={entry.no} />\n                              </LedgerCell>\n                              <LedgerCell className=\"whitespace-nowrap\">{entry.time}</LedgerCell>\n                              <LedgerCell className=\"whitespace-nowrap\">{entry.what.replace(\" · \", \", \")}</LedgerCell>\n                              <LedgerCell className=\"text-right\">\n                                <LedgerAmount value={entry.amount} currency=\"USD\" />\n                              </LedgerCell>\n                              <LedgerCell className=\"text-right\">\n                                <Amount value={entry.after} currency=\"USD\" />\n                              </LedgerCell>\n                              <LedgerCell>\n                                <Stamp tone={statusTone[entry.status]} className=\"px-1 py-0.5 text-(length:--bevel-fine)\">\n                                  {entry.status}\n                                </Stamp>\n                              </LedgerCell>\n                            </LedgerRow>\n                          ))}\n                        </LedgerBody>\n                      </LedgerTable>\n                    </Ledger>\n                  </div>\n                  {/* A ribbon marker hanging from the book. */}\n                  <span\n                    aria-hidden\n                    className=\"absolute right-14 -bottom-7 h-10 w-3 bg-[#9E2B25] shadow-[1px_2px_3px_rgb(0_0_0/0.4)] [clip-path:polygon(0_0,100%_0,100%_100%,50%_calc(100%-6px),0_100%)]\"\n                  />\n                </div>\n              </section>\n\n              <section aria-labelledby=\"ml-keys\" className=\"flex flex-col gap-4\">\n                <div className=\"flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1\">\n                  <Tooled id=\"ml-keys\">API keys</Tooled>\n                  {keysNote && <p className=\"font-[family-name:var(--font-ledger)] text-[17px] text-[#EADFC8]\">{keysNote}</p>}\n                </div>\n                <div data-bevel-family=\"paper\" className=\"flex flex-wrap justify-center gap-6 xl:flex-nowrap xl:justify-start xl:gap-0 xl:[&>*:not(:first-child)]:-ml-1\">\n                  {trafficIds.map((id, i) => {\n                    const dates = state.keys[id]\n                    const full = dates.length >= MAX_STAMPS\n                    return (\n                      <div\n                        key={id}\n                        className={cn(\n                          \"relative transition-[translate] duration-(--bevel-duration-small) ease-(--bevel-ease-out) hover:z-10 hover:-translate-y-1 focus-within:z-10 focus-within:-translate-y-1 motion-reduce:transition-none\",\n                          slipTilt[i % slipTilt.length]\n                        )}\n                      >\n                        <DueDateSlip className=\"w-48\" title={keyInfo[id].title.replace(\" · \", \", \")} dates={dates} now={NOW}>\n                          <DueDateSlipStatus />\n                          <DueDateSlipRenew onClick={() => dispatch({ type: \"renew\", id })} disabled={full}>\n                            {full ? \"Slip full: rotate key\" : \"Renew 90 days\"}\n                          </DueDateSlipRenew>\n                        </DueDateSlip>\n                      </div>\n                    )\n                  })}\n                </div>\n              </section>\n            </div>\n          </div>\n        </div>\n      </main>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/bevel-demos/meterline/meterline.tsx"
    },
    {
      "path": "registry/bevel/blocks/billing-desk/meterline/state.tsx",
      "content": "/** Meterline's account state: one reducer so a tick of traffic moves the meter, wallet, caps and ledger together. */\n\nexport const NOW = new Date(\"2026-10-17T00:00:00Z\")\nconst DAY = 86_400_000\n/** Simulated seconds per tick. Traffic runs at 60x: one 600ms tick is 36 seconds of the day. */\nexport const TICK_MS = 600\nexport const SIM_SECONDS_PER_TICK = 36\nconst SETTLE_EVERY = 8\nexport const LOW_BALANCE = 20\n\nexport type TrafficId = \"production\" | \"staging\" | \"batch\"\nexport type CircuitId = \"main\" | TrafficId\nexport type KeyId = TrafficId\n\nexport const traffic: Record<TrafficId, { name: string; min: number; max: number; price: number }> = {\n  production: { name: \"Production\", min: 180, max: 420, price: 0.0004 },\n  staging: { name: \"Staging\", min: 20, max: 80, price: 0.0002 },\n  batch: { name: \"Batch\", min: 60, max: 200, price: 0.0003 },\n}\nexport const trafficIds = Object.keys(traffic) as TrafficId[]\n\n/** How much a reset lifts a cap that's been hit, for the rest of the day. */\nexport const raiseBy: Record<CircuitId, number> = { main: 10, production: 5, staging: 2, batch: 2 }\n\nexport type Circuit = { on: boolean; tripped: boolean; cap: number; spent: number }\n\nexport type Entry = {\n  no: number\n  time: string\n  what: string\n  amount: number\n  after: number\n  status: \"Settled\" | \"Received\" | \"Bonus\"\n}\n\nexport type ReceiptData = {\n  no: string\n  time: string\n  card: string\n  lines: { label: string; amount: number }[]\n  total: number\n  stampDate: string\n}\n\nexport type Card = { id: string; brand: string; last4: string; tone: \"sapphire\" | \"gold\" | \"graphite\" }\nexport const cards: Card[] = [\n  { id: \"debit-8210\", brand: \"Debit\", last4: \"8210\", tone: \"gold\" },\n  { id: \"visa-4417\", brand: \"Visa\", last4: \"4417\", tone: \"sapphire\" },\n]\nexport const cardName = (id: string) => {\n  const card = cards.find((c) => c.id === id)!\n  return `${card.brand} ··${card.last4}`\n}\n\nexport const packs = [\n  { id: \"25\", credits: 25, bonus: 0, tone: \"vermilion\", note: \"Top-up\" },\n  { id: \"50\", credits: 50, bonus: 0, tone: \"ultramarine\", note: \"Most bought\" },\n  { id: \"100\", credits: 100, bonus: 4, tone: \"emerald\", note: \"+ $4 bonus\" },\n  { id: \"250\", credits: 250, bonus: 15, tone: \"ochre\", note: \"+ $15 bonus\" },\n] as const\n\nexport const keyInfo: Record<KeyId, { title: string; uses: string }> = {\n  production: { title: \"Production · ml_live_…7c1e\", uses: \"Signs requests on the production circuit.\" },\n  staging: { title: \"Staging · ml_test_…09ab\", uses: \"Signs requests on the staging circuit.\" },\n  batch: { title: \"Batch worker · ml_live_…a3d0\", uses: \"Signs nightly and batch jobs.\" },\n}\nexport const MAX_STAMPS = 6\n\nexport type State = {\n  running: boolean\n  clock: number\n  ticks: number\n  balance: number\n  /** Balance as of the last ledger line, in exact cents. */\n  ledgerBalance: number\n  requests: number\n  refused: number\n  circuits: Record<CircuitId, Circuit>\n  pending: { calls: number; amount: number }\n  entries: Entry[]\n  nextNo: number\n  keys: Record<KeyId, string[]>\n  card: string\n  pack: string\n  receipt: ReceiptData\n  receiptNo: number\n  event: string\n}\n\nconst round2 = (n: number) => Math.round(n * 100) / 100\nconst usd = (n: number) =>\n  n.toLocaleString(\"en-US\", { style: \"currency\", currency: \"USD\" })\nexport const formatUsd = usd\n\nconst pad = (n: number) => String(n).padStart(2, \"0\")\nexport function clockText(seconds: number) {\n  const s = Math.min(seconds, 23 * 3600 + 59 * 60)\n  return `${pad(Math.floor(s / 3600))}:${pad(Math.floor((s % 3600) / 60))}`\n}\nconst stampTime = (seconds: number) => `17 Oct ${clockText(seconds)}`\n\nconst iso = (d: Date) => d.toISOString().slice(0, 10)\nconst longDate = (d: Date) =>\n  d.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"short\", year: \"numeric\", timeZone: \"UTC\" })\n\nexport function keyValid(dates: string[]) {\n  const last = dates.at(-1)\n  return last ? new Date(last) >= NOW : false\n}\n\nexport function totalSpent(circuits: Record<CircuitId, Circuit>) {\n  return trafficIds.reduce((sum, id) => sum + circuits[id].spent, 0)\n}\n\nexport function flowing(state: State, id: TrafficId) {\n  const main = state.circuits.main\n  const c = state.circuits[id]\n  return main.on && !main.tripped && c.on && !c.tripped && keyValid(state.keys[id])\n}\n\n/** Expected spend per simulated hour from what's flowing right now. */\nexport function hourlyRate(state: State) {\n  const perTick = trafficIds\n    .filter((id) => flowing(state, id))\n    .reduce((sum, id) => sum + ((traffic[id].min + traffic[id].max) / 2) * traffic[id].price, 0)\n  return (perTick * 3600) / SIM_SECONDS_PER_TICK\n}\n\nexport const initialState: State = {\n  running: false,\n  clock: 14 * 3600 + 2 * 60,\n  ticks: 0,\n  balance: 48.6,\n  ledgerBalance: 48.6,\n  requests: 36_212,\n  refused: 0,\n  circuits: {\n    main: { on: true, tripped: false, cap: 25, spent: 0 },\n    production: { on: true, tripped: false, cap: 15, spent: 10.8 },\n    staging: { on: false, tripped: false, cap: 3, spent: 0 },\n    batch: { on: true, tripped: false, cap: 6, spent: 3.69 },\n  },\n  pending: { calls: 0, amount: 0 },\n  entries: [\n    { no: 118, time: \"17 Oct 13:58\", what: \"Usage · 4,812 calls\", amount: -1.93, after: 48.6, status: \"Settled\" },\n    { no: 117, time: \"17 Oct 12:00\", what: \"Usage · 31,400 calls\", amount: -12.56, after: 50.53, status: \"Settled\" },\n    { no: 116, time: \"16 Oct 23:59\", what: \"Usage · day close\", amount: -54.91, after: 63.09, status: \"Settled\" },\n    { no: 115, time: \"12 Oct 10:41\", what: \"Credits · Visa ··4417\", amount: 100, after: 118, status: \"Received\" },\n  ],\n  nextNo: 119,\n  keys: {\n    production: [\"2026-04-23\", \"2026-07-22\", \"2026-10-21\"],\n    staging: [\"2026-07-16\", \"2026-10-14\"],\n    batch: [\"2026-11-07\"],\n  },\n  card: \"visa-4417\",\n  pack: \"50\",\n  receipt: {\n    no: \"R-0412\",\n    time: \"12 Oct 2026, 10:41\",\n    card: \"Visa ··4417\",\n    lines: [{ label: \"100 credits\", amount: 100 }],\n    total: 100,\n    stampDate: \"12 Oct\",\n  },\n  receiptNo: 413,\n  event: \"Traffic paused. Start traffic to watch spend run.\",\n}\n\nexport type Action =\n  | { type: \"tick\"; draws: Record<TrafficId, number> }\n  | { type: \"start\" }\n  | { type: \"pause\" }\n  | { type: \"settle\" }\n  | { type: \"breaker\"; id: CircuitId; on: boolean }\n  | { type: \"renew\"; id: KeyId }\n  | { type: \"card\"; id: string }\n  | { type: \"pack\"; id: string }\n  | { type: \"pay\" }\n\nconst MAX_ENTRIES = 12\n\n/** Post unsettled usage to the ledger as one line. Keeps the ledger's arithmetic exact in cents. */\nfunction settle(state: State): State {\n  const posted = round2(state.pending.amount)\n  if (state.pending.calls === 0 || posted < 0.01) return state\n  const after = round2(state.ledgerBalance - posted)\n  const entry: Entry = {\n    no: state.nextNo,\n    time: stampTime(state.clock),\n    what: `Usage · ${state.pending.calls.toLocaleString(\"en-US\")} calls`,\n    amount: -posted,\n    after,\n    status: \"Settled\",\n  }\n  return {\n    ...state,\n    ledgerBalance: after,\n    pending: { calls: 0, amount: state.pending.amount - posted },\n    entries: [entry, ...state.entries].slice(0, MAX_ENTRIES),\n    nextNo: state.nextNo + 1,\n  }\n}\n\nfunction tick(state: State, draws: Record<TrafficId, number>): State {\n  if (!state.running) return state\n  const circuits = { ...state.circuits }\n  let balance = state.balance\n  let calls = 0\n  let amount = 0\n  let refused = state.refused\n  let event: string | null = null\n  let empty = false\n\n  for (const id of trafficIds) {\n    const c = circuits[id]\n    const want = Math.round(traffic[id].min + draws[id] * (traffic[id].max - traffic[id].min))\n    if (!c.on || !keyValid(state.keys[id])) continue\n    if (c.tripped || circuits.main.tripped || !circuits.main.on) {\n      refused += want\n      continue\n    }\n    let cost = want * traffic[id].price\n    let n = want\n    const ownRoom = c.cap - c.spent\n    const mainRoom = circuits.main.cap - totalSpent(circuits)\n    const room = Math.min(ownRoom, mainRoom, balance)\n    if (cost >= room) {\n      n = Math.floor((want * Math.max(room, 0)) / cost)\n      cost = Math.max(room, 0)\n      refused += want - n\n      if (room === balance) {\n        empty = true\n        event = \"Out of credit. All traffic stopped. Top up to send requests again.\"\n      } else if (room === ownRoom) {\n        circuits[id] = { ...c, tripped: true }\n        event = `${traffic[id].name} cap tripped at ${usd(c.cap)}. Requests on ${traffic[id].name.toLowerCase()} are refused until you reset it.`\n      } else {\n        circuits.main = { ...circuits.main, tripped: true }\n        event = `Account cap tripped at ${usd(circuits.main.cap)}. Every request is refused until you reset the main breaker.`\n      }\n    }\n    circuits[id] = { ...circuits[id], spent: circuits[id].spent + cost }\n    balance = Math.max(0, balance - cost)\n    calls += n\n    amount += cost\n    if (empty) break\n  }\n\n  const next: State = {\n    ...state,\n    circuits,\n    balance: empty ? 0 : balance,\n    running: !empty,\n    clock: state.clock + SIM_SECONDS_PER_TICK,\n    ticks: state.ticks + 1,\n    requests: state.requests + calls,\n    refused,\n    pending: { calls: state.pending.calls + calls, amount: state.pending.amount + amount },\n    event: event ?? state.event,\n  }\n  return event || next.ticks % SETTLE_EVERY === 0 ? settle(next) : next\n}\n\nexport function reducer(state: State, action: Action): State {\n  switch (action.type) {\n    case \"tick\":\n      return tick(state, action.draws)\n    case \"start\":\n      if (state.balance <= 0) return state\n      return { ...state, running: true, event: \"Traffic running. Usage settles to the ledger every few minutes.\" }\n    case \"pause\":\n      return settle({ ...state, running: false, event: \"Traffic paused.\" })\n    case \"settle\":\n      return settle(state)\n    case \"card\":\n      return { ...state, card: action.id }\n    case \"pack\":\n      return { ...state, pack: action.id }\n    case \"breaker\": {\n      const c = state.circuits[action.id]\n      const name = action.id === \"main\" ? \"Account\" : traffic[action.id].name\n      if (c.tripped && action.on) {\n        const spent = action.id === \"main\" ? totalSpent(state.circuits) : c.spent\n        const cap = spent >= c.cap - 0.005 ? c.cap + raiseBy[action.id] : c.cap\n        return settle({\n          ...state,\n          circuits: { ...state.circuits, [action.id]: { ...c, tripped: false, on: true, cap } },\n          event: `${name} cap reset${cap > c.cap ? ` and raised to ${usd(cap)} for today` : \"\"}.`,\n        })\n      }\n      return settle({\n        ...state,\n        circuits: { ...state.circuits, [action.id]: { ...c, on: action.on, tripped: false } },\n        event:\n          action.id === \"main\"\n            ? action.on\n              ? \"Main breaker on. Traffic can flow.\"\n              : \"Main breaker off. Every request is refused.\"\n            : `${name} circuit switched ${action.on ? \"on\" : \"off\"}.`,\n      })\n    }\n    case \"renew\": {\n      const dates = state.keys[action.id]\n      if (dates.length >= MAX_STAMPS) return state\n      const last = new Date(dates.at(-1)!)\n      const from = last < NOW ? NOW : last\n      const due = new Date(from.getTime() + 90 * DAY)\n      const wasExpired = !keyValid(dates)\n      return {\n        ...state,\n        keys: { ...state.keys, [action.id]: [...dates, iso(due)] },\n        event: `${traffic[action.id].name} key renewed to ${longDate(due)}.${\n          wasExpired ? ` Switch the ${traffic[action.id].name.toLowerCase()} breaker on to send traffic.` : \"\"\n        }`,\n      }\n    }\n    case \"pay\": {\n      const pack = packs.find((p) => p.id === state.pack)!\n      const settled = settle(state)\n      const time = stampTime(settled.clock)\n      const card = cardName(settled.card)\n      const afterCredits = round2(settled.ledgerBalance + pack.credits)\n      const lines: Entry[] = [\n        {\n          no: settled.nextNo,\n          time,\n          what: `Credits · ${card}`,\n          amount: pack.credits,\n          after: afterCredits,\n          status: \"Received\",\n        },\n      ]\n      if (pack.bonus) {\n        lines.unshift({\n          no: settled.nextNo + 1,\n          time,\n          what: `Bonus on ${usd(pack.credits)} pack`,\n          amount: pack.bonus,\n          after: round2(afterCredits + pack.bonus),\n          status: \"Bonus\",\n        })\n      }\n      const added = pack.credits + pack.bonus\n      return {\n        ...settled,\n        balance: settled.balance + added,\n        ledgerBalance: round2(settled.ledgerBalance + added),\n        entries: [...lines, ...settled.entries].slice(0, MAX_ENTRIES),\n        nextNo: settled.nextNo + lines.length,\n        receiptNo: settled.receiptNo + 1,\n        receipt: {\n          no: `R-0${settled.receiptNo}`,\n          time: `17 Oct 2026, ${clockText(settled.clock)}`,\n          card,\n          lines: pack.bonus\n            ? [\n                { label: `${pack.credits} credits`, amount: pack.credits },\n                { label: `${pack.bonus} bonus credits`, amount: 0 },\n              ]\n            : [{ label: `${pack.credits} credits`, amount: pack.credits }],\n          total: pack.credits,\n          stampDate: \"17 Oct\",\n        },\n        event: `Paid ${usd(pack.credits)} with ${card}. ${usd(added)} added to the balance.${\n          settled.running || settled.balance > 0 ? \"\" : \" Start traffic again when you're ready.\"\n        }`,\n      }\n    }\n  }\n}\n",
      "type": "registry:component",
      "target": "components/bevel-demos/meterline/state.tsx"
    },
    {
      "path": "registry/bevel/blocks/billing-desk/shared/environment.tsx",
      "content": "import * as React from \"react\"\nimport { cn } from \"@/lib/utils\"\n\n/**\n * Pieces of the physical environments the demos are set in. Each demo\n * mounts Bevel components on a surface; these are the surface's own parts.\n */\n\n/** A legend engraved into the surface: names the control below it. */\nexport function Legend({ className, ...props }: React.ComponentProps<\"p\">) {\n  return (\n    <p\n      className={cn(\n        \"text-[15px] leading-none font-semibold tracking-wide text-(--legend) [text-shadow:0_-1px_0_rgb(0_0_0/0.45),0_1px_0_rgb(255_255_255/0.08)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\n/** A slotted screw head, for panel corners. */\nexport function Screw({ className, angle = 30 }: { className?: string; angle?: number }) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\"bevel-metal absolute size-3.5 rounded-full shadow-(--bevel-depth-raised)\", className)}\n    >\n      <span className=\"absolute inset-x-0.5 top-1/2 h-px -translate-y-1/2 bg-black/50\" style={{ rotate: `${angle}deg` }} />\n    </span>\n  )\n}\n\n/** Four screws, one in each corner of a positioned panel. */\nconst screwCorners = {\n  \"2\": [\"top-2 left-2\", \"top-2 right-2\", \"bottom-2 left-2\", \"bottom-2 right-2\"],\n  \"3\": [\"top-3 left-3\", \"top-3 right-3\", \"bottom-3 left-3\", \"bottom-3 right-3\"],\n  \"4\": [\"top-4 left-4\", \"top-4 right-4\", \"bottom-4 left-4\", \"bottom-4 right-4\"],\n} as const\n\nexport function Screws({ inset = \"3\" }: { inset?: keyof typeof screwCorners }) {\n  return (\n    <>\n      {screwCorners[inset].map((c, i) => (\n        <Screw key={c} className={c} angle={[20, 75, 130, 160][i]} />\n      ))}\n    </>\n  )\n}\n\n/** A physical key: a raised plastic button that goes down when pressed. */\nexport function PanelKey({ className, tone = \"plain\", ...props }: React.ComponentProps<\"button\"> & { tone?: \"plain\" | \"go\" }) {\n  return (\n    <button\n      type=\"button\"\n      data-tone={tone}\n      className={cn(\n        \"bevel-raised inline-flex h-11 items-center whitespace-nowrap justify-center rounded-(--bevel-radius-sm) px-5 text-[15px] font-semibold outline-none select-none\",\n        \"[--bevel-material:#5B636B] text-[#EEF1F3] data-[tone=go]:[--bevel-material:#C9A44A] data-[tone=go]:text-[#2A2208]\",\n        \"transition-[translate,box-shadow] duration-(--bevel-duration-press) active:translate-y-0.5 active:bevel-pressed\",\n        \"focus-visible:ring-3 focus-visible:ring-[#E9D28A]/60 disabled:opacity-50\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\n/** A backlit status strip: one line of glowing text behind glass. */\nexport function StatusStrip({ className, children }: { className?: string; children: React.ReactNode }) {\n  return (\n    <div\n      className={cn(\n        \"relative overflow-hidden rounded-(--bevel-radius-sm) bg-[#0E1A17] px-4 py-3 shadow-(--bevel-depth-recessed)\",\n        className\n      )}\n    >\n      <p className=\"text-[17px] sm:truncate tracking-wide text-[#8FF0CF] [text-shadow:0_0_8px_rgb(143_240_207/0.55)]\">{children}</p>\n      <span aria-hidden className=\"bevel-glass absolute inset-0\" />\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/bevel-demos/shared/environment.tsx"
    },
    {
      "path": "registry/bevel/blocks/billing-desk/shared/events.ts",
      "content": "/**\n * Announces a milestone in a demo (a merge, a top-up) as a DOM event. It\n * does nothing on its own; a page that wants to count milestones listens\n * for \"bevel:demo\". The Bevel site forwards them to its analytics.\n */\nexport function demoMilestone(demo: string, action: string) {\n  if (typeof window === \"undefined\") return\n  window.dispatchEvent(new CustomEvent(\"bevel:demo\", { detail: { demo, action } }))\n}\n",
      "type": "registry:component",
      "target": "components/bevel-demos/shared/events.ts"
    },
    {
      "path": "registry/bevel/blocks/billing-desk/shared/fonts.ts",
      "content": "import { Barlow_Condensed, Libre_Caslon_Text, Overpass, Source_Serif_4 } from \"next/font/google\"\n\n/** Each demo product has its own type voice, drawn from its world. */\n\n/** Relay: console legends, the condensed grotesk of control-room engraving. */\nexport const consoleFace = Barlow_Condensed({ subsets: [\"latin\"], weight: [\"500\", \"600\", \"700\"], variable: \"--font-console\" })\n\n/** Meterline: a ledger serif, for a desk where money is written down. */\nexport const ledgerFace = Libre_Caslon_Text({ subsets: [\"latin\"], weight: [\"400\", \"700\"], variable: \"--font-ledger\" })\n\n/** Shipyard: highway-sign lettering, for a board read from across a room. */\nexport const signFace = Overpass({ subsets: [\"latin\"], weight: [\"400\", \"600\", \"800\"], variable: \"--font-sign\" })\n\n/** Casefile: a document serif, for papers on a desk. */\nexport const documentFace = Source_Serif_4({ subsets: [\"latin\"], weight: [\"400\", \"600\", \"700\"], variable: \"--font-document\" })\n",
      "type": "registry:component",
      "target": "components/bevel-demos/shared/fonts.ts"
    },
    {
      "path": "registry/bevel/blocks/billing-desk/page.tsx",
      "content": "import { Meterline } from \"@/components/bevel-demos/meterline/meterline\"\n\nexport default function Page() {\n  return <Meterline />\n}\n",
      "type": "registry:page",
      "target": "app/billing-desk/page.tsx"
    }
  ],
  "categories": [
    "blocks"
  ],
  "type": "registry:block"
}