{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pricing-usage-calculator",
  "type": "registry:component",
  "title": "Pricing Usage Calculator",
  "description": "Four metered sliders with free allowances hatched on the track feed a live receipt with a stacked cost bar. It also points to the cheapest flat plan that covers the usage and shows the monthly saving.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "pricing",
    "pricing",
    "calculator",
    "usage",
    "metered",
    "slider",
    "receipt"
  ],
  "docs": "https://hyperblur.dev/effects/pricing-usage-calculator",
  "files": [
    {
      "path": "registry/hyperblur/pricing-usage-calculator.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/pricing-usage-calculator.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PricingUsageMeter {\n  id: string;\n  label: string;\n  unit: string;\n  min: number;\n  max: number;\n  step: number;\n  included: number;\n  rate: number;\n  defaultValue: number;\n  color: string;\n}\n\nexport interface PricingUsagePlan {\n  name: string;\n  price: number;\n  limits: Record<string, number>;\n}\n\nexport interface PricingUsageCalculatorProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\" | \"onChange\"> {\n  eyebrow?: string;\n  title?: string;\n  subtitle?: string;\n  meters?: PricingUsageMeter[];\n  baseFee?: number;\n  plans?: PricingUsagePlan[];\n  currency?: string;\n  locale?: string;\n  defaultValues?: Record<string, number>;\n  onChange?: (values: Record<string, number>, total: number) => void;\n  cta?: { label: string; href: string };\n  accent?: string;\n}\n\nconst defaultMeters: PricingUsageMeter[] = [\n  { id: \"requests\", label: \"API requests\", unit: \"M req\", min: 0, max: 50, step: 1, included: 2, rate: 3.2, defaultValue: 14, color: \"#2f7bff\" },\n  { id: \"storage\", label: \"Storage\", unit: \"GB\", min: 0, max: 2000, step: 25, included: 100, rate: 0.021, defaultValue: 650, color: \"#a78bfa\" },\n  { id: \"bandwidth\", label: \"Bandwidth\", unit: \"TB\", min: 0, max: 20, step: 0.5, included: 1, rate: 8, defaultValue: 4.5, color: \"#34d399\" },\n  { id: \"builds\", label: \"Build minutes\", unit: \"min\", min: 0, max: 20000, step: 250, included: 1000, rate: 0.004, defaultValue: 6000, color: \"#f5a524\" },\n];\n\nconst defaultPlans: PricingUsagePlan[] = [\n  { name: \"Hobby\", price: 0, limits: { requests: 2, storage: 100, bandwidth: 1, builds: 1000 } },\n  { name: \"Pro\", price: 79, limits: { requests: 25, storage: 1000, bandwidth: 10, builds: 10000 } },\n  { name: \"Business\", price: 249, limits: { requests: 50, storage: 2000, bandwidth: 20, builds: 20000 } },\n];\n\nconst css = `\n.hb-vh2 {\n  --hb-vh2-accent: #2f7bff;\n  container-type: inline-size;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-vh2 *, .hb-vh2 *::before, .hb-vh2 *::after { box-sizing: border-box; }\n.hb-vh2-inner { max-width: 1080px; margin: 0 auto; padding: 64px 20px; }\n.hb-vh2-eyebrow { margin: 0 0 12px; color: #8f8f8f; font-family: var(--font-mono), ui-monospace, monospace; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }\n.hb-vh2-eyebrow b { color: var(--hb-vh2-accent); font-weight: 500; }\n.hb-vh2-title { margin: 0; max-width: 620px; font-size: clamp(28px, 4.4cqi, 42px); font-weight: 650; line-height: 1.08; letter-spacing: -.03em; text-wrap: balance; }\n.hb-vh2-sub { margin: 12px 0 0; max-width: 540px; color: #8f8f8f; font-size: 15.5px; line-height: 1.6; }\n.hb-vh2-body { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 36px; }\n@container (min-width: 780px) { .hb-vh2-body { grid-template-columns: 1.25fr 1fr; } }\n.hb-vh2-panel {\n  border: 1px solid rgba(255, 255, 255, .08);\n  border-radius: 20px;\n  background: linear-gradient(180deg, #121214, #0d0d0f);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);\n}\n.hb-vh2-meters { display: grid; gap: 6px; padding: 10px; }\n.hb-vh2-meter { padding: 14px 14px 12px; border-radius: 14px; transition: background-color .25s ease; }\n.hb-vh2-meter:hover, .hb-vh2-meter:focus-within { background: rgba(255, 255, 255, .025); }\n.hb-vh2-mhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }\n.hb-vh2-mlabel { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 550; }\n.hb-vh2-dot { width: 8px; height: 8px; border-radius: 3px; background: var(--c); box-shadow: 0 0 10px var(--c); }\n.hb-vh2-mval { font-family: var(--font-mono), ui-monospace, monospace; font-size: 13px; color: #ededed; font-variant-numeric: tabular-nums; }\n.hb-vh2-mval small { color: #6f6f6f; font-size: 12px; }\n.hb-vh2-range { position: relative; height: 26px; margin-top: 8px; }\n.hb-vh2-rail { position: absolute; left: 0; right: 0; top: 11px; height: 4px; border-radius: 999px; background: #232326; overflow: hidden; }\n.hb-vh2-free { position: absolute; left: 0; top: 0; bottom: 0; background: repeating-linear-gradient(90deg, rgba(255, 255, 255, .22) 0 2px, transparent 2px 5px); }\n.hb-vh2-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--c); border-radius: 999px; transition: width .12s ease-out; }\n.hb-vh2-input {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  margin: 0;\n  background: transparent;\n  -webkit-appearance: none;\n  appearance: none;\n  cursor: pointer;\n}\n.hb-vh2-input::-webkit-slider-runnable-track { height: 26px; background: transparent; }\n.hb-vh2-input::-moz-range-track { height: 26px; background: transparent; }\n.hb-vh2-input::-webkit-slider-thumb {\n  -webkit-appearance: none;\n  width: 18px;\n  height: 18px;\n  margin-top: 4px;\n  border-radius: 999px;\n  border: 0;\n  background: #fff;\n  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 35%, transparent), 0 2px 6px rgba(0, 0, 0, .5);\n  transition: box-shadow .2s ease, transform .2s cubic-bezier(.34, 1.56, .64, 1);\n}\n.hb-vh2-input::-moz-range-thumb {\n  width: 18px;\n  height: 18px;\n  border-radius: 999px;\n  border: 0;\n  background: #fff;\n  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 35%, transparent), 0 2px 6px rgba(0, 0, 0, .5);\n}\n.hb-vh2-input:active::-webkit-slider-thumb { transform: scale(1.15); }\n.hb-vh2-input:focus-visible { outline: none; }\n.hb-vh2-input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--c), 0 0 0 7px rgba(255, 255, 255, .25); }\n.hb-vh2-input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--c), 0 0 0 7px rgba(255, 255, 255, .25); }\n.hb-vh2-mfoot { display: flex; justify-content: space-between; margin-top: 4px; color: #6f6f6f; font-size: 11.5px; font-variant-numeric: tabular-nums; }\n.hb-vh2-receipt { display: flex; flex-direction: column; padding: 22px; }\n.hb-vh2-total-label { color: #8f8f8f; font-size: 13px; }\n.hb-vh2-total { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; }\n.hb-vh2-total strong { font-size: 44px; font-weight: 650; letter-spacing: -.04em; font-variant-numeric: tabular-nums; line-height: 1; }\n.hb-vh2-total span { color: #8f8f8f; font-size: 13.5px; }\n.hb-vh2-stack { display: flex; height: 10px; margin-top: 18px; border-radius: 999px; overflow: hidden; background: #1c1c1f; gap: 2px; }\n.hb-vh2-seg { height: 100%; background: var(--c); transition: flex-grow .45s cubic-bezier(.2, .8, .2, 1); min-width: 0; }\n.hb-vh2-seg:first-child { border-radius: 999px 0 0 999px; }\n.hb-vh2-seg:last-child { border-radius: 0 999px 999px 0; }\n.hb-vh2-lines { display: grid; gap: 0; margin: 16px 0 0; padding: 0; list-style: none; }\n.hb-vh2-lines li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px dashed rgba(255, 255, 255, .08); color: #a1a1a1; font-size: 13px; }\n.hb-vh2-lines li span:first-child { display: flex; align-items: center; gap: 8px; }\n.hb-vh2-lines li span:last-child { color: #ededed; font-family: var(--font-mono), ui-monospace, monospace; font-size: 12.5px; font-variant-numeric: tabular-nums; }\n.hb-vh2-lines li[data-free=\"true\"] span:last-child { color: #6f6f6f; }\n.hb-vh2-fit {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n  margin-top: 16px;\n  padding: 12px 14px;\n  border-radius: 14px;\n  border: 1px solid color-mix(in srgb, var(--hb-vh2-accent) 35%, transparent);\n  background: color-mix(in srgb, var(--hb-vh2-accent) 9%, transparent);\n  font-size: 13px;\n  line-height: 1.45;\n  color: #cfcfcf;\n}\n.hb-vh2-fit svg { flex: none; width: 18px; height: 18px; color: var(--hb-vh2-accent); }\n.hb-vh2-fit b { color: #fff; font-weight: 600; }\n.hb-vh2-fit-text { animation: hb-vh2-swap .45s cubic-bezier(.2, .9, .3, 1); }\n@keyframes hb-vh2-swap { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }\n.hb-vh2-plans { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 6px; margin-top: 12px; }\n.hb-vh2-plan {\n  padding: 9px 10px;\n  border-radius: 10px;\n  border: 1px solid rgba(255, 255, 255, .07);\n  font-size: 12px;\n  color: #8f8f8f;\n  text-align: center;\n  transition: border-color .3s ease, color .3s ease, background-color .3s ease;\n}\n.hb-vh2-plan b { display: block; color: #cfcfcf; font-size: 13px; font-weight: 600; }\n.hb-vh2-plan[data-fit=\"true\"] { border-color: var(--hb-vh2-accent); background: color-mix(in srgb, var(--hb-vh2-accent) 12%, transparent); color: #cfcfcf; }\n.hb-vh2-plan[data-fit=\"true\"] b { color: #fff; }\n.hb-vh2-plan[data-over=\"true\"] { opacity: .45; }\n.hb-vh2-cta {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  height: 44px;\n  margin-top: auto;\n  padding-top: 0;\n  border-radius: 12px;\n  background: #ededed;\n  color: #0a0a0a;\n  font-size: 14px;\n  font-weight: 600;\n  text-decoration: none;\n  transition: background-color .2s ease, transform .15s ease;\n}\n.hb-vh2-ctawrap { display: flex; flex-direction: column; margin-top: 16px; flex: 1; justify-content: flex-end; }\n.hb-vh2-cta:hover { background: #fff; }\n.hb-vh2-cta:active { transform: scale(.98); }\n.hb-vh2-cta:focus-visible { outline: 2px solid var(--hb-vh2-accent); outline-offset: 2px; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-vh2 *, .hb-vh2 *::before, .hb-vh2 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction fitPlan(plans: PricingUsagePlan[], values: Record<string, number>) {\n  const sorted = [...plans].sort((a, b) => a.price - b.price);\n  return sorted.find((p) => Object.entries(values).every(([k, v]) => (p.limits[k] ?? Infinity) >= v)) ?? null;\n}\n\nexport function PricingUsageCalculator({\n  eyebrow = \"Pricing calculator\",\n  title = \"Estimate your bill before you write a line\",\n  subtitle = \"Drag each meter to match your traffic. Every account gets the free allowance, and you only pay for what goes past it.\",\n  meters = defaultMeters,\n  baseFee = 20,\n  plans = defaultPlans,\n  currency = \"USD\",\n  locale = \"en-US\",\n  defaultValues,\n  onChange,\n  cta = { label: \"Start with this setup\", href: \"#\" },\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: PricingUsageCalculatorProps) {\n  const [values, setValues] = React.useState<Record<string, number>>(() => {\n    const init: Record<string, number> = {};\n    for (const m of meters) init[m.id] = defaultValues?.[m.id] ?? m.defaultValue;\n    return init;\n  });\n\n  const money = React.useMemo(\n    () => new Intl.NumberFormat(locale, { style: \"currency\", currency, minimumFractionDigits: 2, maximumFractionDigits: 2 }),\n    [locale, currency],\n  );\n  const rateFmt = React.useMemo(\n    () => new Intl.NumberFormat(locale, { style: \"currency\", currency, minimumFractionDigits: 2, maximumFractionDigits: 4 }),\n    [locale, currency],\n  );\n  const num = React.useMemo(() => new Intl.NumberFormat(locale, { maximumFractionDigits: 2 }), [locale]);\n\n  const costs = meters.map((m) => Math.max(0, (values[m.id] ?? 0) - m.included) * m.rate);\n  const usageTotal = costs.reduce((a, b) => a + b, 0);\n  const total = baseFee + usageTotal;\n  const plan = fitPlan(plans, values);\n  const saving = plan ? total - plan.price : 0;\n\n  const update = (id: string, v: number) => {\n    const next = { ...values, [id]: v };\n    setValues(next);\n    const t = baseFee + meters.reduce((s, m) => s + Math.max(0, (next[m.id] ?? 0) - m.included) * m.rate, 0);\n    onChange?.(next, t);\n  };\n\n  return (\n    <section className={`hb-vh2 ${className}`} style={{ \"--hb-vh2-accent\": accent, ...style } as React.CSSProperties} {...rest}>\n      <style href=\"hb-pricing-usage-calculator\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vh2-inner\">\n        {eyebrow ? <p className=\"hb-vh2-eyebrow\"><b>$</b> {eyebrow}</p> : null}\n        <h2 className=\"hb-vh2-title\">{title}</h2>\n        {subtitle ? <p className=\"hb-vh2-sub\">{subtitle}</p> : null}\n        <div className=\"hb-vh2-body\">\n          <div className=\"hb-vh2-panel hb-vh2-meters\">\n            {meters.map((m) => {\n              const v = values[m.id] ?? 0;\n              const pct = ((v - m.min) / (m.max - m.min)) * 100;\n              const freePct = ((Math.min(m.included, m.max) - m.min) / (m.max - m.min)) * 100;\n              return (\n                <div key={m.id} className=\"hb-vh2-meter\" style={{ \"--c\": m.color } as React.CSSProperties}>\n                  <div className=\"hb-vh2-mhead\">\n                    <label className=\"hb-vh2-mlabel\" htmlFor={`hb-vh2-${m.id}`}>\n                      <span className=\"hb-vh2-dot\" aria-hidden=\"true\" />\n                      {m.label}\n                    </label>\n                    <span className=\"hb-vh2-mval\">\n                      {num.format(v)} <small>{m.unit}</small>\n                    </span>\n                  </div>\n                  <div className=\"hb-vh2-range\">\n                    <div className=\"hb-vh2-rail\" aria-hidden=\"true\">\n                      <div className=\"hb-vh2-fill\" style={{ width: `${pct.toFixed(2)}%` }} />\n                      <div className=\"hb-vh2-free\" style={{ width: `${freePct.toFixed(2)}%` }} />\n                    </div>\n                    <input\n                      id={`hb-vh2-${m.id}`}\n                      className=\"hb-vh2-input\"\n                      type=\"range\"\n                      min={m.min}\n                      max={m.max}\n                      step={m.step}\n                      value={v}\n                      aria-valuetext={`${num.format(v)} ${m.unit}`}\n                      onChange={(e) => update(m.id, Number(e.target.value))}\n                    />\n                  </div>\n                  <div className=\"hb-vh2-mfoot\">\n                    <span>{num.format(m.included)} {m.unit} free</span>\n                    <span>{rateFmt.format(m.rate)} / extra {m.unit}</span>\n                  </div>\n                </div>\n              );\n            })}\n          </div>\n          <div className=\"hb-vh2-panel hb-vh2-receipt\">\n            <span className=\"hb-vh2-total-label\">Pay as you go, estimated</span>\n            <div className=\"hb-vh2-total\" aria-live=\"polite\">\n              <strong>{money.format(total)}</strong>\n              <span>/ month</span>\n            </div>\n            <div className=\"hb-vh2-stack\" aria-hidden=\"true\">\n              <div className=\"hb-vh2-seg\" style={{ flexGrow: baseFee, \"--c\": \"#5a5a60\" } as React.CSSProperties} />\n              {meters.map((m, i) => (\n                <div key={m.id} className=\"hb-vh2-seg\" style={{ flexGrow: costs[i], \"--c\": m.color } as React.CSSProperties} />\n              ))}\n            </div>\n            <ul className=\"hb-vh2-lines\">\n              <li>\n                <span>Platform fee</span>\n                <span>{money.format(baseFee)}</span>\n              </li>\n              {meters.map((m, i) => (\n                <li key={m.id} data-free={costs[i] === 0 ? \"true\" : undefined} style={{ \"--c\": m.color } as React.CSSProperties}>\n                  <span><span className=\"hb-vh2-dot\" aria-hidden=\"true\" />{m.label}</span>\n                  <span>{costs[i] === 0 ? \"Included\" : money.format(costs[i])}</span>\n                </li>\n              ))}\n            </ul>\n            <div className=\"hb-vh2-fit\">\n              <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\">\n                <path d=\"M10 2l2.2 4.6 5 .7-3.6 3.5.9 5L10 13.4 5.5 15.8l.9-5L2.8 7.3l5-.7z\" fill=\"currentColor\" />\n              </svg>\n              <span key={plan ? `${plan.name}-${saving > 0}` : \"none\"} className=\"hb-vh2-fit-text\">\n                {plan && saving > 0 ? (\n                  <>Best fit: <b>{plan.name}</b> at {money.format(plan.price)} flat. You would save <b>{money.format(saving)}</b> a month.</>\n                ) : plan ? (\n                  <>Pay as you go is cheapest here. <b>{plan.name}</b> covers this usage if you want a fixed bill.</>\n                ) : (\n                  <>This is past every plan limit. <b>Talk to us</b> about committed-use discounts.</>\n                )}\n              </span>\n            </div>\n            <div className=\"hb-vh2-plans\" style={{ \"--n\": plans.length } as React.CSSProperties}>\n              {plans.map((p) => (\n                <div\n                  key={p.name}\n                  className=\"hb-vh2-plan\"\n                  data-fit={plan?.name === p.name ? \"true\" : undefined}\n                  data-over={!Object.entries(values).every(([k, v]) => (p.limits[k] ?? Infinity) >= v) ? \"true\" : undefined}\n                >\n                  <b>{p.name}</b>\n                  {money.format(p.price)}\n                </div>\n              ))}\n            </div>\n            <div className=\"hb-vh2-ctawrap\">\n              <a className=\"hb-vh2-cta\" href={cta.href}>{cta.label}</a>\n            </div>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}