@eifi1/ui-kit 0.40.1 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +19 -6
  2. package/dist/admin/admin-area-labels.d.ts +55 -0
  3. package/dist/admin/admin-area-labels.js +33 -0
  4. package/dist/admin/admin-area-labels.js.map +1 -0
  5. package/dist/admin/admin-forbidden.d.ts +35 -0
  6. package/dist/admin/admin-forbidden.js +36 -0
  7. package/dist/admin/admin-forbidden.js.map +1 -0
  8. package/dist/admin/admin-overview.d.ts +93 -0
  9. package/dist/admin/admin-overview.js +69 -0
  10. package/dist/admin/admin-overview.js.map +1 -0
  11. package/dist/admin/admin-sections.d.ts +63 -0
  12. package/dist/admin/admin-sections.js +64 -0
  13. package/dist/admin/admin-sections.js.map +1 -0
  14. package/dist/admin/admin-tool-links.d.ts +48 -0
  15. package/dist/admin/admin-tool-links.js +31 -0
  16. package/dist/admin/admin-tool-links.js.map +1 -0
  17. package/dist/billing/billing-banner.d.ts +25 -2
  18. package/dist/billing/billing-banner.js +5 -2
  19. package/dist/billing/billing-banner.js.map +1 -1
  20. package/dist/billing/billing-labels.d.ts +32 -0
  21. package/dist/billing/billing-labels.js +9 -0
  22. package/dist/billing/billing-labels.js.map +1 -1
  23. package/dist/billing/billing-overview.d.ts +33 -0
  24. package/dist/billing/billing-overview.js +6 -0
  25. package/dist/billing/billing-overview.js.map +1 -1
  26. package/dist/billing/billing-standing.d.ts +8 -0
  27. package/dist/billing/billing-standing.js.map +1 -1
  28. package/dist/billing/cancel-subscription.d.ts +46 -0
  29. package/dist/billing/cancel-subscription.js +57 -0
  30. package/dist/billing/cancel-subscription.js.map +1 -0
  31. package/dist/billing/plan-card.d.ts +45 -1
  32. package/dist/billing/plan-card.js +53 -2
  33. package/dist/billing/plan-card.js.map +1 -1
  34. package/dist/billing/plan-switch.d.ts +10 -1
  35. package/dist/billing/plan-switch.js +22 -13
  36. package/dist/billing/plan-switch.js.map +1 -1
  37. package/dist/billing/subscription-actions.d.ts +37 -4
  38. package/dist/billing/subscription-actions.js +10 -3
  39. package/dist/billing/subscription-actions.js.map +1 -1
  40. package/dist/components/account-chips.d.ts +42 -1
  41. package/dist/components/account-chips.js +33 -0
  42. package/dist/components/account-chips.js.map +1 -1
  43. package/dist/components/empty-state.d.ts +2 -1
  44. package/dist/components/empty-state.js.map +1 -1
  45. package/dist/components/nav-pills.d.ts +2 -2
  46. package/dist/components/nav-pills.js.map +1 -1
  47. package/dist/components/tabs.d.ts +4 -32
  48. package/dist/components/tabs.js +30 -66
  49. package/dist/components/tabs.js.map +1 -1
  50. package/dist/components/translation-review-parts.d.ts +2 -2
  51. package/dist/components/translation-review-parts.js.map +1 -1
  52. package/dist/eslint/index.js +1 -1
  53. package/dist/feedback/feedback-menu-labels.js +0 -2
  54. package/dist/feedback/feedback-menu-labels.js.map +1 -1
  55. package/dist/feedback/feedback-menu.d.ts +0 -6
  56. package/dist/feedback/feedback-menu.js.map +1 -1
  57. package/dist/i18n/defaults.js +5 -1
  58. package/dist/i18n/defaults.js.map +1 -1
  59. package/dist/i18n/german.js +79 -2
  60. package/dist/i18n/german.js.map +1 -1
  61. package/dist/i18n/kit-labels.d.ts +9 -0
  62. package/dist/i18n/kit-labels.js.map +1 -1
  63. package/dist/i18n/locales/en.js +93 -3
  64. package/dist/i18n/locales/en.js.map +3 -3
  65. package/dist/i18n/locales/es.js +76 -2
  66. package/dist/i18n/locales/es.js.map +1 -1
  67. package/dist/i18n/locales/fr.js +75 -2
  68. package/dist/i18n/locales/fr.js.map +1 -1
  69. package/dist/i18n/locales/hu.js +76 -2
  70. package/dist/i18n/locales/hu.js.map +1 -1
  71. package/dist/i18n/locales/it.js +76 -2
  72. package/dist/i18n/locales/it.js.map +1 -1
  73. package/dist/i18n/locales/zh.js +75 -2
  74. package/dist/i18n/locales/zh.js.map +1 -1
  75. package/dist/i18n/review.js +20 -1
  76. package/dist/i18n/review.js.map +1 -1
  77. package/dist/index.d.ts +18 -2
  78. package/dist/index.js +23 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/settings/settings-layout.d.ts +7 -1
  81. package/dist/settings/settings-layout.js +35 -27
  82. package/dist/settings/settings-layout.js.map +1 -1
  83. package/dist/shell/account-menu-language.d.ts +46 -0
  84. package/dist/shell/account-menu-language.js +64 -0
  85. package/dist/shell/account-menu-language.js.map +1 -0
  86. package/dist/shell/admin-menu.d.ts +46 -0
  87. package/dist/shell/admin-menu.js +60 -0
  88. package/dist/shell/admin-menu.js.map +1 -0
  89. package/dist/shell/app-shell.d.ts +10 -0
  90. package/dist/shell/app-shell.js +22 -4
  91. package/dist/shell/app-shell.js.map +1 -1
  92. package/dist/shell/dev-switchers.d.ts +53 -0
  93. package/dist/shell/dev-switchers.js +102 -0
  94. package/dist/shell/dev-switchers.js.map +1 -0
  95. package/dist/shell/sync-status-indicator.d.ts +86 -0
  96. package/dist/shell/sync-status-indicator.js +170 -0
  97. package/dist/shell/sync-status-indicator.js.map +1 -0
  98. package/dist/shell/top-bar-actions.d.ts +49 -0
  99. package/dist/shell/top-bar-actions.js +31 -0
  100. package/dist/shell/top-bar-actions.js.map +1 -0
  101. package/dist/shell/top-bar-parts-labels.d.ts +84 -0
  102. package/dist/shell/top-bar-parts-labels.js +48 -0
  103. package/dist/shell/top-bar-parts-labels.js.map +1 -0
  104. package/dist/shell/topbar-action-menu.d.ts +13 -1
  105. package/dist/shell/topbar-action-menu.js +5 -2
  106. package/dist/shell/topbar-action-menu.js.map +1 -1
  107. package/dist/shell/topbar-controls.d.ts +16 -3
  108. package/dist/shell/topbar-controls.js +5 -1
  109. package/dist/shell/topbar-controls.js.map +1 -1
  110. package/dist/shell/tour-menu.d.ts +58 -0
  111. package/dist/shell/tour-menu.js +73 -0
  112. package/dist/shell/tour-menu.js.map +1 -0
  113. package/dist/shell.d.ts +14 -0
  114. package/dist/shell.js +19 -0
  115. package/dist/shell.js.map +1 -1
  116. package/package.json +1 -1
  117. package/src/admin/admin-area-labels.ts +85 -0
  118. package/src/admin/admin-forbidden.tsx +75 -0
  119. package/src/admin/admin-overview.tsx +166 -0
  120. package/src/admin/admin-sections.tsx +137 -0
  121. package/src/admin/admin-tool-links.tsx +84 -0
  122. package/src/billing/billing-banner.tsx +32 -4
  123. package/src/billing/billing-labels.ts +53 -0
  124. package/src/billing/billing-overview.ts +37 -0
  125. package/src/billing/billing-standing.ts +8 -0
  126. package/src/billing/cancel-subscription.tsx +102 -0
  127. package/src/billing/plan-card.tsx +97 -1
  128. package/src/billing/plan-switch.tsx +16 -0
  129. package/src/billing/subscription-actions.tsx +64 -15
  130. package/src/components/account-chips.tsx +81 -1
  131. package/src/components/empty-state.tsx +2 -1
  132. package/src/components/nav-pills.tsx +2 -2
  133. package/src/components/tabs.tsx +19 -110
  134. package/src/components/translation-review-parts.tsx +2 -2
  135. package/src/feedback/feedback-menu-labels.ts +0 -2
  136. package/src/feedback/feedback-menu.tsx +0 -6
  137. package/src/i18n/defaults.ts +4 -0
  138. package/src/i18n/german.ts +92 -2
  139. package/src/i18n/kit-labels.tsx +9 -0
  140. package/src/i18n/locales/en.ts +19 -0
  141. package/src/i18n/locales/es.ts +86 -2
  142. package/src/i18n/locales/fr.ts +86 -2
  143. package/src/i18n/locales/hu.ts +84 -2
  144. package/src/i18n/locales/it.ts +87 -2
  145. package/src/i18n/locales/zh.ts +79 -2
  146. package/src/i18n/review.ts +19 -0
  147. package/src/index.ts +30 -2
  148. package/src/settings/settings-layout.tsx +58 -34
  149. package/src/shell/account-menu-language.tsx +116 -0
  150. package/src/shell/admin-menu.tsx +117 -0
  151. package/src/shell/app-shell.tsx +44 -3
  152. package/src/shell/dev-switchers.tsx +171 -0
  153. package/src/shell/sync-status-indicator.tsx +301 -0
  154. package/src/shell/top-bar-actions.tsx +79 -0
  155. package/src/shell/top-bar-parts-labels.ts +133 -0
  156. package/src/shell/topbar-action-menu.tsx +15 -2
  157. package/src/shell/topbar-controls.tsx +20 -3
  158. package/src/shell/tour-menu.tsx +144 -0
  159. package/src/shell.ts +24 -0
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useKitLabels, useKitLocale } from "../i18n/kit-labels.js";
4
+ import { DEFAULT_COMMON_LABELS } from "../i18n/shared-labels.js";
5
+ import { formatDate } from "../lib/format.js";
6
+ import { Button } from "../components/button.js";
7
+ import { DialogFrame } from "../components/dialog-frame.js";
8
+ import { COMMIT_EXCEPT_BILLING } from "../components/write-lock.js";
9
+ import { useBillingLabels } from "./billing-labels.js";
10
+ function CancelSubscriptionConfirm({
11
+ open,
12
+ onOpenChange,
13
+ periodEnd,
14
+ onConfirm,
15
+ pending = false,
16
+ locale: localeProp,
17
+ labels: labelsProp
18
+ }) {
19
+ const labels = useBillingLabels(labelsProp);
20
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
21
+ const locale = useKitLocale(localeProp);
22
+ return /* @__PURE__ */ jsx(
23
+ DialogFrame,
24
+ {
25
+ open,
26
+ title: labels.cancelConfirmTitle,
27
+ description: labels.cancelConfirmBody(formatDate(periodEnd, "medium", { locale })),
28
+ onClose: () => {
29
+ if (!pending) onOpenChange(false);
30
+ },
31
+ onKeyDown: (e) => {
32
+ if (pending && e.key === "Escape") e.preventDefault();
33
+ },
34
+ "aria-busy": pending || void 0,
35
+ "data-cancel-subscription-confirm": "",
36
+ actions: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
37
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: close, disabled: pending, children: common.back }),
38
+ /* @__PURE__ */ jsx(
39
+ Button,
40
+ {
41
+ variant: "danger",
42
+ commit: COMMIT_EXCEPT_BILLING,
43
+ pending,
44
+ onClick: () => {
45
+ if (!pending) onConfirm();
46
+ },
47
+ children: labels.cancelConfirmAction
48
+ }
49
+ )
50
+ ] })
51
+ }
52
+ );
53
+ }
54
+ export {
55
+ CancelSubscriptionConfirm
56
+ };
57
+ //# sourceMappingURL=cancel-subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/billing/cancel-subscription.tsx"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\n\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { DEFAULT_COMMON_LABELS } from \"../i18n/shared-labels\";\nimport { formatDate } from \"../lib/format\";\nimport type { DateInput } from \"../lib/format\";\nimport { Button } from \"../components/button\";\nimport { DialogFrame } from \"../components/dialog-frame\";\nimport { COMMIT_EXCEPT_BILLING } from \"../components/write-lock\";\nimport { useBillingLabels } from \"./billing-labels\";\nimport type { BillingLabels } from \"./billing-labels\";\n\nexport interface CancelSubscriptionConfirmProps {\n open: boolean;\n /** `false` when the admin dismisses it — Back, Escape, the backdrop. Confirm leaves it\n * open: close it once `POST /billing/cancel` answers. */\n onOpenChange: (open: boolean) => void;\n /** The overview's `current_period_end`: the day the subscription ends. Formatted with\n * the kit's date formatter (`formatDate`, `\"medium\"`). */\n periodEnd: DateInput;\n /** Confirm: the app's `POST /billing/cancel` (server-kit 0.14, §16.3). */\n onConfirm: () => void;\n /** The cancel is under way: Confirm's spinner, no second press, and Escape and Back\n * don't close. */\n pending?: boolean;\n /** The date's locale. Default: the provider's. */\n locale?: string;\n /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */\n labels?: LabelOverride<BillingLabels>;\n}\n\n/**\n * The in-app cancel's confirm (docs/billing-harmonization.md §16.2 decision 2, §16.4,\n * ui-kit 0.42): \"Cancel subscription\" for an admin the provider's portal doesn't open for\n * (`SubscriptionActions`' `portal=\"buyer_only\"` → `onCancelInApp`). It names the day the\n * subscription ends — \"Your subscription ends on 9 Nov 2026. Until then everything works\n * as before.\" — and its button reads \"Cancel subscription now\" (German \"Jetzt kündigen\",\n * the confirmation button of §312k BGB).\n *\n * <CancelSubscriptionConfirm\n * open={asking}\n * onOpenChange={setAsking}\n * periodEnd={overview.current_period_end}\n * pending={cancel.isPending}\n * onConfirm={() => cancel.mutate()}\n * />\n *\n * The cancel is at the period's end (Paddle's `cancel`, not immediately); the row follows\n * by webhook (`cancel_at_period_end`), as after a cancel in the portal, and\n * `SubscriptionActions` then offers \"Keep subscription\" (`onResume`).\n *\n * It takes no billing lock (`COMMIT_EXCEPT_BILLING` built in, §3.3): a read-only payer\n * may always cancel. A demo lock still holds it, as the server's demo guard does. The kit\n * sends no request.\n */\nexport function CancelSubscriptionConfirm({\n open,\n onOpenChange,\n periodEnd,\n onConfirm,\n pending = false,\n locale: localeProp,\n labels: labelsProp,\n}: CancelSubscriptionConfirmProps) {\n const labels = useBillingLabels(labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const locale = useKitLocale(localeProp);\n\n return (\n <DialogFrame\n open={open}\n title={labels.cancelConfirmTitle}\n description={labels.cancelConfirmBody(formatDate(periodEnd, \"medium\", { locale }))}\n onClose={() => {\n if (!pending) onOpenChange(false);\n }}\n onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {\n if (pending && e.key === \"Escape\") e.preventDefault();\n }}\n aria-busy={pending || undefined}\n data-cancel-subscription-confirm=\"\"\n actions={(close) => (\n <>\n <Button variant=\"secondary\" onClick={close} disabled={pending}>\n {common.back}\n </Button>\n <Button\n variant=\"danger\"\n commit={COMMIT_EXCEPT_BILLING}\n pending={pending}\n onClick={() => {\n if (!pending) onConfirm();\n }}\n >\n {labels.cancelConfirmAction}\n </Button>\n </>\n )}\n />\n );\n}\n"],"mappings":";AAmFQ,mBACE,KADF;AAjFR,SAAS,cAAc,oBAAoB;AAE3C,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAE3B,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AA8C1B,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AACV,GAAmC;AACjC,QAAM,SAAS,iBAAiB,UAAU;AAC1C,QAAM,SAAS,aAAa,UAAU,qBAAqB;AAC3D,QAAM,SAAS,aAAa,UAAU;AAEtC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO,OAAO;AAAA,MACd,aAAa,OAAO,kBAAkB,WAAW,WAAW,UAAU,EAAE,OAAO,CAAC,CAAC;AAAA,MACjF,SAAS,MAAM;AACb,YAAI,CAAC,QAAS,cAAa,KAAK;AAAA,MAClC;AAAA,MACA,WAAW,CAAC,MAAqC;AAC/C,YAAI,WAAW,EAAE,QAAQ,SAAU,GAAE,eAAe;AAAA,MACtD;AAAA,MACA,aAAW,WAAW;AAAA,MACtB,oCAAiC;AAAA,MACjC,SAAS,CAAC,UACR,iCACE;AAAA,4BAAC,UAAO,SAAQ,aAAY,SAAS,OAAO,UAAU,SACnD,iBAAO,MACV;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,SAAQ;AAAA,YACR,QAAQ;AAAA,YACR;AAAA,YACA,SAAS,MAAM;AACb,kBAAI,CAAC,QAAS,WAAU;AAAA,YAC1B;AAAA,YAEC,iBAAO;AAAA;AAAA,QACV;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
@@ -115,6 +115,24 @@ export interface PlanPickerProps extends Omit<PlanDisplayProps, "currency" | "in
115
115
  onChoose: (choice: PlanChoice) => void;
