{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-billing-plan",
  "type": "registry:block",
  "title": "App, plan and usage",
  "description": "The current plan on one card: name, price, what is included, usage meters (native meter elements; the band is said in words at 70%, 90% and over the limit, and a limit without a number such as Unlimited draws no meter), and manage and upgrade actions. Active, trial and past-due states.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/badge.json",
    "https://ui.klarhimmel.com/r/banner.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-app.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-billing-plan/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-billing-plan/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, link, t, req } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  plan: z.object({ name: t(40), badge: t(20).optional(), price: t(20), interval: t(20) }),\n  features: z.array(t(80)).min(2).max(6),\n  /** The word between the two numbers: \"1 800 of 2 000 messages\". */\n  of: t(10),\n  /**\n   * Meters. Values are numbers written as text (\"1800\", \"1,840\", \"1 840\", \"12 000\"). A limit with no number in it\n   * (\"Unlimited\") draws no meter and warns about nothing. Words are said at 70% (warn), 90% (critical) and over the limit.\n   */\n  usage: z.array(z.object({ label: req(40), used: t(12), limit: t(12), unit: t(20) })).min(1).max(4),\n  /** Said after a meter's numbers: at 70% to 89% (warnLimit), 90% to 100% (nearLimit), and above 100% (overLimit). */\n  warnLimit: t(40),\n  nearLimit: t(40),\n  overLimit: t(40),\n  manage: link,\n  upgrade: link,\n  /** active: nothing to say. trial: a notice with the days left. pastDue: an error notice. */\n  state: z.enum(['active', 'trial', 'pastDue']),\n  notices: z.object({ trial: t(160), pastDue: t(160) }),\n});\n\nexport const spec = defineSpec({\n  type: 'app-billing-plan',\n  aliases: ['app/billing-plan'],\n  name: 'App, plan and usage',\n  category: 'app',\n  role: 'body',\n  description: 'The current plan on one card: name, price, what is included, usage meters (native meter elements; the band is said in words at 70%, 90% and over the limit, and a limit without a number such as Unlimited draws no meter), and manage and upgrade actions. Active, trial and past-due states.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Billing\",\n    \"title\": \"Your plan\",\n    \"description\": \"Say what the plan covers and how much of it is used.\",\n    \"plan\": {\n      \"name\": \"Name it\",\n      \"badge\": \"Current plan\",\n      \"price\": \"$00\",\n      \"interval\": \"per month\"\n    },\n    \"features\": [\n      \"Say the first limit\",\n      \"Say the second limit\",\n      \"Say the first extra included\",\n      \"Say the support included\"\n    ],\n    \"of\": \"in\",\n    \"usage\": [\n      {\n        \"label\": \"Name a limit\",\n        \"used\": \"12\",\n        \"limit\": \"15\",\n        \"unit\": \"units\"\n      },\n      {\n        \"label\": \"Name another limit\",\n        \"used\": \"1840\",\n        \"limit\": \"2000\",\n        \"unit\": \"items\"\n      }\n    ],\n    \"warnLimit\": \"Getting close\",\n    \"nearLimit\": \"Almost full\",\n    \"overLimit\": \"Over the limit\",\n    \"manage\": {\n      \"label\": \"Manage billing\",\n      \"href\": \"#manage\"\n    },\n    \"upgrade\": {\n      \"label\": \"Upgrade plan\",\n      \"href\": \"#upgrade\"\n    },\n    \"state\": \"active\",\n    \"notices\": {\n      \"trial\": \"Say when the trial ends and what to do to keep what they have.\",\n      \"pastDue\": \"Say the payment failed and what to update to stay online.\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-billing-plan/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-billing-plan/index.tsx",
      "content": "import { useId } from 'react';\nimport { Check } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Badge } from '../../ui/badge';\nimport { Banner } from '../../ui/banner';\nimport { Container, Section, SectionHeader, ActionLink, useEditing } from '../_shared/kit';\nimport { AppPanel, StateSlot, parseAmount } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nconst meter =\n  'h-2 w-full appearance-none overflow-hidden rounded-kh-pill [&::-moz-meter-bar]:bg-kh-accent [&::-webkit-meter-bar]:bg-kh-surface-3 [&::-webkit-meter-even-less-good-value]:bg-kh-danger [&::-webkit-meter-optimum-value]:bg-kh-accent [&::-webkit-meter-suboptimum-value]:bg-kh-ink-2';\n\nfunction AppBillingPlan({ props }: BlockProps<Props>) {\n  const id = useId();\n  const { state } = props;\n  const editing = useEditing();\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <StateSlot show={state === 'trial'} className=\"mt-10\">\n          <Banner tone=\"info\">\n            <Text path={['notices', 'trial']} value={props.notices.trial} as=\"span\" />\n          </Banner>\n        </StateSlot>\n        <StateSlot show={state === 'pastDue'} className=\"mt-10\">\n          <Banner tone=\"error\">\n            <Text path={['notices', 'pastDue']} value={props.notices.pastDue} as=\"span\" />\n          </Banner>\n        </StateSlot>\n        <AppPanel className=\"mt-10\">\n          <div className=\"flex flex-col gap-6 p-6 @xl:p-8\">\n            <div className=\"flex flex-wrap items-start justify-between gap-4\">\n              <div>\n                <div className=\"flex flex-wrap items-center gap-3\">\n                  <Text path={['plan', 'name']} value={props.plan.name} as=\"h3\" className=\"text-kh-heading font-semibold\" />\n                  {(props.plan.badge || editing) && (\n                    <Badge tone=\"accent\">\n                      <Text path={['plan', 'badge']} value={props.plan.badge ?? ''} as=\"span\" />\n                    </Badge>\n                  )}\n                </div>\n                <ul className=\"mt-4 flex flex-col gap-2\">\n                  {props.features.map((f, i) => (\n                    <li key={i} className=\"flex items-start gap-2 text-kh-small text-kh-ink-2\">\n                      <Check aria-hidden className=\"mt-0.5 size-4 shrink-0 text-kh-accent-ink\" />\n                      <Text path={['features', i]} value={f} as=\"span\" />\n                    </li>\n                  ))}\n                </ul>\n              </div>\n              <p className=\"text-right\">\n                <Text path={['plan', 'price']} value={props.plan.price} as=\"span\" className=\"block text-kh-title font-semibold tabular-nums\" />\n                <Text path={['plan', 'interval']} value={props.plan.interval} as=\"span\" className=\"text-kh-small text-kh-muted\" />\n              </p>\n            </div>\n            {/* No usage and no actions: no divider bands with nothing between them (Klar Portal 10-24, the free plan on /ws). */}\n            {(props.usage.length > 0 || editing) && (\n            <ul className=\"flex flex-col gap-5 border-t border-kh-line pt-6\">\n              {props.usage.map((u, i) => {\n                const used = Math.max(0, parseAmount(u.used) ?? 0);\n                const parsed = parseAmount(u.limit);\n                const limit = parsed !== null && parsed > 0 ? parsed : null; // no number: unlimited\n                const ratio = limit === null ? 0 : used / limit;\n                const band = limit === null ? '' : ratio > 1 ? 'over' : ratio >= 0.9 ? 'critical' : ratio >= 0.7 ? 'warn' : '';\n                const mid = `${id}-m${i}`;\n                const words = [['over', 'overLimit'], ['critical', 'nearLimit'], ['warn', 'warnLimit']] as const;\n                return (\n                  <li key={i} className=\"flex flex-col gap-2\">\n                    <div className=\"flex flex-wrap items-baseline justify-between gap-x-4 text-kh-small\">\n                      <label htmlFor={mid} className=\"font-medium\">\n                        <Text path={['usage', i, 'label']} value={u.label} as=\"span\" />\n                      </label>\n                      <p className=\"tabular-nums text-kh-muted\">\n                        <Text path={['usage', i, 'used']} value={u.used} as=\"span\" />{' '}\n                        {limit === null ? (\n                          <>\n                            <Text path={['usage', i, 'unit']} value={u.unit} as=\"span\" /> · <Text path={['usage', i, 'limit']} value={u.limit} as=\"span\" />\n                          </>\n                        ) : (\n                          <>\n                            <Text path={['of']} value={props.of} as=\"span\" /> <Text path={['usage', i, 'limit']} value={u.limit} as=\"span\" />{' '}\n                            <Text path={['usage', i, 'unit']} value={u.unit} as=\"span\" />\n                          </>\n                        )}\n                        {words.map(([k, prop]) => (\n                          <span key={k} hidden={band !== k} className={band === 'warn' ? 'ml-2 font-medium text-kh-ink' : 'ml-2 font-medium text-kh-danger'}>\n                            <Text path={[prop]} value={props[prop]} as=\"span\" />\n                          </span>\n                        ))}\n                      </p>\n                    </div>\n                    {limit !== null ? (\n                      <meter id={mid} min={0} max={limit} low={limit * 0.7} high={limit * 0.9} optimum={0} value={Math.min(used, limit)} className={meter} />\n                    ) : (\n                      <span id={mid} hidden />\n                    )}\n                  </li>\n                );\n              })}\n            </ul>\n            )}\n            {(props.manage.label || props.upgrade.label || editing) && (\n              <div className=\"flex flex-wrap justify-end gap-3 border-t border-kh-line pt-6\">\n                <ActionLink path={['manage']} value={props.manage} variant=\"secondary\" size=\"md\" />\n                <ActionLink path={['upgrade']} value={props.upgrade} variant=\"primary\" size=\"md\" />\n              </div>\n            )}\n          </div>\n        </AppPanel>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppBillingPlan);\n"
    }
  ]
}
