{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "usage-price-calculator",
  "title": "Usage Price Calculator",
  "description": "A pay-as-you-go pricing calculator: sliders for requests, seats and storage, a live monthly estimate with a line-by-line breakdown, and bars comparing every plan so the cheapest one for that usage stands out.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/usage-price-calculator/usage-price-calculator.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type CalculatorTheme = \"dark\" | \"light\";\n\nexport interface UsageMetric {\n  key: string;\n  label: string;\n  /** Unit shown after the value, e.g. \"requests\". */\n  unit: string;\n  min: number;\n  max: number;\n  defaultValue: number;\n  /** Spread the slider logarithmically, for ranges like 10K to 50M. */\n  log?: boolean;\n}\n\nexport interface UsagePlan {\n  name: string;\n  /** Monthly base fee. */\n  base: number;\n  /** Amount of each metric included in the base fee. */\n  included: Record<string, number>;\n  /** Price per extra unit of each metric, after the included amount. */\n  overage: Record<string, number>;\n  /** How many units one overage price covers, e.g. 1000 for \"per 1,000 requests\". Defaults to 1. */\n  per?: Record<string, number>;\n}\n\nexport interface UsagePriceCalculatorProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"title\" | \"onSelect\"\n> {\n  theme?: CalculatorTheme;\n  title?: string;\n  subtitle?: string;\n  metrics?: UsageMetric[];\n  plans?: UsagePlan[];\n  /** Discount on base fees when billed yearly (0–1). */\n  yearlyDiscount?: number;\n  currency?: string;\n  ctaLabel?: string;\n  onSelect?: (\n    plan: UsagePlan,\n    monthly: number,\n    usage: Record<string, number>,\n  ) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#0E0E0E\",\n    panel: \"#141416\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F4F5F7\",\n    sub: \"rgba(255,255,255,0.55)\",\n    faint: \"rgba(255,255,255,0.36)\",\n    track: \"rgba(255,255,255,0.1)\",\n    chip: \"rgba(255,255,255,0.06)\",\n    accent: \"#87FFE3\",\n    accentText: \"#06241D\",\n    btn: \"#F4F5F7\",\n    btnText: \"#0E0E0E\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    panel: \"#F6F6F4\",\n    border: \"rgba(0,0,0,0.08)\",\n    text: \"#111317\",\n    sub: \"rgba(17,19,23,0.58)\",\n    faint: \"rgba(17,19,23,0.4)\",\n    track: \"rgba(17,19,23,0.1)\",\n    chip: \"rgba(17,19,23,0.05)\",\n    accent: \"#0E9F80\",\n    accentText: \"#FFFFFF\",\n    btn: \"#111317\",\n    btnText: \"#FFFFFF\",\n  },\n};\n\nconst DEFAULT_METRICS: UsageMetric[] = [\n  {\n    key: \"requests\",\n    label: \"API requests\",\n    unit: \"per month\",\n    min: 10000,\n    max: 50000000,\n    defaultValue: 2500000,\n    log: true,\n  },\n  {\n    key: \"seats\",\n    label: \"Team seats\",\n    unit: \"people\",\n    min: 1,\n    max: 200,\n    defaultValue: 12,\n  },\n  {\n    key: \"storage\",\n    label: \"Storage\",\n    unit: \"GB\",\n    min: 1,\n    max: 5000,\n    defaultValue: 120,\n    log: true,\n  },\n];\n\nconst DEFAULT_PLANS: UsagePlan[] = [\n  {\n    name: \"Starter\",\n    base: 0,\n    included: { requests: 100000, seats: 2, storage: 5 },\n    overage: { requests: 0.9, seats: 15, storage: 0.5 },\n    per: { requests: 1000 },\n  },\n  {\n    name: \"Pro\",\n    base: 79,\n    included: { requests: 1000000, seats: 5, storage: 100 },\n    overage: { requests: 0.45, seats: 12, storage: 0.25 },\n    per: { requests: 1000 },\n  },\n  {\n    name: \"Scale\",\n    base: 499,\n    included: { requests: 20000000, seats: 25, storage: 1000 },\n    overage: { requests: 0.18, seats: 9, storage: 0.1 },\n    per: { requests: 1000 },\n  },\n];\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** Eases a displayed number toward its target. */\nfunction useEased(target: number, reduce: boolean) {\n  const [value, setValue] = React.useState(target);\n  const current = React.useRef(target);\n  React.useEffect(() => {\n    let raf = 0;\n    const tick = () => {\n      const next = reduce\n        ? target\n        : current.current + (target - current.current) * 0.22;\n      const done = Math.abs(next - target) < 0.5;\n      current.current = done ? target : next;\n      setValue(current.current);\n      if (!done) raf = requestAnimationFrame(tick);\n    };\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n  }, [target, reduce]);\n  return value;\n}\n\nconst STEPS = 1000;\nconst toSlider = (m: UsageMetric, v: number) =>\n  m.log\n    ? (Math.log(v / m.min) / Math.log(m.max / m.min)) * STEPS\n    : ((v - m.min) / (m.max - m.min)) * STEPS;\nfunction fromSlider(m: UsageMetric, s: number) {\n  const raw = m.log\n    ? m.min * Math.pow(m.max / m.min, s / STEPS)\n    : m.min + ((m.max - m.min) * s) / STEPS;\n  // Round to two significant figures so the numbers stay tidy while dragging.\n  if (raw < 100) return Math.round(raw);\n  const mag = Math.pow(10, Math.floor(Math.log10(raw)) - 1);\n  return Math.round(raw / mag) * mag;\n}\nconst short = (v: number) =>\n  v >= 1e6\n    ? `${+(v / 1e6).toFixed(1)}M`\n    : v >= 1e4\n      ? `${+(v / 1e3).toFixed(0)}K`\n      : v.toLocaleString(\"en-US\");\n\nfunction costOf(\n  plan: UsagePlan,\n  metrics: UsageMetric[],\n  usage: Record<string, number>,\n  baseFactor: number,\n) {\n  const lines = metrics.map((m) => {\n    const extra = Math.max(0, usage[m.key] - (plan.included[m.key] ?? 0));\n    const per = plan.per?.[m.key] ?? 1;\n    return {\n      key: m.key,\n      label: m.label,\n      extra,\n      cost: (extra / per) * (plan.overage[m.key] ?? 0),\n    };\n  });\n  const base = plan.base * baseFactor;\n  return { base, lines, total: base + lines.reduce((s, l) => s + l.cost, 0) };\n}\n\nexport function UsagePriceCalculator({\n  theme = \"dark\",\n  title = \"Estimate your bill\",\n  subtitle = \"Drag to match your usage. We'll find the cheapest plan.\",\n  metrics = DEFAULT_METRICS,\n  plans = DEFAULT_PLANS,\n  yearlyDiscount = 0.2,\n  currency = \"$\",\n  ctaLabel = \"Start with\",\n  onSelect,\n  className,\n  style,\n  ...props\n}: UsagePriceCalculatorProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const id = React.useId();\n  const [usage, setUsage] = React.useState<Record<string, number>>(() =>\n    Object.fromEntries(metrics.map((m) => [m.key, m.defaultValue])),\n  );\n  const [yearly, setYearly] = React.useState(false);\n  const [picked, setPicked] = React.useState<string | null>(null);\n\n  const factor = yearly ? 1 - yearlyDiscount : 1;\n  const costs = plans.map((p) => ({\n    plan: p,\n    ...costOf(p, metrics, usage, factor),\n  }));\n  const cheapest = costs.reduce(\n    (b, c) => (c.total < b.total ? c : b),\n    costs[0],\n  );\n  const active = costs.find((c) => c.plan.name === picked) ?? cheapest;\n  const money = (v: number) =>\n    `${currency}${Math.round(v).toLocaleString(\"en-US\")}`;\n  const shown = useEased(active.total, reduce);\n  const most = Math.max(...costs.map((c) => c.total), 1);\n  const saving =\n    active === cheapest\n      ? Math.max(...costs.map((c) => c.total)) - cheapest.total\n      : 0;\n\n  return (\n    <div\n      className={cn(\n        \"@container w-full overflow-hidden rounded-[20px]\",\n        className,\n      )}\n      style={{\n        background: pal.card,\n        border: `1px solid ${pal.border}`,\n        color: pal.text,\n        fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\",\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"grid @[680px]:grid-cols-[1.15fr_1fr]\">\n        <div className=\"p-5 sm:p-7\">\n          <div className=\"flex flex-wrap items-start justify-between gap-3\">\n            <div>\n              <p className=\"m-0 text-[17px] font-semibold tracking-[-0.01em]\">\n                {title}\n              </p>\n              <p className=\"m-0 mt-1 text-[13px]\" style={{ color: pal.sub }}>\n                {subtitle}\n              </p>\n            </div>\n          </div>\n          <div className=\"mt-6 flex flex-col gap-6\">\n            {metrics.map((m) => {\n              const pos = toSlider(m, usage[m.key]);\n              return (\n                <div key={m.key}>\n                  <div className=\"flex items-baseline justify-between gap-3\">\n                    <label\n                      htmlFor={`${id}-${m.key}`}\n                      className=\"text-[13px] font-medium\"\n                    >\n                      {m.label}\n                    </label>\n                    <span className=\"text-[13px] tabular-nums\">\n                      <b className=\"text-[15px] font-semibold\">\n                        {short(usage[m.key])}\n                      </b>{\" \"}\n                      <span style={{ color: pal.sub }}>{m.unit}</span>\n                    </span>\n                  </div>\n                  <input\n                    id={`${id}-${m.key}`}\n                    type=\"range\"\n                    min={0}\n                    max={STEPS}\n                    step={1}\n                    value={pos}\n                    aria-valuetext={`${usage[m.key].toLocaleString(\"en-US\")} ${m.unit}`}\n                    onChange={(e) =>\n                      setUsage((u) => ({\n                        ...u,\n                        [m.key]: fromSlider(m, Number(e.target.value)),\n                      }))\n                    }\n                    className=\"mt-2.5 block h-5 w-full cursor-pointer appearance-none rounded-full bg-transparent outline-none focus-visible:ring-2 [&::-moz-range-thumb]:size-5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-[var(--thumb)] [&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-[image:var(--fill)] [&::-webkit-slider-thumb]:-mt-[7px] [&::-webkit-slider-thumb]:size-5 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--thumb)] [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(0,0,0,.4)]\"\n                    style={\n                      {\n                        \"--thumb\": pal.text,\n                        \"--fill\": `linear-gradient(to right, ${pal.accent} ${(pos / STEPS) * 100}%, ${pal.track} ${(pos / STEPS) * 100}%)`,\n                      } as React.CSSProperties\n                    }\n                  />\n                  <div\n                    className=\"mt-1 flex justify-between text-[11px] tabular-nums\"\n                    style={{ color: pal.faint }}\n                  >\n                    <span>{short(m.min)}</span>\n                    <span>\n                      {active.plan.included[m.key] !== undefined\n                        ? `${short(active.plan.included[m.key])} included`\n                        : \"\"}\n                    </span>\n                    <span>{short(m.max)}</span>\n                  </div>\n                </div>\n              );\n            })}\n          </div>\n        </div>\n\n        <div\n          className=\"flex flex-col border-t p-5 sm:p-7 @[680px]:border-t-0 @[680px]:border-l\"\n          style={{ background: pal.panel, borderColor: pal.border }}\n        >\n          <div className=\"flex items-center justify-between gap-3\">\n            <span\n              className=\"text-[12px] font-medium\"\n              style={{ color: pal.sub }}\n            >\n              {active.plan.name} plan\n            </span>\n            <button\n              type=\"button\"\n              role=\"switch\"\n              aria-checked={yearly}\n              onClick={() => setYearly((y) => !y)}\n              className=\"flex cursor-pointer items-center gap-2 text-[12px] font-medium\"\n              style={{ color: pal.sub }}\n            >\n              <span\n                className=\"relative h-[18px] w-8 rounded-full transition-colors\"\n                style={{ background: yearly ? pal.accent : pal.track }}\n              >\n                <span\n                  className=\"absolute top-0.5 left-0.5 size-3.5 rounded-full bg-white shadow transition-transform\"\n                  style={{ transform: yearly ? \"translateX(14px)\" : \"none\" }}\n                />\n              </span>\n              Yearly, base −{Math.round(yearlyDiscount * 100)}%\n            </button>\n          </div>\n          <p\n            className=\"m-0 mt-3 flex items-baseline gap-1.5\"\n            aria-live=\"polite\"\n          >\n            <span className=\"text-[46px] leading-none font-semibold tracking-[-0.035em] tabular-nums\">\n              {money(shown)}\n            </span>\n            <span className=\"text-[13px]\" style={{ color: pal.sub }}>\n              / month\n            </span>\n          </p>\n          <p\n            className=\"m-0 mt-1.5 min-h-[18px] text-[12.5px] font-medium\"\n            style={{ color: saving > 1 ? pal.accent : pal.sub }}\n          >\n            {saving > 1\n              ? `Saves ${money(saving)} a month over the priciest option`\n              : active !== cheapest\n                ? `${money(active.total - cheapest.total)} more than ${cheapest.plan.name}`\n                : \"The same on every plan at this usage\"}\n          </p>\n\n          <dl\n            className=\"m-0 mt-4 flex flex-col gap-1.5 border-t pt-3 text-[12.5px] tabular-nums\"\n            style={{ borderColor: pal.border }}\n          >\n            <div className=\"flex justify-between\">\n              <dt style={{ color: pal.sub }}>Base fee</dt>\n              <dd className=\"m-0\">{money(active.base)}</dd>\n            </div>\n            {active.lines.map((l) => (\n              <div key={l.key} className=\"flex justify-between gap-3\">\n                <dt className=\"truncate\" style={{ color: pal.sub }}>\n                  {l.label}\n                  {l.extra > 0 ? ` (+${short(l.extra)})` : \"\"}\n                </dt>\n                <dd\n                  className=\"m-0 shrink-0\"\n                  style={{ color: l.cost ? undefined : pal.faint }}\n                >\n                  {l.cost ? money(l.cost) : \"Included\"}\n                </dd>\n              </div>\n            ))}\n          </dl>\n\n          <div\n            role=\"radiogroup\"\n            aria-label=\"Compare plans\"\n            className=\"mt-4 flex flex-col gap-1\"\n          >\n            {costs.map((c) => {\n              const on = c === active;\n              return (\n                <button\n                  key={c.plan.name}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={on}\n                  onClick={() => setPicked(c.plan.name)}\n                  className=\"group flex cursor-pointer items-center gap-2.5 rounded-lg px-2 py-1.5 text-left text-[12.5px] transition-colors\"\n                  style={{ background: on ? pal.chip : \"transparent\" }}\n                >\n                  <span className=\"w-14 shrink-0 font-medium\">\n                    {c.plan.name}\n                  </span>\n                  <span\n                    className=\"h-1.5 flex-1 overflow-hidden rounded-full\"\n                    style={{ background: pal.track }}\n                  >\n                    <span\n                      className=\"block h-full rounded-full motion-safe:transition-[width] motion-safe:duration-300\"\n                      style={{\n                        width: `${Math.max(3, (c.total / most) * 100)}%`,\n                        background: c === cheapest ? pal.accent : pal.sub,\n                      }}\n                    />\n                  </span>\n                  <span\n                    className=\"w-14 shrink-0 text-right tabular-nums\"\n                    style={{ color: c === cheapest ? pal.accent : pal.sub }}\n                  >\n                    {money(c.total)}\n                  </span>\n                </button>\n              );\n            })}\n          </div>\n\n          <button\n            type=\"button\"\n            onClick={() => onSelect?.(active.plan, active.total, usage)}\n            className=\"mt-auto w-full cursor-pointer rounded-xl py-2.5 text-[13.5px] font-semibold transition-opacity hover:opacity-90\"\n            style={{ background: pal.btn, color: pal.btnText, marginTop: 16 }}\n          >\n            {ctaLabel} {active.plan.name}\n          </button>\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}