116
116
  /** The checkout is being opened: the button's spinner, no second press. */
117
117
  pending?: boolean;
118
+ /**
119
+ * 0.42 (§16.2 decision 5, §16.8 B): the payer's free grant runs without an end —
120
+ * `isPermanentGrant(overview)`. A purchase under it changes nothing the payer gets
121
+ * while the grant runs (§12.11), so the button first opens a confirm —
122
+ * `grantWarningTitle`, `grantWarningBody`, "Buy anyway" (`grantWarningAction`) and
123
+ * "Back" — and {@link onChoose} runs only on "Buy anyway". Warned, not refused.
124
+ *
125
+ * Not while {@link switching}: then the pick opens `PlanSwitchConfirm`, which takes
126
+ * the same `permanentGrant` and shows the warning above its figures — one warning,
127
+ * in the dialog where the payer agrees, rather than a confirm before a confirm.
128
+ */
129
+ permanentGrant?: boolean;
130
+ /**
131
+ * 0.42: the overview's `switching` — the app sends this pick to `PlanSwitchConfirm`
132
+ * (§15.2.10), not the checkout. Only decides where {@link permanentGrant}'s warning
133
+ * shows; the button and {@link onChoose} are the same either way.
134
+ */
135
+ switching?: boolean;
118
136
  /** The provider's localised price for a plan, or `undefined` for the catalogue's —
119
137
  * see {@link PlanCardProps.pricePreview}. */
120
138
  pricePreview?: (plan: BillingPlan, choice: Omit<PlanChoice, "plan">) => ReactNode | undefined;
@@ -143,6 +161,32 @@ export interface PlanPickerProps extends Omit<PlanDisplayProps, "currency" | "in
143
161
  * The button never takes the write lock: billing itself always works, a read-only payer
144
162
  * must be able to pay (§3.3). It is off, with the reason on hover and focus, while
145
163
  * nothing is picked or the current plan is.
164
+ *
165
+ * 0.42 (§16.8 B): under a grant without an end (`permanentGrant`) the payer is warned
166
+ * before paying for a plan that won't apply — here, in a confirm before `onChoose`, on
167
+ * the way to the checkout; on the way to a switch (`switching`) in `PlanSwitchConfirm`
168
+ * instead, so the warning shows once on either path.
169
+ */
170
+ export declare function PlanPicker({ plans, current, value: valueProp, defaultValue, onValueChange, interval: intervalProp, defaultInterval, onIntervalChange, currency: currencyProp, defaultCurrency, onCurrencyChange, currencies: currenciesProp, onChoose, pending, permanentGrant, switching, pricePreview, legend, name, className, gridClassName, cardClassName, dimensionLabels, formatLimit, locale: localeProp, labels: labelsProp, }: PlanPickerProps): import("react").JSX.Element;
171
+ export interface GrantWarningConfirmProps {
172
+ /** Shown, controlled. */
173
+ open: boolean;
174
+ /** `false` on "Back", Escape, the backdrop — and after "Buy anyway". */
175
+ onOpenChange: (open: boolean) => void;
176
+ /** "Buy anyway": the app opens its checkout. The dialog closes itself after it. */
177
+ onConfirm: () => void;
178
+ /** Prop > `<UiKitProvider labels={{ billing }}>` > English: `grantWarningTitle`,
179
+ * `grantWarningBody`, `grantWarningAction`. "Back" is `common.back`. */
180
+ labels?: LabelOverride<BillingLabels>;
181
+ }
182
+ /**
183
+ * 0.42 (§16.8 B): the permanent-grant warning before a checkout — `grantWarningTitle`,
184
+ * `grantWarningBody`, "Back" and "Buy anyway" (`grantWarningAction`). {@link PlanPicker}
185
+ * shows it itself under `permanentGrant` when not `switching`. Exported for the path the
186
+ * picker cannot see: an app that meant to switch, learned there is no subscription to
187
+ * switch (keksdose: `/billing/plan/preview` → 409 `billing_not_subscribed`) and falls back
188
+ * to a checkout — show this before that checkout, so a permanent-grant holder is still
189
+ * warned. Carries `data-grant-warning`.
146
190
  */
147
- export declare function PlanPicker({ plans, current, value: valueProp, defaultValue, onValueChange, interval: intervalProp, defaultInterval, onIntervalChange, currency: currencyProp, defaultCurrency, onCurrencyChange, currencies: currenciesProp, onChoose, pending, pricePreview, legend, name, className, gridClassName, cardClassName, dimensionLabels, formatLimit, locale: localeProp, labels: labelsProp, }: PlanPickerProps): import("react").JSX.Element;
191
+ export declare function GrantWarningConfirm({ open, onOpenChange, onConfirm, labels: labelsProp }: GrantWarningConfirmProps): import("react").JSX.Element;
148
192
  export {};
@@ -9,6 +9,7 @@ import { ChoiceCard } from "../components/choice-card.js";
9
9
  import { Chip } from "../components/chip.js";
10
10
  import { ToggleGroup } from "../components/toggle-group.js";
11
11
  import { Button } from "../components/button.js";
12
+ import { DialogFrame } from "../components/dialog-frame.js";
12
13
  import { useBillingLabels } from "./billing-labels.js";
13
14
  import { BILLING_INTERVALS, billingCurrencyFor, formatPlanPrice, planPrice } from "./plan-price.js";
14
15
  function planRelation(plans, code, current) {
@@ -132,6 +133,8 @@ function PlanPicker({
132
133
  currencies: currenciesProp,
133
134
  onChoose,
134
135
  pending,
136
+ permanentGrant = false,
137
+ switching = false,
135
138
  pricePreview,
136
139
  legend,
137
140
  name,
@@ -146,6 +149,7 @@ function PlanPicker({
146
149
  const labels = useBillingLabels(labelsProp);
147
150
  const locale = useKitLocale(localeProp);
148
151
  const generated = useId();
152
+ const [warned, setWarned] = useState(null);
149
153
  const groupName = name ?? generated;
150
154
  const legendId = `${generated}-legend`;
151
155
  const [ownValue, setOwnValue] = useState(() => defaultValue ?? current ?? null);
@@ -236,13 +240,60 @@ function PlanPicker({
236
240
  className: "max-sm:w-full",
237
241
  disabledReason: blocked,
238
242
  pending,
239
- onClick: () => picked && onChoose({ plan: picked.code, interval, currency }),
243
+ onClick: () => {
244
+ if (!picked) return;
245
+ const choice = { plan: picked.code, interval, currency };
246
+ if (permanentGrant && !switching) setWarned(choice);
247
+ else onChoose(choice);
248
+ },
240
249
  children: buttonText
241
250
  }
242
- ) })
251
+ ) }),
252
+ permanentGrant && !switching && /* @__PURE__ */ jsx(
253
+ GrantWarningConfirm,
254
+ {
255
+ open: warned !== null,
256
+ onOpenChange: (open) => {
257
+ if (!open) setWarned(null);
258
+ },
259
+ onConfirm: () => {
260
+ if (warned) onChoose(warned);
261
+ },
262
+ labels: labelsProp
263
+ }
264
+ )
243
265
  ] });
244
266
  }
