{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "a-la-carte-plan-builder",
  "title": "À la Carte Plan Builder",
  "description": "A build-your-own plan: pick modules, set seats and watch the total update, with bundle discounts that unlock as you add more, modules that bring their dependencies along, a yearly switch and a live summary.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/a-la-carte-plan-builder/a-la-carte-plan-builder.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 PlanBuilderTheme = \"dark\" | \"light\";\n\nexport interface PlanModule {\n  id: string;\n  name: string;\n  description: string;\n  /** Monthly price. */\n  price: number;\n  /** Charged per seat instead of per workspace. */\n  perSeat?: boolean;\n  /** Always in the plan and can't be removed. */\n  required?: boolean;\n  /** Ids of modules this one needs; they're added with it. */\n  requires?: string[];\n}\n\nexport interface BundleTier {\n  /** Optional modules needed to reach this tier. */\n  count: number;\n  /** Discount on the whole plan (0–1). */\n  discount: number;\n}\n\nexport interface ALaCartePlanBuilderProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"title\" | \"onChange\"\n> {\n  theme?: PlanBuilderTheme;\n  title?: string;\n  subtitle?: string;\n  modules?: PlanModule[];\n  tiers?: BundleTier[];\n  /** Discount for paying yearly (0–1), on top of the bundle discount. */\n  yearlyDiscount?: number;\n  defaultSelected?: string[];\n  defaultSeats?: number;\n  maxSeats?: number;\n  currency?: string;\n  onCheckout?: (plan: {\n    modules: string[];\n    seats: number;\n    yearly: boolean;\n    monthly: number;\n  }) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#0E0E0E\",\n    panel: \"#141416\",\n    border: \"rgba(255,255,255,0.09)\",\n    text: \"#F4F5F7\",\n    sub: \"rgba(255,255,255,0.55)\",\n    faint: \"rgba(255,255,255,0.36)\",\n    chip: \"rgba(255,255,255,0.06)\",\n    on: \"rgba(143,184,255,0.1)\",\n    onBorder: \"#8FB8FF\",\n    accent: \"#8FB8FF\",\n    accentText: \"#0B1730\",\n    good: \"#87FFE3\",\n    btn: \"#F4F5F7\",\n    btnText: \"#0E0E0E\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    panel: \"#F6F6F4\",\n    border: \"rgba(0,0,0,0.09)\",\n    text: \"#111317\",\n    sub: \"rgba(17,19,23,0.58)\",\n    faint: \"rgba(17,19,23,0.4)\",\n    chip: \"rgba(17,19,23,0.05)\",\n    on: \"rgba(59,111,216,0.07)\",\n    onBorder: \"#3B6FD8\",\n    accent: \"#3B6FD8\",\n    accentText: \"#FFFFFF\",\n    good: \"#0E9F80\",\n    btn: \"#111317\",\n    btnText: \"#FFFFFF\",\n  },\n};\n\nconst DEFAULT_MODULES: PlanModule[] = [\n  {\n    id: \"core\",\n    name: \"Core workspace\",\n    description: \"Projects, tasks and docs\",\n    price: 8,\n    perSeat: true,\n    required: true,\n  },\n  {\n    id: \"automations\",\n    name: \"Automations\",\n    description: \"Rules that run on any change\",\n    price: 24,\n  },\n  {\n    id: \"analytics\",\n    name: \"Analytics\",\n    description: \"Dashboards and scheduled reports\",\n    price: 36,\n  },\n  {\n    id: \"forms\",\n    name: \"Client forms\",\n    description: \"Branded intake and approvals\",\n    price: 18,\n  },\n  {\n    id: \"guests\",\n    name: \"Guest access\",\n    description: \"Unlimited view-only guests\",\n    price: 15,\n  },\n  {\n    id: \"sso\",\n    name: \"SSO & SCIM\",\n    description: \"Okta, Entra ID and provisioning\",\n    price: 4,\n    perSeat: true,\n    requires: [\"audit\"],\n  },\n  {\n    id: \"audit\",\n    name: \"Audit log\",\n    description: \"Every change, kept for two years\",\n    price: 29,\n  },\n];\nconst DEFAULT_TIERS: BundleTier[] = [\n  { count: 2, discount: 0.1 },\n  { count: 4, discount: 0.2 },\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\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\nexport function ALaCartePlanBuilder({\n  theme = \"dark\",\n  title = \"Build your plan\",\n  subtitle = \"Pay only for what your team uses. Add more and the whole plan gets cheaper.\",\n  modules = DEFAULT_MODULES,\n  tiers = DEFAULT_TIERS,\n  yearlyDiscount = 0.15,\n  defaultSelected = [\"automations\", \"analytics\"],\n  defaultSeats = 8,\n  maxSeats = 250,\n  currency = \"$\",\n  onCheckout,\n  className,\n  style,\n  ...props\n}: ALaCartePlanBuilderProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const [selected, setSelected] = React.useState<Set<string>>(\n    () =>\n      new Set([\n        ...modules.filter((m) => m.required).map((m) => m.id),\n        ...defaultSelected,\n      ]),\n  );\n  const [seats, setSeats] = React.useState(defaultSeats);\n  const [yearly, setYearly] = React.useState(false);\n\n  const byId = new Map(modules.map((m) => [m.id, m]));\n  const dependents = (id: string) =>\n    modules.filter((m) => selected.has(m.id) && m.requires?.includes(id));\n  const toggle = (m: PlanModule) => {\n    if (m.required) return;\n    setSelected((prev) => {\n      const next = new Set(prev);\n      if (next.has(m.id)) {\n        next.delete(m.id);\n        // Anything that depended on this module goes with it.\n        modules.forEach((d) => d.requires?.includes(m.id) && next.delete(d.id));\n      } else {\n        next.add(m.id);\n        m.requires?.forEach((r) => next.add(r));\n      }\n      return next;\n    });\n  };\n\n  const chosen = modules.filter((m) => selected.has(m.id));\n  const optional = chosen.filter((m) => !m.required).length;\n  const sorted = [...tiers].sort((a, b) => a.count - b.count);\n  const tier = [...sorted].reverse().find((t) => optional >= t.count);\n  const nextTier = sorted.find((t) => optional < t.count);\n  const lineCost = (m: PlanModule) => m.price * (m.perSeat ? seats : 1);\n  const subtotal = chosen.reduce((s, m) => s + lineCost(m), 0);\n  const bundleOff = subtotal * (tier?.discount ?? 0);\n  const yearlyOff = yearly ? (subtotal - bundleOff) * yearlyDiscount : 0;\n  const total = subtotal - bundleOff - yearlyOff;\n  const shown = useEased(total, reduce);\n  const money = (v: number) =>\n    `${currency}${Math.round(v).toLocaleString(\"en-US\")}`;\n  const topCount = sorted[sorted.length - 1]?.count ?? 1;\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 grid-cols-[minmax(0,1fr)] @[720px]:grid-cols-[minmax(0,1.35fr)_minmax(0,1fr)]\">\n        <div className=\"p-5 sm:p-6\">\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          <ul className=\"m-0 mt-4 flex list-none flex-col gap-1.5 p-0\">\n            {modules.map((m) => {\n              const on = selected.has(m.id);\n              const needs = dependents(m.id);\n              return (\n                <li key={m.id}>\n                  <button\n                    type=\"button\"\n                    role=\"checkbox\"\n                    aria-checked={on}\n                    aria-disabled={m.required}\n                    onClick={() => toggle(m)}\n                    className={cn(\n                      \"flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-left transition-colors\",\n                      m.required ? \"cursor-default\" : \"cursor-pointer\",\n                    )}\n                    style={{\n                      background: on ? pal.on : \"transparent\",\n                      boxShadow: `inset 0 0 0 1px ${on ? pal.onBorder : pal.border}`,\n                    }}\n                  >\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"grid size-[18px] shrink-0 place-items-center rounded-[5px] transition-colors\"\n                      style={{\n                        background: on ? pal.accent : \"transparent\",\n                        boxShadow: on\n                          ? \"none\"\n                          : `inset 0 0 0 1.5px ${pal.faint}`,\n                        color: pal.accentText,\n                      }}\n                    >\n                      {on && (\n                        <svg\n                          width=\"11\"\n                          height=\"11\"\n                          viewBox=\"0 0 12 12\"\n                          fill=\"none\"\n                          stroke=\"currentColor\"\n                          strokeWidth=\"2.2\"\n                          strokeLinecap=\"round\"\n                          strokeLinejoin=\"round\"\n                        >\n                          <path d=\"M2.4 6.3 4.9 8.7 9.6 3.4\" />\n                        </svg>\n                      )}\n                    </span>\n                    <span className=\"min-w-0 flex-1\">\n                      <span className=\"block truncate text-[13.5px] font-medium\">\n                        {m.name}\n                        {m.required && (\n                          <span\n                            className=\"ml-1.5 text-[11px] font-normal\"\n                            style={{ color: pal.faint }}\n                          >\n                            Included\n                          </span>\n                        )}\n                      </span>\n                      <span\n                        className=\"block truncate text-[12px]\"\n                        style={{ color: pal.sub }}\n                      >\n                        {needs.length\n                          ? `Needed by ${needs.map((d) => d.name).join(\", \")}`\n                          : m.requires?.length\n                            ? `${m.description}. Adds ${m.requires.map((r) => byId.get(r)?.name).join(\", \")}`\n                            : m.description}\n                      </span>\n                    </span>\n                    <span className=\"shrink-0 text-right text-[13px] font-medium tabular-nums\">\n                      {currency}\n                      {m.price}\n                      <span\n                        className=\"block text-[10.5px] font-normal\"\n                        style={{ color: pal.faint }}\n                      >\n                        {m.perSeat ? \"per seat\" : \"per month\"}\n                      </span>\n                    </span>\n                  </button>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n\n        <div\n          className=\"flex flex-col border-t p-5 sm:p-6 @[720px]:border-t-0 @[720px]:border-l\"\n          style={{ background: pal.panel, borderColor: pal.border }}\n        >\n          <div className=\"flex items-center justify-between gap-3\">\n            <span className=\"text-[13px] font-medium\">Seats</span>\n            <span\n              className=\"flex items-center rounded-lg\"\n              style={{ boxShadow: `inset 0 0 0 1px ${pal.border}` }}\n              role=\"group\"\n              aria-label=\"Seats\"\n            >\n              <button\n                type=\"button\"\n                aria-label=\"Fewer seats\"\n                disabled={seats <= 1}\n                onClick={() => setSeats((s) => Math.max(1, s - 1))}\n                className=\"size-8 cursor-pointer text-[15px] disabled:cursor-default disabled:opacity-30\"\n              >\n                −\n              </button>\n              <output className=\"w-9 text-center text-[13.5px] font-semibold tabular-nums\">\n                {seats}\n              </output>\n              <button\n                type=\"button\"\n                aria-label=\"More seats\"\n                disabled={seats >= maxSeats}\n                onClick={() => setSeats((s) => Math.min(maxSeats, s + 1))}\n                className=\"size-8 cursor-pointer text-[15px] disabled:cursor-default disabled:opacity-30\"\n              >\n                +\n              </button>\n            </span>\n          </div>\n\n          <div className=\"mt-4\">\n            <div className=\"flex justify-between text-[11.5px] font-medium\">\n              <span style={{ color: tier ? pal.good : pal.sub }}>\n                {tier\n                  ? `${Math.round(tier.discount * 100)}% bundle discount`\n                  : \"No bundle discount yet\"}\n              </span>\n              {nextTier && (\n                <span style={{ color: pal.sub }}>\n                  {nextTier.count - optional} more for{\" \"}\n                  {Math.round(nextTier.discount * 100)}%\n                </span>\n              )}\n            </div>\n            <div\n              className=\"relative mt-2 h-1.5 rounded-full\"\n              style={{ background: pal.chip }}\n            >\n              <div\n                className=\"h-full rounded-full motion-safe:transition-[width] motion-safe:duration-300\"\n                style={{\n                  width: `${Math.min(1, optional / topCount) * 100}%`,\n                  background: pal.good,\n                }}\n              />\n              {sorted.map((t) => (\n                <span\n                  key={t.count}\n                  aria-hidden=\"true\"\n                  className=\"absolute top-1/2 size-2.5 -translate-1/2 rounded-full\"\n                  style={{\n                    left: `${Math.min(100, (t.count / topCount) * 100)}%`,\n                    background: optional >= t.count ? pal.good : pal.panel,\n                    boxShadow: `0 0 0 1.5px ${optional >= t.count ? pal.good : pal.faint}`,\n                  }}\n                />\n              ))}\n            </div>\n          </div>\n\n          <dl className=\"m-0 mt-5 flex flex-col gap-1.5 text-[12.5px] tabular-nums\">\n            {chosen.map((m) => (\n              <div key={m.id} className=\"flex justify-between gap-3\">\n                <dt className=\"truncate\" style={{ color: pal.sub }}>\n                  {m.name}\n                  {m.perSeat ? ` × ${seats}` : \"\"}\n                </dt>\n                <dd className=\"m-0 shrink-0\">{money(lineCost(m))}</dd>\n              </div>\n            ))}\n            {bundleOff > 0 && (\n              <div\n                className=\"flex justify-between gap-3\"\n                style={{ color: pal.good }}\n              >\n                <dt>Bundle −{Math.round((tier?.discount ?? 0) * 100)}%</dt>\n                <dd className=\"m-0\">−{money(bundleOff)}</dd>\n              </div>\n            )}\n            {yearlyOff > 0 && (\n              <div\n                className=\"flex justify-between gap-3\"\n                style={{ color: pal.good }}\n              >\n                <dt>Yearly −{Math.round(yearlyDiscount * 100)}%</dt>\n                <dd className=\"m-0\">−{money(yearlyOff)}</dd>\n              </div>\n            )}\n          </dl>\n\n          <div className=\"mt-auto pt-4\">\n            <div\n              className=\"flex items-end justify-between gap-3 border-t pt-3\"\n              style={{ borderColor: pal.border }}\n            >\n              <p className=\"m-0 flex items-baseline gap-1\" aria-live=\"polite\">\n                <span className=\"text-[34px] leading-none font-semibold tracking-[-0.03em] tabular-nums\">\n                  {money(shown)}\n                </span>\n                <span className=\"text-[12.5px]\" style={{ color: pal.sub }}>\n                  / mo\n                </span>\n              </p>\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-1.5 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.good : pal.chip }}\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                Pay yearly\n              </button>\n            </div>\n            <button\n              type=\"button\"\n              onClick={() =>\n                onCheckout?.({\n                  modules: chosen.map((m) => m.id),\n                  seats,\n                  yearly,\n                  monthly: total,\n                })\n              }\n              className=\"mt-3 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 }}\n            >\n              Continue with {chosen.length} modules\n            </button>\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}