267
+ function GrantWarningConfirm({ open, onOpenChange, onConfirm, labels: labelsProp }) {
268
+ const labels = useBillingLabels(labelsProp);
269
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
270
+ return /* @__PURE__ */ jsx(
271
+ DialogFrame,
272
+ {
273
+ open,
274
+ title: labels.grantWarningTitle,
275
+ description: labels.grantWarningBody,
276
+ onClose: () => onOpenChange(false),
277
+ "data-grant-warning": "",
278
+ actions: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
279
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: close, children: common.back }),
280
+ /* @__PURE__ */ jsx(
281
+ Button,
282
+ {
283
+ variant: "primary",
284
+ onClick: () => {
285
+ onConfirm();
286
+ onOpenChange(false);
287
+ },
288
+ children: labels.grantWarningAction
289
+ }
290
+ )
291
+ ] })
292
+ }
293
+ );
294
+ }
245
295
  export {
296
+ GrantWarningConfirm,
246
297
  PlanCard,
247
298
  PlanPicker,
248
299
  planRelation
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/billing/plan-card.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { Check, Gauge } from \"lucide-react\";\n\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { formatNumber } from \"../lib/format\";\nimport { cn } from \"../lib/cn\";\nimport { ChoiceCard } from \"../components/choice-card\";\nimport type { ChoiceCardProps } from \"../components/choice-card\";\nimport { Chip } from \"../components/chip\";\nimport { ToggleGroup } from \"../components/toggle-group\";\nimport { Button } from \"../components/button\";\nimport { useBillingLabels } from \"./billing-labels\";\nimport type { BillingLabels } from \"./billing-labels\";\nimport { BILLING_INTERVALS, billingCurrencyFor, formatPlanPrice, planPrice } from \"./plan-price\";\nimport type { BillingCurrency, BillingInterval, PlanPrices } from \"./plan-price\";\n\n/**\n * One plan of the app's catalogue (docs/billing-harmonization.md §3.1) as a page shows it:\n * server-kit's `PlanSpec` from `GET /billing/plans`, plus the words, which are the app's\n * (display names and feature lines come from its i18n, never from the provider).\n */\nexport interface BillingPlan {\n /** The plan code, lowercase on the wire (§12.16); compared without case here. */\n code: string;\n /** The app's display name, in the reader's language: \"Pro\". */\n name: string;\n /** A line under the price. */\n description?: ReactNode;\n /** Gross prices in minor units, per currency and period (§3.1, §12.17). None at all —\n * or 0 — is a free plan. */\n prices?: PlanPrices | null;\n /** Dimension → limit; `null` is unlimited (§3.1). Shown in the object's order. */\n limits?: Readonly<Record<string, number | null>>;\n /** The app's feature lines. */\n features?: readonly ReactNode[];\n /** Not choosable — a plan being retired, say. */\n disabled?: boolean;\n}\n\n/**\n * How a plan stands to the one the payer pays for now: `current` is it, `upgrade` comes\n * after it in the catalogue's order (`PlanSpec.sort`), `downgrade` before it.\n */\nexport type PlanRelation = \"current\" | \"upgrade\" | \"downgrade\";\n\n/** The plan's place against `current`, by the order of `plans`; `undefined` without a\n * current plan (a trial, an ended plan) or for a code that is not in the list. */\nexport function planRelation(\n plans: readonly Pick<BillingPlan, \"code\">[],\n code: string,\n current: string | null | undefined,\n): PlanRelation | undefined {\n if (!current) return undefined;\n const index = (c: string) => plans.findIndex((p) => p.code.toLowerCase() === c.toLowerCase());\n const at = index(code);\n const now = index(current);\n if (at < 0 || now < 0) return undefined;\n return at === now ? \"current\" : at > now ? \"upgrade\" : \"downgrade\";\n}\n\n/** What both parts need to draw a plan. */\ninterface PlanDisplayProps {\n /** The currency the prices are shown in (§2.6). */\n currency: BillingCurrency;\n /** The period the prices are shown for. */\n interval: BillingInterval;\n /** The app's name of each limit's dimension (\"Budgets\"). A dimension without one is\n * shown by its key. */\n dimensionLabels?: Readonly<Record<string, string>>;\n /** How a limit's figure is written — kastlan's storage is bytes (`formatFileSize`).\n * Default: a number in the kit's locale. */\n formatLimit?: (dimension: string, value: number) => string;\n /** Over the provider's locale. */\n locale?: string;\n /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */\n labels?: LabelOverride<BillingLabels>;\n}\n\nexport interface PlanCardProps\n extends Omit<ChoiceCardProps, \"type\" | \"title\" | \"description\" | \"icon\" | \"indeterminate\" | \"value\" | \"labels\">,\n PlanDisplayProps {\n plan: BillingPlan;\n /** See {@link PlanRelation}. `current` draws the \"Current plan\" chip — a word in the\n * card's name, never a colour alone. */\n relation?: PlanRelation;\n /**\n * The provider's own localised price in place of the catalogue's figure (§12.17) — a\n * Merchant of Record's price preview for the buyer's country, tax included. The period\n * and \"VAT included\" stay: the law asks for a gross price, and the card says so.\n */\n pricePreview?: ReactNode;\n}\n\n/** A list from spans (`role=\"list\"`): the card is a `<label>`, which may hold phrasing\n * content only, so a `<ul>` there would be invalid HTML. */\nfunction SpanList({ name, items, icon }: { name: string; items: ReactNode[]; icon: ReactNode }) {\n if (items.length === 0) return null;\n return (\n <span role=\"list\" aria-label={name} className=\"block space-y-1\">\n {items.map((item, i) => (\n <span role=\"listitem\" key={i} className=\"flex items-start gap-1.5 text-secondary\">\n <span aria-hidden className=\"mt-[0.0625rem] flex shrink-0 text-muted [&_svg]:size-3.5\">\n {icon}\n </span>\n <span className=\"min-w-0\">\n {item}\n {/* A space between the items' texts in the flattened description. */}{\" \"}\n </span>\n </span>\n ))}\n </span>\n );\n}\n\n/**\n * One plan as a {@link ChoiceCard} radio (§7): the name (and \"Current plan\"), the GROSS\n * price in the chosen currency and period through `formatMoney` (\"CHF 49 per year, VAT\n * included\", §12.17), the limits (\"Budgets: 3\", \"Seats: Unlimited\") and the app's feature\n * lines. A plan with prices but none for this currency and period is shown, \"Not offered\n * for this billing period\", and cannot be picked.\n *\n * A radio of a set: give the cards one `name`, or use {@link PlanPicker}, which does that\n * and owns the choice. Everything else a `ChoiceCard` takes goes to it — `checked`,\n * `onCheckedChange`, `name`, `className`. Carries `data-plan` and `data-relation`.\n */\nexport function PlanCard({\n // The radio `<input>` (ChoiceCard's): a React 19 ref prop since 0.34 (MOD-4, refactor\n // audit 2026-10), where this was `forwardRef`.\n ref,\n plan,\n relation,\n pricePreview,\n currency,\n interval,\n dimensionLabels,\n formatLimit,\n locale: localeProp,\n labels: labelsProp,\n disabled,\n ...rest\n}: PlanCardProps) {\n const labels = useBillingLabels(labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const locale = useKitLocale(localeProp);\n const price = planPrice(plan.prices, currency, interval);\n\n const priced = price.kind === \"price\";\n const figure = priced\n ? pricePreview !== undefined && pricePreview !== null\n ? pricePreview\n : formatPlanPrice(price.minor, currency, { locale })\n : price.kind === \"free\"\n ? labels.free\n : labels.notOffered;\n\n const limitLines = Object.entries(plan.limits ?? {}).map(([dimension, value]) => {\n const name = dimensionLabels?.[dimension] ?? dimension;\n const shown =\n value === null ? labels.unlimited : formatLimit ? formatLimit(dimension, value) : formatNumber(value, { locale });\n return common.fieldValue(name, shown);\n });\n\n const body = (\n <span className=\"mt-1 block space-y-2\">\n <span className=\"block\">\n <span\n data-part=\"price\"\n className={cn(\n \"tabular-nums\",\n price.kind === \"not-offered\"\n ? \"text-xs text-muted\"\n : \"text-lg font-semibold leading-tight text-primary\",\n )}\n >\n {figure}\n </span>\n {priced && (\n <>\n {\" \"}\n <span className=\"text-xs text-secondary\">\n {interval === \"year\" ? labels.perYear : labels.perMonth}\n </span>{\" \"}\n <span className=\"block text-xs text-muted\">{labels.vatIncluded}</span>\n </>\n )}{\" \"}\n </span>\n {plan.description !== undefined && plan.description !== null && (\n <span className=\"block text-secondary\">{plan.description} </span>\n )}\n <SpanList name={labels.limits} items={limitLines} icon={<Gauge />} />\n <SpanList name={labels.features} items={[...(plan.features ?? [])]} icon={<Check />} />\n </span>\n );\n\n return (\n <ChoiceCard\n ref={ref}\n {...rest}\n type=\"radio\"\n value={plan.code}\n disabled={disabled || plan.disabled || price.kind === \"not-offered\"}\n data-plan={plan.code}\n data-relation={relation}\n title={\n <>\n {plan.name}\n {relation === \"current\" && (\n <>\n {\" \"}\n <Chip size=\"xs\" tone=\"brand\" shape=\"square\" caps className=\"ms-1 align-[0.0625rem]\">\n {labels.current}\n </Chip>\n </>\n )}\n </>\n }\n description={body}\n />\n );\n}\n\n/** What {@link PlanPickerProps.onChoose} is handed: everything `POST /billing/checkout`\n * takes (§4). */\nexport interface PlanChoice {\n plan: string;\n interval: BillingInterval;\n currency: BillingCurrency;\n}\n\nexport interface PlanPickerProps extends Omit<PlanDisplayProps, \"currency\" | \"interval\"> {\n /** The catalogue, in its order (`PlanSpec.sort`): cheapest first. The order decides\n * upgrade and downgrade. */\n plans: readonly BillingPlan[];\n /**\n * The plan the payer pays for now (`plan` of the overview while `active` or\n * `past_due`). Leave it out during a trial and after a plan ended: then every plan is\n * \"Choose …\", the trial's plan included, since none is paid for yet.\n */\n current?: string | null;\n /** The picked plan, controlled. `null` while none is. */\n value?: string | null;\n /** The picked plan, uncontrolled. Default: `current`, else nothing. */\n defaultValue?: string | null;\n onValueChange?: (plan: string) => void;\n /** The period, controlled. */\n interval?: BillingInterval;\n /** The period, uncontrolled. Default `year` — lead with yearly (§12.17). */\n defaultInterval?: BillingInterval;\n onIntervalChange?: (interval: BillingInterval) => void;\n /** The currency, controlled. */\n currency?: BillingCurrency;\n /** The currency, uncontrolled. Default: the account's stored currency is the app's to\n * pass here (§12.18); without it, {@link billingCurrencyFor} the kit's locale. */\n defaultCurrency?: BillingCurrency;\n onCurrencyChange?: (currency: BillingCurrency) => void;\n /** The currencies the payer may switch between. Default: every currency a plan has a\n * price in. The switch shows only for more than one. */\n currencies?: readonly BillingCurrency[];\n /** The button: the app starts its checkout (`POST /billing/checkout`, then off to the\n * provider's page). The kit sends no request. */\n onChoose: (choice: PlanChoice) => void;\n /** The checkout is being opened: the button's spinner, no second press. */\n pending?: boolean;\n /** The provider's localised price for a plan, or `undefined` for the catalogue's —\n * see {@link PlanCardProps.pricePreview}. */\n pricePreview?: (plan: BillingPlan, choice: Omit<PlanChoice, \"plan\">) => ReactNode | undefined;\n /** A visible question over the cards. Without one the set is named \"Plans\". */\n legend?: ReactNode;\n /** Shared by the radios. Generated if omitted. */\n name?: string;\n /** Classes for the whole picker. */\n className?: string;\n /** Classes for the card grid. Default: one column, two from `sm`, three from `lg`. */\n gridClassName?: string;\n /** Classes for every card. */\n cardClassName?: string;\n}\n\n/** Every currency some plan has a price in, CHF first. */\nfunction pricedCurrencies(plans: readonly BillingPlan[]): BillingCurrency[] {\n const found = new Set<BillingCurrency>();\n for (const p of plans) for (const c of Object.keys(p.prices ?? {})) found.add(c as BillingCurrency);\n return ([\"CHF\", \"EUR\"] as const).filter((c) => found.has(c));\n}\n\n/** Every period some plan has a price for, yearly first. */\nfunction pricedIntervals(plans: readonly BillingPlan[]): BillingInterval[] {\n const found = new Set<BillingInterval>();\n for (const p of plans)\n for (const byInterval of Object.values(p.prices ?? {}))\n for (const [k, v] of Object.entries(byInterval ?? {})) if (typeof v === \"number\") found.add(k as BillingInterval);\n return BILLING_INTERVALS.filter((i) => found.has(i));\n}\n\n/**\n * The plans to choose from (§7): the period switch — yearly first (§12.17) — and, where\n * the payer may pay in either, the currency switch (§2.6); a {@link PlanCard} per plan in\n * a radio set; and one button that says what pressing it does: \"Upgrade to Pro\", \"Switch\n * to Free\", or \"Choose Pro\" with no plan paid for yet.\n *\n * One button under the set rather than one per card: each card IS a radio — a `<label>`\n * round an `<input>` — and a button inside a label is interactive content inside\n * interactive content. Picking and committing are two steps anyway: the price under the\n * picked card is what checkout will charge.\n *\n * The button never takes the write lock: billing itself always works, a read-only payer\n * must be able to pay (§3.3). It is off, with the reason on hover and focus, while\n * nothing is picked or the current plan is.\n */\nexport function PlanPicker({\n plans,\n current,\n value: valueProp,\n defaultValue,\n onValueChange,\n interval: intervalProp,\n defaultInterval = \"year\",\n onIntervalChange,\n currency: currencyProp,\n defaultCurrency,\n onCurrencyChange,\n currencies: currenciesProp,\n onChoose,\n pending,\n pricePreview,\n legend,\n name,\n className,\n gridClassName,\n cardClassName,\n dimensionLabels,\n formatLimit,\n locale: localeProp,\n labels: labelsProp,\n}: PlanPickerProps) {\n const labels = useBillingLabels(labelsProp);\n const locale = useKitLocale(localeProp);\n const generated = useId();\n const groupName = name ?? generated;\n const legendId = `${generated}-legend`;\n\n const [ownValue, setOwnValue] = useState<string | null>(() => defaultValue ?? current ?? null);\n const [ownInterval, setOwnInterval] = useState<BillingInterval>(defaultInterval);\n const [ownCurrency, setOwnCurrency] = useState<BillingCurrency>(\n () => defaultCurrency ?? billingCurrencyFor(locale),\n );\n const value = valueProp !== undefined ? valueProp : ownValue;\n const interval = intervalProp ?? ownInterval;\n const currency = currencyProp ?? ownCurrency;\n\n const pick = (code: string) => {\n if (valueProp === undefined) setOwnValue(code);\n onValueChange?.(code);\n };\n const setInterval = (next: BillingInterval) => {\n if (intervalProp === undefined) setOwnInterval(next);\n onIntervalChange?.(next);\n };\n const setCurrency = (next: BillingCurrency) => {\n if (currencyProp === undefined) setOwnCurrency(next);\n onCurrencyChange?.(next);\n };\n\n const currencies = currenciesProp ?? pricedCurrencies(plans);\n const intervals = pricedIntervals(plans);\n const picked = value ? plans.find((p) => p.code.toLowerCase() === value.toLowerCase()) : undefined;\n const relation = picked ? planRelation(plans, picked.code, current) : undefined;\n const pickedPrice = picked ? planPrice(picked.prices, currency, interval) : undefined;\n\n const buttonText = !picked\n ? labels.choosePlan\n : relation === \"upgrade\"\n ? labels.upgrade(picked.name)\n : relation === \"downgrade\"\n ? labels.downgrade(picked.name)\n : labels.choose(picked.name);\n const blocked = !picked\n ? labels.pickFirst\n : relation === \"current\"\n ? labels.isCurrent\n : pickedPrice?.kind === \"not-offered\"\n ? labels.notOffered\n : undefined;\n\n return (\n <div className={cn(\"min-w-0 space-y-3\", className)} data-billing-interval={interval} data-billing-currency={currency}>\n {(intervals.length > 1 || currencies.length > 1) && (\n <div className=\"flex flex-wrap items-center gap-2\">\n {intervals.length > 1 && (\n <ToggleGroup\n aria-label={labels.interval}\n // Content-wide, so the two switches share a row and wrap only when narrow.\n className=\"w-auto\"\n options={intervals.map((i) => ({ value: i, label: i === \"year\" ? labels.yearly : labels.monthly }))}\n value={interval}\n onChange={setInterval}\n />\n )}\n {currencies.length > 1 && (\n <ToggleGroup\n aria-label={labels.currency}\n className=\"w-auto\"\n options={currencies.map((c) => ({ value: c, label: c }))}\n value={currency}\n onChange={setCurrency}\n />\n )}\n </div>\n )}\n <fieldset\n className=\"min-w-0\"\n aria-labelledby={legend !== undefined ? legendId : undefined}\n aria-label={legend === undefined ? labels.plans : undefined}\n >\n {legend !== undefined && (\n <legend id={legendId} className=\"mb-2 text-sm font-medium text-primary\">\n {legend}\n </legend>\n )}\n <div className={cn(\"grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-3\", gridClassName)}>\n {plans.map((plan) => (\n <PlanCard\n key={plan.code}\n plan={plan}\n name={groupName}\n currency={currency}\n interval={interval}\n relation={planRelation(plans, plan.code, current)}\n pricePreview={pricePreview?.(plan, { interval, currency })}\n checked={picked?.code === plan.code}\n onCheckedChange={(on) => on && pick(plan.code)}\n dimensionLabels={dimensionLabels}\n formatLimit={formatLimit}\n locale={locale}\n labels={labelsProp}\n className={cardClassName}\n />\n ))}\n </div>\n </fieldset>\n <div className=\"flex justify-end\">\n <Button\n type=\"button\"\n variant=\"primary\"\n className=\"max-sm:w-full\"\n disabledReason={blocked}\n pending={pending}\n onClick={() => picked && onChoose({ plan: picked.code, interval, currency })}\n >\n {buttonText}\n </Button>\n </div>\n </div>\n );\n}\n"],"mappings":";AAuGU,SA4EA,UA5EA,KAGA,YAHA;AAvGV,SAAS,OAAO,gBAAgB;AAEhC,SAAS,OAAO,aAAa;AAE7B,SAAS,uBAAuB,cAAc,oBAAoB;AAElE,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,kBAAkB;AAE3B,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB,oBAAoB,iBAAiB,iBAAiB;AAkC3E,SAAS,aACd,OACA,MACA,SAC0B;AAC1B,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,QAAQ,CAAC,MAAc,MAAM,UAAU,CAAC,MAAM,EAAE,KAAK,YAAY,MAAM,EAAE,YAAY,CAAC;AAC5F,QAAM,KAAK,MAAM,IAAI;AACrB,QAAM,MAAM,MAAM,OAAO;AACzB,MAAI,KAAK,KAAK,MAAM,EAAG,QAAO;AAC9B,SAAO,OAAO,MAAM,YAAY,KAAK,MAAM,YAAY;AACzD;AAqCA,SAAS,SAAS,EAAE,MAAM,OAAO,KAAK,GAA0D;AAC9F,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,SACE,oBAAC,UAAK,MAAK,QAAO,cAAY,MAAM,WAAU,mBAC3C,gBAAM,IAAI,CAAC,MAAM,MAChB,qBAAC,UAAK,MAAK,YAAmB,WAAU,2CACtC;AAAA,wBAAC,UAAK,eAAW,MAAC,WAAU,4DACzB,gBACH;AAAA,IACA,qBAAC,UAAK,WAAU,WAC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,WAAU;AAAA,QACV,mBAAiB,WAAW,SAAY,WAAW;AAAA,QACnD,cAAY,WAAW,SAAY,OAAO,QAAQ;AAAA,QAEjD;AAAA,qBAAW,UACV,oBAAC,YAAO,IAAI,UAAU,WAAU,yCAC7B,kBACH;AAAA,UAEF,oBAAC,SAAI,WAAW,GAAG,wDAAwD,aAAa,GACrF,gBAAM,IAAI,CAAC,SACV;AAAA,YAAC;AAAA;AAAA,cAEC;AAAA,cACA,MAAM;AAAA,cACN;AAAA,cACA;AAAA,cACA,UAAU,aAAa,OAAO,KAAK,MAAM,OAAO;AAAA,cAChD,cAAc,eAAe,MAAM,EAAE,UAAU,SAAS,CAAC;AAAA,cACzD,SAAS,QAAQ,SAAS,KAAK;AAAA,cAC/B,iBAAiB,CAAC,OAAO,MAAM,KAAK,KAAK,IAAI;AAAA,cAC7C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR,WAAW;AAAA;AAAA,YAbN,KAAK;AAAA,UAcZ,CACD,GACH;AAAA;AAAA;AAAA,IACF;AAAA,IACA,oBAAC,SAAI,WAAU,oBACb;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAQ;AAAA,QACR,WAAU;AAAA,QACV,gBAAgB;AAAA,QAChB;AAAA,QACA,SAAS,MAAM,UAAU,SAAS,EAAE,MAAM,OAAO,MAAM,UAAU,SAAS,CAAC;AAAA,QAE1E;AAAA;AAAA,IACH,GACF;AAAA,KACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/billing/plan-card.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { Check, Gauge } from \"lucide-react\";\n\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { formatNumber } from \"../lib/format\";\nimport { cn } from \"../lib/cn\";\nimport { ChoiceCard } from \"../components/choice-card\";\nimport type { ChoiceCardProps } from \"../components/choice-card\";\nimport { Chip } from \"../components/chip\";\nimport { ToggleGroup } from \"../components/toggle-group\";\nimport { Button } from \"../components/button\";\nimport { DialogFrame } from \"../components/dialog-frame\";\nimport { useBillingLabels } from \"./billing-labels\";\nimport type { BillingLabels } from \"./billing-labels\";\nimport { BILLING_INTERVALS, billingCurrencyFor, formatPlanPrice, planPrice } from \"./plan-price\";\nimport type { BillingCurrency, BillingInterval, PlanPrices } from \"./plan-price\";\n\n/**\n * One plan of the app's catalogue (docs/billing-harmonization.md §3.1) as a page shows it:\n * server-kit's `PlanSpec` from `GET /billing/plans`, plus the words, which are the app's\n * (display names and feature lines come from its i18n, never from the provider).\n */\nexport interface BillingPlan {\n /** The plan code, lowercase on the wire (§12.16); compared without case here. */\n code: string;\n /** The app's display name, in the reader's language: \"Pro\". */\n name: string;\n /** A line under the price. */\n description?: ReactNode;\n /** Gross prices in minor units, per currency and period (§3.1, §12.17). None at all —\n * or 0 — is a free plan. */\n prices?: PlanPrices | null;\n /** Dimension → limit; `null` is unlimited (§3.1). Shown in the object's order. */\n limits?: Readonly<Record<string, number | null>>;\n /** The app's feature lines. */\n features?: readonly ReactNode[];\n /** Not choosable — a plan being retired, say. */\n disabled?: boolean;\n}\n\n/**\n * How a plan stands to the one the payer pays for now: `current` is it, `upgrade` comes\n * after it in the catalogue's order (`PlanSpec.sort`), `downgrade` before it.\n */\nexport type PlanRelation = \"current\" | \"upgrade\" | \"downgrade\";\n\n/** The plan's place against `current`, by the order of `plans`; `undefined` without a\n * current plan (a trial, an ended plan) or for a code that is not in the list. */\nexport function planRelation(\n plans: readonly Pick<BillingPlan, \"code\">[],\n code: string,\n current: string | null | undefined,\n): PlanRelation | undefined {\n if (!current) return undefined;\n const index = (c: string) => plans.findIndex((p) => p.code.toLowerCase() === c.toLowerCase());\n const at = index(code);\n const now = index(current);\n if (at < 0 || now < 0) return undefined;\n return at === now ? \"current\" : at > now ? \"upgrade\" : \"downgrade\";\n}\n\n/** What both parts need to draw a plan. */\ninterface PlanDisplayProps {\n /** The currency the prices are shown in (§2.6). */\n currency: BillingCurrency;\n /** The period the prices are shown for. */\n interval: BillingInterval;\n /** The app's name of each limit's dimension (\"Budgets\"). A dimension without one is\n * shown by its key. */\n dimensionLabels?: Readonly<Record<string, string>>;\n /** How a limit's figure is written — kastlan's storage is bytes (`formatFileSize`).\n * Default: a number in the kit's locale. */\n formatLimit?: (dimension: string, value: number) => string;\n /** Over the provider's locale. */\n locale?: string;\n /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */\n labels?: LabelOverride<BillingLabels>;\n}\n\nexport interface PlanCardProps\n extends Omit<ChoiceCardProps, \"type\" | \"title\" | \"description\" | \"icon\" | \"indeterminate\" | \"value\" | \"labels\">,\n PlanDisplayProps {\n plan: BillingPlan;\n /** See {@link PlanRelation}. `current` draws the \"Current plan\" chip — a word in the\n * card's name, never a colour alone. */\n relation?: PlanRelation;\n /**\n * The provider's own localised price in place of the catalogue's figure (§12.17) — a\n * Merchant of Record's price preview for the buyer's country, tax included. The period\n * and \"VAT included\" stay: the law asks for a gross price, and the card says so.\n */\n pricePreview?: ReactNode;\n}\n\n/** A list from spans (`role=\"list\"`): the card is a `<label>`, which may hold phrasing\n * content only, so a `<ul>` there would be invalid HTML. */\nfunction SpanList({ name, items, icon }: { name: string; items: ReactNode[]; icon: ReactNode }) {\n if (items.length === 0) return null;\n return (\n <span role=\"list\" aria-label={name} className=\"block space-y-1\">\n {items.map((item, i) => (\n <span role=\"listitem\" key={i} className=\"flex items-start gap-1.5 text-secondary\">\n <span aria-hidden className=\"mt-[0.0625rem] flex shrink-0 text-muted [&_svg]:size-3.5\">\n {icon}\n </span>\n <span className=\"min-w-0\">\n {item}\n {/* A space between the items' texts in the flattened description. */}{\" \"}\n </span>\n </span>\n ))}\n </span>\n );\n}\n\n/**\n * One plan as a {@link ChoiceCard} radio (§7): the name (and \"Current plan\"), the GROSS\n * price in the chosen currency and period through `formatMoney` (\"CHF 49 per year, VAT\n * included\", §12.17), the limits (\"Budgets: 3\", \"Seats: Unlimited\") and the app's feature\n * lines. A plan with prices but none for this currency and period is shown, \"Not offered\n * for this billing period\", and cannot be picked.\n *\n * A radio of a set: give the cards one `name`, or use {@link PlanPicker}, which does that\n * and owns the choice. Everything else a `ChoiceCard` takes goes to it — `checked`,\n * `onCheckedChange`, `name`, `className`. Carries `data-plan` and `data-relation`.\n */\nexport function PlanCard({\n // The radio `<input>` (ChoiceCard's): a React 19 ref prop since 0.34 (MOD-4, refactor\n // audit 2026-10), where this was `forwardRef`.\n ref,\n plan,\n relation,\n pricePreview,\n currency,\n interval,\n dimensionLabels,\n formatLimit,\n locale: localeProp,\n labels: labelsProp,\n disabled,\n ...rest\n}: PlanCardProps) {\n const labels = useBillingLabels(labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const locale = useKitLocale(localeProp);\n const price = planPrice(plan.prices, currency, interval);\n\n const priced = price.kind === \"price\";\n const figure = priced\n ? pricePreview !== undefined && pricePreview !== null\n ? pricePreview\n : formatPlanPrice(price.minor, currency, { locale })\n : price.kind === \"free\"\n ? labels.free\n : labels.notOffered;\n\n const limitLines = Object.entries(plan.limits ?? {}).map(([dimension, value]) => {\n const name = dimensionLabels?.[dimension] ?? dimension;\n const shown =\n value === null ? labels.unlimited : formatLimit ? formatLimit(dimension, value) : formatNumber(value, { locale });\n return common.fieldValue(name, shown);\n });\n\n const body = (\n <span className=\"mt-1 block space-y-2\">\n <span className=\"block\">\n <span\n data-part=\"price\"\n className={cn(\n \"tabular-nums\",\n price.kind === \"not-offered\"\n ? \"text-xs text-muted\"\n : \"text-lg font-semibold leading-tight text-primary\",\n )}\n >\n {figure}\n </span>\n {priced && (\n <>\n {\" \"}\n <span className=\"text-xs text-secondary\">\n {interval === \"year\" ? labels.perYear : labels.perMonth}\n </span>{\" \"}\n <span className=\"block text-xs text-muted\">{labels.vatIncluded}</span>\n </>\n )}{\" \"}\n </span>\n {plan.description !== undefined && plan.description !== null && (\n <span className=\"block text-secondary\">{plan.description} </span>\n )}\n <SpanList name={labels.limits} items={limitLines} icon={<Gauge />} />\n <SpanList name={labels.features} items={[...(plan.features ?? [])]} icon={<Check />} />\n </span>\n );\n\n return (\n <ChoiceCard\n ref={ref}\n {...rest}\n type=\"radio\"\n value={plan.code}\n disabled={disabled || plan.disabled || price.kind === \"not-offered\"}\n data-plan={plan.code}\n data-relation={relation}\n title={\n <>\n {plan.name}\n {relation === \"current\" && (\n <>\n {\" \"}\n <Chip size=\"xs\" tone=\"brand\" shape=\"square\" caps className=\"ms-1 align-[0.0625rem]\">\n {labels.current}\n </Chip>\n </>\n )}\n </>\n }\n description={body}\n />\n );\n}\n\n/** What {@link PlanPickerProps.onChoose} is handed: everything `POST /billing/checkout`\n * takes (§4). */\nexport interface PlanChoice {\n plan: string;\n interval: BillingInterval;\n currency: BillingCurrency;\n}\n\nexport interface PlanPickerProps extends Omit<PlanDisplayProps, \"currency\" | \"interval\"> {\n /** The catalogue, in its order (`PlanSpec.sort`): cheapest first. The order decides\n * upgrade and downgrade. */\n plans: readonly BillingPlan[];\n /**\n * The plan the payer pays for now (`plan` of the overview while `active` or\n * `past_due`). Leave it out during a trial and after a plan ended: then every plan is\n * \"Choose …\", the trial's plan included, since none is paid for yet.\n */\n current?: string | null;\n /** The picked plan, controlled. `null` while none is. */\n value?: string | null;\n /** The picked plan, uncontrolled. Default: `current`, else nothing. */\n defaultValue?: string | null;\n onValueChange?: (plan: string) => void;\n /** The period, controlled. */\n interval?: BillingInterval;\n /** The period, uncontrolled. Default `year` — lead with yearly (§12.17). */\n defaultInterval?: BillingInterval;\n onIntervalChange?: (interval: BillingInterval) => void;\n /** The currency, controlled. */\n currency?: BillingCurrency;\n /** The currency, uncontrolled. Default: the account's stored currency is the app's to\n * pass here (§12.18); without it, {@link billingCurrencyFor} the kit's locale. */\n defaultCurrency?: BillingCurrency;\n onCurrencyChange?: (currency: BillingCurrency) => void;\n /** The currencies the payer may switch between. Default: every currency a plan has a\n * price in. The switch shows only for more than one. */\n currencies?: readonly BillingCurrency[];\n /** The button: the app starts its checkout (`POST /billing/checkout`, then off to the\n * provider's page). The kit sends no request. */\n onChoose: (choice: PlanChoice) => void;\n /** The checkout is being opened: the button's spinner, no second press. */\n pending?: boolean;\n /**\n * 0.42 (§16.2 decision 5, §16.8 B): the payer's free grant runs without an end —\n * `isPermanentGrant(overview)`. A purchase under it changes nothing the payer gets\n * while the grant runs (§12.11), so the button first opens a confirm —\n * `grantWarningTitle`, `grantWarningBody`, \"Buy anyway\" (`grantWarningAction`) and\n * \"Back\" — and {@link onChoose} runs only on \"Buy anyway\". Warned, not refused.\n *\n * Not while {@link switching}: then the pick opens `PlanSwitchConfirm`, which takes\n * the same `permanentGrant` and shows the warning above its figures — one warning,\n * in the dialog where the payer agrees, rather than a confirm before a confirm.\n */\n permanentGrant?: boolean;\n /**\n * 0.42: the overview's `switching` — the app sends this pick to `PlanSwitchConfirm`\n * (§15.2.10), not the checkout. Only decides where {@link permanentGrant}'s warning\n * shows; the button and {@link onChoose} are the same either way.\n */\n switching?: boolean;\n /** The provider's localised price for a plan, or `undefined` for the catalogue's —\n * see {@link PlanCardProps.pricePreview}. */\n pricePreview?: (plan: BillingPlan, choice: Omit<PlanChoice, \"plan\">) => ReactNode | undefined;\n /** A visible question over the cards. Without one the set is named \"Plans\". */\n legend?: ReactNode;\n /** Shared by the radios. Generated if omitted. */\n name?: string;\n /** Classes for the whole picker. */\n className?: string;\n /** Classes for the card grid. Default: one column, two from `sm`, three from `lg`. */\n gridClassName?: string;\n /** Classes for every card. */\n cardClassName?: string;\n}\n\n/** Every currency some plan has a price in, CHF first. */\nfunction pricedCurrencies(plans: readonly BillingPlan[]): BillingCurrency[] {\n const found = new Set<BillingCurrency>();\n for (const p of plans) for (const c of Object.keys(p.prices ?? {})) found.add(c as BillingCurrency);\n return ([\"CHF\", \"EUR\"] as const).filter((c) => found.has(c));\n}\n\n/** Every period some plan has a price for, yearly first. */\nfunction pricedIntervals(plans: readonly BillingPlan[]): BillingInterval[] {\n const found = new Set<BillingInterval>();\n for (const p of plans)\n for (const byInterval of Object.values(p.prices ?? {}))\n for (const [k, v] of Object.entries(byInterval ?? {})) if (typeof v === \"number\") found.add(k as BillingInterval);\n return BILLING_INTERVALS.filter((i) => found.has(i));\n}\n\n/**\n * The plans to choose from (§7): the period switch — yearly first (§12.17) — and, where\n * the payer may pay in either, the currency switch (§2.6); a {@link PlanCard} per plan in\n * a radio set; and one button that says what pressing it does: \"Upgrade to Pro\", \"Switch\n * to Free\", or \"Choose Pro\" with no plan paid for yet.\n *\n * One button under the set rather than one per card: each card IS a radio — a `<label>`\n * round an `<input>` — and a button inside a label is interactive content inside\n * interactive content. Picking and committing are two steps anyway: the price under the\n * picked card is what checkout will charge.\n *\n * The button never takes the write lock: billing itself always works, a read-only payer\n * must be able to pay (§3.3). It is off, with the reason on hover and focus, while\n * nothing is picked or the current plan is.\n *\n * 0.42 (§16.8 B): under a grant without an end (`permanentGrant`) the payer is warned\n * before paying for a plan that won't apply — here, in a confirm before `onChoose`, on\n * the way to the checkout; on the way to a switch (`switching`) in `PlanSwitchConfirm`\n * instead, so the warning shows once on either path.\n */\nexport function PlanPicker({\n plans,\n current,\n value: valueProp,\n defaultValue,\n onValueChange,\n interval: intervalProp,\n defaultInterval = \"year\",\n onIntervalChange,\n currency: currencyProp,\n defaultCurrency,\n onCurrencyChange,\n currencies: currenciesProp,\n onChoose,\n pending,\n permanentGrant = false,\n switching = false,\n pricePreview,\n legend,\n name,\n className,\n gridClassName,\n cardClassName,\n dimensionLabels,\n formatLimit,\n locale: localeProp,\n labels: labelsProp,\n}: PlanPickerProps) {\n const labels = useBillingLabels(labelsProp);\n const locale = useKitLocale(localeProp);\n const generated = useId();\n /** The choice the grant warning holds back until \"Buy anyway\". */\n const [warned, setWarned] = useState<PlanChoice | null>(null);\n const groupName = name ?? generated;\n const legendId = `${generated}-legend`;\n\n const [ownValue, setOwnValue] = useState<string | null>(() => defaultValue ?? current ?? null);\n const [ownInterval, setOwnInterval] = useState<BillingInterval>(defaultInterval);\n const [ownCurrency, setOwnCurrency] = useState<BillingCurrency>(\n () => defaultCurrency ?? billingCurrencyFor(locale),\n );\n const value = valueProp !== undefined ? valueProp : ownValue;\n const interval = intervalProp ?? ownInterval;\n const currency = currencyProp ?? ownCurrency;\n\n const pick = (code: string) => {\n if (valueProp === undefined) setOwnValue(code);\n onValueChange?.(code);\n };\n const setInterval = (next: BillingInterval) => {\n if (intervalProp === undefined) setOwnInterval(next);\n onIntervalChange?.(next);\n };\n const setCurrency = (next: BillingCurrency) => {\n if (currencyProp === undefined) setOwnCurrency(next);\n onCurrencyChange?.(next);\n };\n\n const currencies = currenciesProp ?? pricedCurrencies(plans);\n const intervals = pricedIntervals(plans);\n const picked = value ? plans.find((p) => p.code.toLowerCase() === value.toLowerCase()) : undefined;\n const relation = picked ? planRelation(plans, picked.code, current) : undefined;\n const pickedPrice = picked ? planPrice(picked.prices, currency, interval) : undefined;\n\n const buttonText = !picked\n ? labels.choosePlan\n : relation === \"upgrade\"\n ? labels.upgrade(picked.name)\n : relation === \"downgrade\"\n ? labels.downgrade(picked.name)\n : labels.choose(picked.name);\n const blocked = !picked\n ? labels.pickFirst\n : relation === \"current\"\n ? labels.isCurrent\n : pickedPrice?.kind === \"not-offered\"\n ? labels.notOffered\n : undefined;\n\n return (\n <div className={cn(\"min-w-0 space-y-3\", className)} data-billing-interval={interval} data-billing-currency={currency}>\n {(intervals.length > 1 || currencies.length > 1) && (\n <div className=\"flex flex-wrap items-center gap-2\">\n {intervals.length > 1 && (\n <ToggleGroup\n aria-label={labels.interval}\n // Content-wide, so the two switches share a row and wrap only when narrow.\n className=\"w-auto\"\n options={intervals.map((i) => ({ value: i, label: i === \"year\" ? labels.yearly : labels.monthly }))}\n value={interval}\n onChange={setInterval}\n />\n )}\n {currencies.length > 1 && (\n <ToggleGroup\n aria-label={labels.currency}\n className=\"w-auto\"\n options={currencies.map((c) => ({ value: c, label: c }))}\n value={currency}\n onChange={setCurrency}\n />\n )}\n </div>\n )}\n <fieldset\n className=\"min-w-0\"\n aria-labelledby={legend !== undefined ? legendId : undefined}\n aria-label={legend === undefined ? labels.plans : undefined}\n >\n {legend !== undefined && (\n <legend id={legendId} className=\"mb-2 text-sm font-medium text-primary\">\n {legend}\n </legend>\n )}\n <div className={cn(\"grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-3\", gridClassName)}>\n {plans.map((plan) => (\n <PlanCard\n key={plan.code}\n plan={plan}\n name={groupName}\n currency={currency}\n interval={interval}\n relation={planRelation(plans, plan.code, current)}\n pricePreview={pricePreview?.(plan, { interval, currency })}\n checked={picked?.code === plan.code}\n onCheckedChange={(on) => on && pick(plan.code)}\n dimensionLabels={dimensionLabels}\n formatLimit={formatLimit}\n locale={locale}\n labels={labelsProp}\n className={cardClassName}\n />\n ))}\n </div>\n </fieldset>\n <div className=\"flex justify-end\">\n <Button\n type=\"button\"\n variant=\"primary\"\n className=\"max-sm:w-full\"\n disabledReason={blocked}\n pending={pending}\n onClick={() => {\n if (!picked) return;\n const choice = { plan: picked.code, interval, currency };\n if (permanentGrant && !switching) setWarned(choice);\n else onChoose(choice);\n }}\n >\n {buttonText}\n </Button>\n </div>\n {permanentGrant && !switching && (\n <GrantWarningConfirm\n open={warned !== null}\n onOpenChange={(open) => {\n if (!open) setWarned(null);\n }}\n onConfirm={() => {\n if (warned) onChoose(warned);\n }}\n labels={labelsProp}\n />\n )}\n </div>\n );\n}\n\nexport interface GrantWarningConfirmProps {\n /** Shown, controlled. */\n open: boolean;\n /** `false` on \"Back\", Escape, the backdrop — and after \"Buy anyway\". */\n onOpenChange: (open: boolean) => void;\n /** \"Buy anyway\": the app opens its checkout. The dialog closes itself after it. */\n onConfirm: () => void;\n /** Prop > `<UiKitProvider labels={{ billing }}>` > English: `grantWarningTitle`,\n * `grantWarningBody`, `grantWarningAction`. \"Back\" is `common.back`. */\n labels?: LabelOverride<BillingLabels>;\n}\n\n/**\n * 0.42 (§16.8 B): the permanent-grant warning before a checkout — `grantWarningTitle`,\n * `grantWarningBody`, \"Back\" and \"Buy anyway\" (`grantWarningAction`). {@link PlanPicker}\n * shows it itself under `permanentGrant` when not `switching`. Exported for the path the\n * picker cannot see: an app that meant to switch, learned there is no subscription to\n * switch (keksdose: `/billing/plan/preview` → 409 `billing_not_subscribed`) and falls back\n * to a checkout — show this before that checkout, so a permanent-grant holder is still\n * warned. Carries `data-grant-warning`.\n */\nexport function GrantWarningConfirm({ open, onOpenChange, onConfirm, labels: labelsProp }: GrantWarningConfirmProps) {\n const labels = useBillingLabels(labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n return (\n <DialogFrame\n open={open}\n title={labels.grantWarningTitle}\n description={labels.grantWarningBody}\n onClose={() => onOpenChange(false)}\n data-grant-warning=\"\"\n actions={(close) => (\n <>\n <Button variant=\"secondary\" onClick={close}>\n {common.back}\n </Button>\n <Button\n variant=\"primary\"\n onClick={() => {\n onConfirm();\n onOpenChange(false);\n }}\n >\n {labels.grantWarningAction}\n </Button>\n </>\n )}\n />\n );\n}\n"],"mappings":";AAwGU,SA4EA,UA5EA,KAGA,YAHA;AAxGV,SAAS,OAAO,gBAAgB;AAEhC,SAAS,OAAO,aAAa;AAE7B,SAAS,uBAAuB,cAAc,oBAAoB;AAElE,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,kBAAkB;AAE3B,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB,oBAAoB,iBAAiB,iBAAiB;AAkC3E,SAAS,aACd,OACA,MACA,SAC0B;AAC1B,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,QAAQ,CAAC,MAAc,MAAM,UAAU,CAAC,MAAM,EAAE,KAAK,YAAY,MAAM,EAAE,YAAY,CAAC;AAC5F,QAAM,KAAK,MAAM,IAAI;AACrB,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,MAAK;AAAA,QACL,SAAQ;AAAA,QACR,WAAU;AAAA,QACV,gBAAgB;AAAA,QAChB;AAAA,QACA,SAAS,MAAM;AACb,cAAI,CAAC,OAAQ;AACb,gBAAM,SAAS,EAAE,MAAM,OAAO,MAAM,UAAU,SAAS;AACvD,cAAI,kBAAkB,CAAC,UAAW,WAAU,MAAM;AAAA,cAC7C,UAAS,MAAM;AAAA,QACtB;AAAA,QAEC;AAAA;AAAA,IACH,GACF;AAAA,IACC,kBAAkB,CAAC,aAClB;AAAA,MAAC;AAAA;AAAA,QACC,MAAM,WAAW;AAAA,QACjB,cAAc,CAAC,SAAS;AACtB,cAAI,CAAC,KAAM,WAAU,IAAI;AAAA,QAC3B;AAAA,QACA,WAAW,MAAM;AACf,cAAI,OAAQ,UAAS,MAAM;AAAA,QAC7B;AAAA,QACA,QAAQ;AAAA;AAAA,IACV;AAAA,KAEJ;AAEJ;AAuBO,SAAS,oBAAoB,EAAE,MAAM,cAAc,WAAW,QAAQ,WAAW,GAA6B;AACnH,QAAM,SAAS,iBAAiB,UAAU;AAC1C,QAAM,SAAS,aAAa,UAAU,qBAAqB;AAC3D,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO,OAAO;AAAA,MACd,aAAa,OAAO;AAAA,MACpB,SAAS,MAAM,aAAa,KAAK;AAAA,MACjC,sBAAmB;AAAA,MACnB,SAAS,CAAC,UACR,iCACE;AAAA,4BAAC,UAAO,SAAQ,aAAY,SAAS,OAClC,iBAAO,MACV;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,SAAQ;AAAA,YACR,SAAS,MAAM;AACb,wBAAU;AACV,2BAAa,KAAK;AAAA,YACpB;AAAA,YAEC,iBAAO;AAAA;AAAA,QACV;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
@@ -51,6 +51,15 @@ export interface PlanSwitchConfirmProps {
51
51
  onConfirm: () => void;
52
52
  /** The figures' and the date's locale. Default: the provider's. */
53
53
  locale?: string;
54
+ /**
55
+ * 0.42 (§16.2 decision 5, §16.8 B): the payer's free grant runs without an end —
56
+ * `isPermanentGrant(overview)`. The switch changes the PAID plan, not the applied one
57
+ * (§12.11), so the dialog says so above its figures (`grantWarningTitle`,
58
+ * `grantWarningBody`) before the payer agrees. Confirm stays Confirm: the warning is
59
+ * this dialog's own, and `PlanPicker` — told `switching` — shows none of its own on
60
+ * the way here, so the payer reads it once.
61
+ */
62
+ permanentGrant?: boolean;
54
63
  /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */
55
64
  labels?: LabelOverride<BillingLabels>;
56
65
  }
@@ -76,4 +85,4 @@ export interface PlanSwitchConfirmProps {
76
85
  * change plan, as they may pay. A demo lock still holds it, as the server's demo guard
77
86
  * does. The kit sends no request.
78
87
  */
79
- export declare function PlanSwitchConfirm({ open, onOpenChange, from, to, preview, pending, planName, dimensionLabels, formatLimit, onConfirm, locale: localeProp, labels: labelsProp, }: PlanSwitchConfirmProps): import("react").JSX.Element;
88
+ export declare function PlanSwitchConfirm({ open, onOpenChange, from, to, preview, pending, planName, dimensionLabels, formatLimit, onConfirm, locale: localeProp, permanentGrant, labels: labelsProp, }: PlanSwitchConfirmProps): import("react").JSX.Element;
@@ -4,6 +4,7 @@ import { useKitLabels, useKitLocale } from "../i18n/kit-labels.js";
4
4
  import { DEFAULT_COMMON_LABELS } from "../i18n/shared-labels.js";
5
5
  import { pluralForm } from "../i18n/plurals.js";
6
6
  import { formatDate, formatMoney, formatNumber } from "../lib/format.js";
7
+ import { AlertBanner } from "../components/alert-banner.js";
7
8
  import { Button } from "../components/button.js";
8
9
  import { DialogFrame } from "../components/dialog-frame.js";
9
10
  import { Spinner } from "../components/spinner.js";
@@ -23,6 +24,7 @@ function PlanSwitchConfirm({
23
24
  formatLimit,
24
25
  onConfirm,
25
26
  locale: localeProp,
27
+ permanentGrant = false,
26
28
  labels: labelsProp
27
29
  }) {
28
30
  const labels = useBillingLabels(labelsProp);
@@ -44,7 +46,7 @@ function PlanSwitchConfirm({
44
46
  });
45
47
  const credit = preview !== void 0 && preview.now_minor < 0;
46
48
  const lines = preview ? overLimit(preview) : [];
47
- return /* @__PURE__ */ jsx(
49
+ return /* @__PURE__ */ jsxs(
48
50
  DialogFrame,
49
51
  {
50
52
  open,
@@ -70,20 +72,27 @@ function PlanSwitchConfirm({
70
72
  }
71
73
  )
72
74
  ] }),
73
- children: preview === void 0 ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-4", children: /* @__PURE__ */ jsx(Spinner, { showLabel: true }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
74
- /* @__PURE__ */ jsxs("dl", { className: "grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 text-sm", "data-plan-switch-preview": true, children: [
75
- /* @__PURE__ */ jsx("dt", { className: "text-secondary", children: credit ? labels.switchCredited : labels.switchChargedNow }),
76
- /* @__PURE__ */ jsx("dd", { className: "text-right font-medium tabular-nums", "data-now": credit ? "credit" : "charge", children: money(Math.abs(preview.now_minor), preview.currency) }),
77
- preview.next_billed_at && preview.next_minor != null && /* @__PURE__ */ jsxs(Fragment, { children: [
78
- /* @__PURE__ */ jsx("dt", { className: "text-secondary", children: labels.switchNextCharge(formatDate(preview.next_billed_at, "medium", { locale })) }),
79
- /* @__PURE__ */ jsx("dd", { className: "text-right tabular-nums", children: money(preview.next_minor, preview.currency) })
80
- ] })
75
+ children: [
76
+ permanentGrant && /* @__PURE__ */ jsxs(AlertBanner, { tone: "warning", size: "sm", "data-grant-warning": "", children: [
77
+ /* @__PURE__ */ jsx("strong", { className: "block font-medium", children: labels.grantWarningTitle }),
78
+ " ",
79
+ labels.grantWarningBody
81
80
  ] }),
82
- lines.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-sm", "data-plan-switch-over-limit": true, children: [
83
- /* @__PURE__ */ jsx("p", { children: planChange.overLimit }),
84
- /* @__PURE__ */ jsx("ul", { className: "list-disc space-y-0.5 ps-5 text-secondary", children: lines.map((line) => /* @__PURE__ */ jsx("li", { children: line }, line)) })
81
+ preview === void 0 ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-4", children: /* @__PURE__ */ jsx(Spinner, { showLabel: true }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
82
+ /* @__PURE__ */ jsxs("dl", { className: "grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 text-sm", "data-plan-switch-preview": true, children: [
83
+ /* @__PURE__ */ jsx("dt", { className: "text-secondary", children: credit ? labels.switchCredited : labels.switchChargedNow }),
84
+ /* @__PURE__ */ jsx("dd", { className: "text-right font-medium tabular-nums", "data-now": credit ? "credit" : "charge", children: money(Math.abs(preview.now_minor), preview.currency) }),
85
+ preview.next_billed_at && preview.next_minor != null && /* @__PURE__ */ jsxs(Fragment, { children: [
86
+ /* @__PURE__ */ jsx("dt", { className: "text-secondary", children: labels.switchNextCharge(formatDate(preview.next_billed_at, "medium", { locale })) }),
87
+ /* @__PURE__ */ jsx("dd", { className: "text-right tabular-nums", children: money(preview.next_minor, preview.currency) })
88
+ ] })
89
+ ] }),
90
+ lines.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-sm", "data-plan-switch-over-limit": true, children: [
91
+ /* @__PURE__ */ jsx("p", { children: planChange.overLimit }),
92
+ /* @__PURE__ */ jsx("ul", { className: "list-disc space-y-0.5 ps-5 text-secondary", children: lines.map((line) => /* @__PURE__ */ jsx("li", { children: line }, line)) })
93
+ ] })
85
94
  ] })
86
- ] })
95
+ ]
87
96
  }
88
97
  );
89
98
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/billing/plan-switch.tsx"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\n\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { DEFAULT_COMMON_LABELS } from \"../i18n/shared-labels\";\nimport { pluralForm } from \"../i18n/plurals\";\nimport type { PluralForms } from \"../i18n/plurals\";\nimport { formatDate, formatMoney, formatNumber } from \"../lib/format\";\nimport { Button } from \"../components/button\";\nimport { DialogFrame } from \"../components/dialog-frame\";\nimport { Spinner } from \"../components/spinner\";\nimport { COMMIT_EXCEPT_BILLING } from \"../components/write-lock\";\nimport { DEFAULT_PLAN_CHANGE_LABELS } from \"../admin/plan-change-labels\";\nimport { useBillingLabels } from \"./billing-labels\";\nimport type { BillingLabels } from \"./billing-labels\";\nimport type { PlanSwitchPreview } from \"./billing-overview\";\nimport { minorToMajor } from \"./plan-price\";\nimport type { BillingInterval } from \"./plan-price\";\n\n/**\n * The payer's plan switch (docs/billing-harmonization.md §15.2.10, ui-kit 0.39): built\n * once in the kits and used by all three apps, instead of Paddle's portal. While a\n * provider subscription runs, the app sends a `PlanPicker` pick to\n * `POST /billing/plan/preview` and opens this dialog with the answer; Confirm is the\n * app's `POST /billing/plan`. Otherwise the pick goes to the checkout, as before.\n *\n * The switch is immediate and prorated: an upgrade charges the difference now, a\n * downgrade credits the unused part to the customer's balance, which Paddle takes off\n * the next charges. So the payer agrees to a figure — Paddle's preview — and sees the\n * dimensions over the new plan's limit before agreeing (§3.4: a limit gates creation\n * only, so the switch is allowed).\n */\n\n/** One side of a switch: a plan code and its billing period. */\nexport interface PlanSwitchSide {\n plan: string;\n interval: BillingInterval;\n}\n\nexport interface PlanSwitchConfirmProps {\n open: boolean;\n /** `false` when the payer dismisses it — Cancel, Escape, the backdrop. Confirm leaves\n * it open: close it once the switch answers. */\n onOpenChange: (open: boolean) => void;\n /** What the payer pays now: the overview's `paid`. */\n from: PlanSwitchSide;\n /** The pick. */\n to: PlanSwitchSide;\n /** `POST /billing/plan/preview`'s answer. Undefined while it loads: a spinner, and\n * Confirm is held. */\n preview?: PlanSwitchPreview;\n /** `POST /billing/plan` is under way: Confirm's spinner, no second press, and Escape\n * doesn't close. */\n pending?: boolean;\n /** The plan's display name, the app's (§3.1). Default: the code. */\n planName?: (code: string) => string;\n /**\n * The app's word per dimension, for the over-limit lines. A heading's word (\"Budgets\")\n * reads \"Budgets: 7 of 5\" (`billing.limitUsageLine`); its plural forms\n * (`{ one: \"budget\", other: \"budgets\" }`) read \"7 of 5 budgets\" (`planChange.usageOf`,\n * the form the limit takes). A dimension without one is named by its key.\n */\n dimensionLabels?: Readonly<Record<string, string | PluralForms>>;\n /** How a usage or limit figure is written. Default: a number in the locale. */\n formatLimit?: (dimension: string, value: number) => string;\n /** Confirm: the app's `POST /billing/plan` with `{plan, interval}` of `to`. */\n onConfirm: () => void;\n /** The figures' and the date's locale. Default: the provider's. */\n locale?: string;\n /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */\n labels?: LabelOverride<BillingLabels>;\n}\n\n/**\n * The confirm for a plan switch (§15.2.10): from → to, each with its billing period;\n * Paddle's preview — \"Charged now\" (an upgrade) or \"Credited towards your next charges\"\n * (a downgrade), and the next charge with its date — in the subscription's currency;\n * the dimensions over the new plan's limit; and Confirm.\n *\n * const preview = useMutation({ mutationFn: api.previewPlanSwitch });\n * <PlanSwitchConfirm\n * open={pick !== null}\n * onOpenChange={(open) => !open && setPick(null)}\n * from={overview.paid}\n * to={pick}\n * preview={preview.data}\n * pending={switching.isPending}\n * planName={planName}\n * onConfirm={() => switching.mutate(pick)}\n * />\n *\n * It takes no billing lock (`COMMIT_EXCEPT_BILLING` built in): a read-only payer may\n * change plan, as they may pay. A demo lock still holds it, as the server's demo guard\n * does. The kit sends no request.\n */\nexport function PlanSwitchConfirm({\n open,\n onOpenChange,\n from,\n to,\n preview,\n pending = false,\n planName = (code) => code,\n dimensionLabels,\n formatLimit,\n onConfirm,\n locale: localeProp,\n labels: labelsProp,\n}: PlanSwitchConfirmProps) {\n const labels = useBillingLabels(labelsProp);\n const planChange = useKitLabels(\"planChange\", DEFAULT_PLAN_CHANGE_LABELS);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const locale = useKitLocale(localeProp);\n\n const period = (interval: BillingInterval) => (interval === \"year\" ? labels.yearly : labels.monthly);\n const side = (s: PlanSwitchSide) => `${planName(s.plan.toLowerCase())} (${period(s.interval)})`;\n const money = (minor: number, currency: string) =>\n formatMoney(minorToMajor(minor, currency), currency, { locale });\n const figure = (dimension: string, value: number) =>\n formatLimit ? formatLimit(dimension, value) : formatNumber(value, { locale });\n\n /** One line per dimension over the new limit, in the word's own sentence. */\n const overLimit = (p: PlanSwitchPreview): string[] =>\n (p.over_limit ?? []).flatMap((dimension) => {\n const limit = p.limits?.[dimension];\n const used = p.usage?.[dimension];\n if (limit === null || limit === undefined || used === undefined) return [];\n const word = dimensionLabels?.[dimension] ?? dimension;\n return [\n typeof word === \"string\"\n ? labels.limitUsageLine(word, figure(dimension, used), figure(dimension, limit))\n : planChange.usageOf(figure(dimension, used), figure(dimension, limit), pluralForm(limit, word, locale)),\n ];\n });\n\n const credit = preview !== undefined && preview.now_minor < 0;\n const lines = preview ? overLimit(preview) : [];\n\n return (\n <DialogFrame\n open={open}\n title={labels.switchTitle}\n description={labels.switchFromTo(side(from), side(to))}\n onClose={() => onOpenChange(false)}\n onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {\n if (pending && e.key === \"Escape\") e.preventDefault();\n }}\n aria-busy={preview === undefined || pending || undefined}\n actions={(close) => (\n <>\n <Button variant=\"secondary\" onClick={close} disabled={pending}>\n {common.cancel}\n </Button>\n <Button\n commit={COMMIT_EXCEPT_BILLING}\n pending={pending}\n disabled={preview === undefined}\n onClick={() => {\n if (preview !== undefined && !pending) onConfirm();\n }}\n >\n {labels.switchConfirm}\n </Button>\n </>\n )}\n >\n {preview === undefined ? (\n <div className=\"flex justify-center py-4\">\n <Spinner showLabel />\n </div>\n ) : (\n <>\n <dl className=\"grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 text-sm\" data-plan-switch-preview>\n <dt className=\"text-secondary\">{credit ? labels.switchCredited : labels.switchChargedNow}</dt>\n <dd className=\"text-right font-medium tabular-nums\" data-now={credit ? \"credit\" : \"charge\"}>\n {money(Math.abs(preview.now_minor), preview.currency)}\n </dd>\n {preview.next_billed_at && preview.next_minor != null && (\n <>\n <dt className=\"text-secondary\">\n {labels.switchNextCharge(formatDate(preview.next_billed_at, \"medium\", { locale }))}\n </dt>\n <dd className=\"text-right tabular-nums\">{money(preview.next_minor, preview.currency)}</dd>\n </>\n )}\n </dl>\n {lines.length > 0 && (\n <div className=\"space-y-1 text-sm\" data-plan-switch-over-limit>\n <p>{planChange.overLimit}</p>\n <ul className=\"list-disc space-y-0.5 ps-5 text-secondary\">\n {lines.map((line) => (\n <li key={line}>{line}</li>\n ))}\n </ul>\n </div>\n )}\n </>\n )}\n </DialogFrame>\n );\n}\n"],"mappings":";AAqJQ,mBACE,KADF;AAnJR,SAAS,cAAc,oBAAoB;AAE3C,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAE3B,SAAS,YAAY,aAAa,oBAAoB;AACtD,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAC3C,SAAS,wBAAwB;AAGjC,SAAS,oBAAoB;AA+EtB,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,WAAW,CAAC,SAAS;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,QAAQ;AACV,GAA2B;AACzB,QAAM,SAAS,iBAAiB,UAAU;AAC1C,QAAM,aAAa,aAAa,cAAc,0BAA0B;AACxE,QAAM,SAAS,aAAa,UAAU,qBAAqB;AAC3D,QAAM,SAAS,aAAa,UAAU;AAEtC,QAAM,SAAS,CAAC,aAA+B,aAAa,SAAS,OAAO,SAAS,OAAO;AAC5F,QAAM,OAAO,CAAC,MAAsB,GAAG,SAAS,EAAE,KAAK,YAAY,CAAC,CAAC,KAAK,OAAO,EAAE,QAAQ,CAAC;AAC5F,QAAM,QAAQ,CAAC,OAAe,aAC5B,YAAY,aA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,kBAAI,YAAY,UAAa,CAAC,QAAS,WAAU;AAAA,YACnD;AAAA,YAEC,iBAAO;AAAA;AAAA,QACV;AAAA,SACF;AAAA,MAGD,sBAAY,SACX,oBAAC,SAAI,WAAU,4BACb,8BAAC,WAAQ,WAAS,MAAC,GACrB,IAEA,iCACE;AAAA,6BAAC,QAAG,WAAU,+DAA8D,4BAAwB,MAClG;AAAA,8BAAC,QAAG,WAAU,kBAAkB,mBAAS,OAAO,iBAAiB,OAAO,kBAAiB;AAAA,UACzF,oBAAC,QAAG,WAAU,uCAAsC,YAAU,SAAS,WAAW,UAC/E,gBAAM,KAAK,IAAI,QAAQ,SAAS,GAAG,QAAQ,QAAQ,GACtD;AAAA,UACC,QAAQ,kBAAkB,QAAQ,cAAc,QAC/C,iCACE;AAAA,gCAAC,QAAG,WAAU,kBACX,iBAAO,iBAAiB,WAAW,QAAQ,gBAAgB,UAAU,EAAE,OAAO,CAAC,CAAC,GACnF;AAAA,YACA,oBAAC,QAAG,WAAU,2BAA2B,gBAAM,QAAQ,YAAY,QAAQ,QAAQ,GAAE;AAAA,aACvF;AAAA,WAEJ;AAAA,QACC,MAAM,SAAS,KACd,qBAAC,SAAI,WAAU,qBAAoB,+BAA2B,MAC5D;AAAA,8BAAC,OAAG,qBAAW,WAAU;AAAA,UACzB,oBAAC,QAAG,WAAU,6CACX,gBAAM,IAAI,CAAC,SACV,oBAAC,QAAe,kBAAP,IAAY,CACtB,GACH;AAAA,WACF;AAAA,SAEJ;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/billing/plan-switch.tsx"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\n\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { DEFAULT_COMMON_LABELS } from \"../i18n/shared-labels\";\nimport { pluralForm } from \"../i18n/plurals\";\nimport type { PluralForms } from \"../i18n/plurals\";\nimport { formatDate, formatMoney, formatNumber } from \"../lib/format\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { Button } from \"../components/button\";\nimport { DialogFrame } from \"../components/dialog-frame\";\nimport { Spinner } from \"../components/spinner\";\nimport { COMMIT_EXCEPT_BILLING } from \"../components/write-lock\";\nimport { DEFAULT_PLAN_CHANGE_LABELS } from \"../admin/plan-change-labels\";\nimport { useBillingLabels } from \"./billing-labels\";\nimport type { BillingLabels } from \"./billing-labels\";\nimport type { PlanSwitchPreview } from \"./billing-overview\";\nimport { minorToMajor } from \"./plan-price\";\nimport type { BillingInterval } from \"./plan-price\";\n\n/**\n * The payer's plan switch (docs/billing-harmonization.md §15.2.10, ui-kit 0.39): built\n * once in the kits and used by all three apps, instead of Paddle's portal. While a\n * provider subscription runs, the app sends a `PlanPicker` pick to\n * `POST /billing/plan/preview` and opens this dialog with the answer; Confirm is the\n * app's `POST /billing/plan`. Otherwise the pick goes to the checkout, as before.\n *\n * The switch is immediate and prorated: an upgrade charges the difference now, a\n * downgrade credits the unused part to the customer's balance, which Paddle takes off\n * the next charges. So the payer agrees to a figure — Paddle's preview — and sees the\n * dimensions over the new plan's limit before agreeing (§3.4: a limit gates creation\n * only, so the switch is allowed).\n */\n\n/** One side of a switch: a plan code and its billing period. */\nexport interface PlanSwitchSide {\n plan: string;\n interval: BillingInterval;\n}\n\nexport interface PlanSwitchConfirmProps {\n open: boolean;\n /** `false` when the payer dismisses it — Cancel, Escape, the backdrop. Confirm leaves\n * it open: close it once the switch answers. */\n onOpenChange: (open: boolean) => void;\n /** What the payer pays now: the overview's `paid`. */\n from: PlanSwitchSide;\n /** The pick. */\n to: PlanSwitchSide;\n /** `POST /billing/plan/preview`'s answer. Undefined while it loads: a spinner, and\n * Confirm is held. */\n preview?: PlanSwitchPreview;\n /** `POST /billing/plan` is under way: Confirm's spinner, no second press, and Escape\n * doesn't close. */\n pending?: boolean;\n /** The plan's display name, the app's (§3.1). Default: the code. */\n planName?: (code: string) => string;\n /**\n * The app's word per dimension, for the over-limit lines. A heading's word (\"Budgets\")\n * reads \"Budgets: 7 of 5\" (`billing.limitUsageLine`); its plural forms\n * (`{ one: \"budget\", other: \"budgets\" }`) read \"7 of 5 budgets\" (`planChange.usageOf`,\n * the form the limit takes). A dimension without one is named by its key.\n */\n dimensionLabels?: Readonly<Record<string, string | PluralForms>>;\n /** How a usage or limit figure is written. Default: a number in the locale. */\n formatLimit?: (dimension: string, value: number) => string;\n /** Confirm: the app's `POST /billing/plan` with `{plan, interval}` of `to`. */\n onConfirm: () => void;\n /** The figures' and the date's locale. Default: the provider's. */\n locale?: string;\n /**\n * 0.42 (§16.2 decision 5, §16.8 B): the payer's free grant runs without an end —\n * `isPermanentGrant(overview)`. The switch changes the PAID plan, not the applied one\n * (§12.11), so the dialog says so above its figures (`grantWarningTitle`,\n * `grantWarningBody`) before the payer agrees. Confirm stays Confirm: the warning is\n * this dialog's own, and `PlanPicker` — told `switching` — shows none of its own on\n * the way here, so the payer reads it once.\n */\n permanentGrant?: boolean;\n /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */\n labels?: LabelOverride<BillingLabels>;\n}\n\n/**\n * The confirm for a plan switch (§15.2.10): from → to, each with its billing period;\n * Paddle's preview — \"Charged now\" (an upgrade) or \"Credited towards your next charges\"\n * (a downgrade), and the next charge with its date — in the subscription's currency;\n * the dimensions over the new plan's limit; and Confirm.\n *\n * const preview = useMutation({ mutationFn: api.previewPlanSwitch });\n * <PlanSwitchConfirm\n * open={pick !== null}\n * onOpenChange={(open) => !open && setPick(null)}\n * from={overview.paid}\n * to={pick}\n * preview={preview.data}\n * pending={switching.isPending}\n * planName={planName}\n * onConfirm={() => switching.mutate(pick)}\n * />\n *\n * It takes no billing lock (`COMMIT_EXCEPT_BILLING` built in): a read-only payer may\n * change plan, as they may pay. A demo lock still holds it, as the server's demo guard\n * does. The kit sends no request.\n */\nexport function PlanSwitchConfirm({\n open,\n onOpenChange,\n from,\n to,\n preview,\n pending = false,\n planName = (code) => code,\n dimensionLabels,\n formatLimit,\n onConfirm,\n locale: localeProp,\n permanentGrant = false,\n labels: labelsProp,\n}: PlanSwitchConfirmProps) {\n const labels = useBillingLabels(labelsProp);\n const planChange = useKitLabels(\"planChange\", DEFAULT_PLAN_CHANGE_LABELS);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const locale = useKitLocale(localeProp);\n\n const period = (interval: BillingInterval) => (interval === \"year\" ? labels.yearly : labels.monthly);\n const side = (s: PlanSwitchSide) => `${planName(s.plan.toLowerCase())} (${period(s.interval)})`;\n const money = (minor: number, currency: string) =>\n formatMoney(minorToMajor(minor, currency), currency, { locale });\n const figure = (dimension: string, value: number) =>\n formatLimit ? formatLimit(dimension, value) : formatNumber(value, { locale });\n\n /** One line per dimension over the new limit, in the word's own sentence. */\n const overLimit = (p: PlanSwitchPreview): string[] =>\n (p.over_limit ?? []).flatMap((dimension) => {\n const limit = p.limits?.[dimension];\n const used = p.usage?.[dimension];\n if (limit === null || limit === undefined || used === undefined) return [];\n const word = dimensionLabels?.[dimension] ?? dimension;\n return [\n typeof word === \"string\"\n ? labels.limitUsageLine(word, figure(dimension, used), figure(dimension, limit))\n : planChange.usageOf(figure(dimension, used), figure(dimension, limit), pluralForm(limit, word, locale)),\n ];\n });\n\n const credit = preview !== undefined && preview.now_minor < 0;\n const lines = preview ? overLimit(preview) : [];\n\n return (\n <DialogFrame\n open={open}\n title={labels.switchTitle}\n description={labels.switchFromTo(side(from), side(to))}\n onClose={() => onOpenChange(false)}\n onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {\n if (pending && e.key === \"Escape\") e.preventDefault();\n }}\n aria-busy={preview === undefined || pending || undefined}\n actions={(close) => (\n <>\n <Button variant=\"secondary\" onClick={close} disabled={pending}>\n {common.cancel}\n </Button>\n <Button\n commit={COMMIT_EXCEPT_BILLING}\n pending={pending}\n disabled={preview === undefined}\n onClick={() => {\n if (preview !== undefined && !pending) onConfirm();\n }}\n >\n {labels.switchConfirm}\n </Button>\n </>\n )}\n >\n {permanentGrant && (\n <AlertBanner tone=\"warning\" size=\"sm\" data-grant-warning=\"\">\n <strong className=\"block font-medium\">{labels.grantWarningTitle}</strong> {labels.grantWarningBody}\n </AlertBanner>\n )}\n {preview === undefined ? (\n <div className=\"flex justify-center py-4\">\n <Spinner showLabel />\n </div>\n ) : (\n <>\n <dl className=\"grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 text-sm\" data-plan-switch-preview>\n <dt className=\"text-secondary\">{credit ? labels.switchCredited : labels.switchChargedNow}</dt>\n <dd className=\"text-right font-medium tabular-nums\" data-now={credit ? \"credit\" : \"charge\"}>\n {money(Math.abs(preview.now_minor), preview.currency)}\n </dd>\n {preview.next_billed_at && preview.next_minor != null && (\n <>\n <dt className=\"text-secondary\">\n {labels.switchNextCharge(formatDate(preview.next_billed_at, \"medium\", { locale }))}\n </dt>\n <dd className=\"text-right tabular-nums\">{money(preview.next_minor, preview.currency)}</dd>\n </>\n )}\n </dl>\n {lines.length > 0 && (\n <div className=\"space-y-1 text-sm\" data-plan-switch-over-limit>\n <p>{planChange.overLimit}</p>\n <ul className=\"list-disc space-y-0.5 ps-5 text-secondary\">\n {lines.map((line) => (\n <li key={line}>{line}</li>\n ))}\n </ul>\n </div>\n )}\n </>\n )}\n </DialogFrame>\n );\n}\n"],"mappings":";AAgKQ,mBACE,KADF;AA9JR,SAAS,cAAc,oBAAoB;AAE3C,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAE3B,SAAS,YAAY,aAAa,oBAAoB;AACtD,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAC3C,SAAS,wBAAwB;AAGjC,SAAS,oBAAoB;AAwFtB,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,WAAW,CAAC,SAAS;AAAA,E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,WAAU,2BAA2B,gBAAM,QAAQ,YAAY,QAAQ,QAAQ,GAAE;AAAA,eACvF;AAAA,aAEJ;AAAA,UACC,MAAM,SAAS,KACd,qBAAC,SAAI,WAAU,qBAAoB,+BAA2B,MAC5D;AAAA,gCAAC,OAAG,qBAAW,WAAU;AAAA,YACzB,oBAAC,QAAG,WAAU,6CACX,gBAAM,IAAI,CAAC,SACV,oBAAC,QAAe,kBAAP,IAAY,CACtB,GACH;AAAA,aACF;AAAA,WAEJ;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import type { ComponentPropsWithRef } from "react";
2
2
  import type { LabelOverride } from "../i18n/kit-labels.js";
3
3
  import type { BillingLabels } from "./billing-labels.js";
4
- import type { PortalTarget } from "./billing-overview.js";
4
+ import type { BillingPortalAccess, PortalTarget } from "./billing-overview.js";
5
5
  export interface SubscriptionActionsProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
6
6
  /** "Payment and invoices", as a link — or {@link onManage}. Without either, none. */
7
7
  manageHref?: string;
@@ -30,8 +30,35 @@ export interface SubscriptionActionsProps extends Omit<ComponentPropsWithRef<"di
30
30
  * (§12.26). Default true (0.32's behaviour).
31
31
  */
32
32
  atProvider?: boolean;
33
- /** Which of the two is under way: its spinner, no second press. */
34
- pending?: "manage" | "cancel" | null;
33
+ /**
34
+ * 0.42 (§16.2, server-kit 0.14): the overview's `portal`. `"buyer_only"` — the row has
35
+ * a buyer and the viewer isn't them, so the portal would answer `403
36
+ * billing_portal_buyer_only`: "Payment and invoices" becomes a caption naming the buyer
37
+ * (`buyerHolds`, no button), and "Cancel subscription" calls {@link onCancelInApp}
38
+ * (no portal at all — `cancelHref`, `onCancel` and `onPortal` are not used). `"open"`
39
+ * (default): as before.
40
+ */
41
+ portal?: BillingPortalAccess;
42
+ /** 0.42: the overview's `buyer_name`, for the caption under `"buyer_only"`. Empty: "…with
43
+ * the admin who bought the subscription". */
44
+ buyerName?: string | null;
45
+ /**
46
+ * 0.42 (§16.2 decision 2): "Cancel subscription" in the app — open
47
+ * `CancelSubscriptionConfirm`, whose Confirm is `POST /billing/cancel`. The cancel under
48
+ * `"buyer_only"`. Under `"open"` it is the last resort, used only when no portal cancel
49
+ * (`cancelHref`, `onCancel`, `onPortal`) is given — a person-payer app that mounts the
50
+ * route and not the portal's cancel.
51
+ */
52
+ onCancelInApp?: () => void;
53
+ /** 0.42 (§16.7 C): the overview's `cancel_at_period_end` — a cancel is scheduled. With
54
+ * {@link onResume}, "Keep subscription" takes the cancel's place. */
55
+ cancelAtPeriodEnd?: boolean;
56
+ /** 0.42 (§16.7 C): "Keep subscription", the app's `POST /billing/resume` — shown in
57
+ * the cancel's place while {@link cancelAtPeriodEnd} is true. Without it, the cancel
58
+ * stays as before. */
59
+ onResume?: () => void;
60
+ /** Which one is under way: its spinner, no second press. `"resume"` since 0.42. */
61
+ pending?: "manage" | "cancel" | "resume" | null;
35
62
  /** Prop > `<UiKitProvider labels={{ billing }}>` > English. */
36
63
  labels?: LabelOverride<BillingLabels>;
37
64
  }
@@ -50,5 +77,11 @@ export interface SubscriptionActionsProps extends Omit<ComponentPropsWithRef<"di
50
77
  * Before the payer has reached the provider (`atProvider={false}`, a trial without a
51
78
  * card, a beta) there is no portal to open: the part says so in a caption instead of
52
79
  * offering two buttons that could only end in `409 billing_not_at_provider`.
80
+ *
81
+ * 0.42 (§16): where the company's buyer is another admin (`portal="buyer_only"`), the
82
+ * portal stays the buyer's — "Payment and invoices" is a caption that names them, and
83
+ * "Cancel subscription" is the in-app cancel (`onCancelInApp`). While a cancel is
84
+ * scheduled (`cancelAtPeriodEnd`) and `onResume` is given, "Keep subscription" stands in
85
+ * the cancel's place, whoever the viewer is.
53
86
  */
54
- export declare function SubscriptionActions({ manageHref, onManage, cancelHref, onCancel, onPortal, atProvider, pending, labels: labelsProp, className, ...rest }: SubscriptionActionsProps): import("react").JSX.Element | null;
87
+ export declare function SubscriptionActions({ manageHref, onManage, cancelHref, onCancel, onPortal, atProvider, portal, buyerName, onCancelInApp, cancelAtPeriodEnd, onResume, pending, labels: labelsProp, className, ...rest }: SubscriptionActionsProps): import("react").JSX.Element | null;
@@ -10,6 +10,11 @@ function SubscriptionActions({
10
10
  onCancel,
11
11
  onPortal,
12
12
  atProvider = true,
13
+ portal = "open",
14
+ buyerName,
15
+ onCancelInApp,
16
+ cancelAtPeriodEnd = false,
17
+ onResume,
13
18
  pending,
14
19
  labels: labelsProp,
15
20
  className,
@@ -19,10 +24,12 @@ function SubscriptionActions({
19
24
  if (!atProvider) {
20
25
  return /* @__PURE__ */ jsx("div", { ...rest, "data-at-provider": "false", className: cn("text-sm text-muted", className), children: /* @__PURE__ */ jsx("p", { children: labels.notAtProvider }) });
21
26
  }
27
+ const buyerOnly = portal === "buyer_only";
22
28
  const manageCall = onManage ?? (onPortal ? () => onPortal("overview") : void 0);
23
- const cancelCall = onCancel ?? (onPortal ? () => onPortal("cancel") : void 0);
24
- const manage = manageHref !== void 0 ? /* @__PURE__ */ jsx(Button, { href: manageHref, variant: "secondary", children: labels.manage }) : manageCall !== void 0 ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: manageCall, pending: pending === "manage", children: labels.manage }) : null;
25
- const cancel = cancelHref !== void 0 ? /* @__PURE__ */ jsx(Button, { href: cancelHref, variant: "link", tone: "danger", children: labels.cancel }) : cancelCall !== void 0 ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "link", tone: "danger", onClick: cancelCall, pending: pending === "cancel", children: labels.cancel }) : null;
29
+ const portalCancel = onCancel ?? (onPortal ? () => onPortal("cancel") : void 0);
30
+ const cancelCall = buyerOnly ? onCancelInApp : portalCancel ?? (cancelHref === void 0 ? onCancelInApp : void 0);
31
+ const manage = buyerOnly ? /* @__PURE__ */ jsx("p", { className: "basis-full text-sm text-muted", "data-buyer-holds": "", children: labels.buyerHolds(buyerName || void 0) }) : manageHref !== void 0 ? /* @__PURE__ */ jsx(Button, { href: manageHref, variant: "secondary", children: labels.manage }) : manageCall !== void 0 ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: manageCall, pending: pending === "manage", children: labels.manage }) : null;
32
+ const cancel = cancelAtPeriodEnd && onResume !== void 0 ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "link", onClick: onResume, pending: pending === "resume", "data-keep-subscription": "", children: labels.keepSubscription }) : cancelHref !== void 0 && !buyerOnly ? /* @__PURE__ */ jsx(Button, { href: cancelHref, variant: "link", tone: "danger", children: labels.cancel }) : cancelCall !== void 0 ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "link", tone: "danger", onClick: cancelCall, pending: pending === "cancel", children: labels.cancel }) : null;
26
33
  if (!manage && !cancel) return null;
27
34
  return /* @__PURE__ */ jsxs("div", { ...rest, className: cn("flex flex-wrap items-center gap-x-4 gap-y-2", className), children: [
28
35
  manage,