@openrails/billing-ui 0.273.0 → 0.274.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 (160) hide show
  1. package/dist/admin/components/customer-search.d.ts +5 -0
  2. package/dist/admin/components/missing-record.d.ts +6 -0
  3. package/dist/admin/components/status-badge.d.ts +1 -0
  4. package/dist/admin/context.d.ts +20 -2
  5. package/dist/admin/lib/api/endpoints.d.ts +3 -1
  6. package/dist/admin/lib/api/index.d.ts +2 -0
  7. package/dist/admin/lib/api/types.d.ts +2 -0
  8. package/dist/admin/lib/capabilities.d.ts +4 -0
  9. package/dist/admin/lib/dialog-width.d.ts +4 -3
  10. package/dist/admin/lib/error-text.d.ts +4 -0
  11. package/dist/admin/lib/mutations.d.ts +6 -1
  12. package/dist/admin/lib/queries.d.ts +3 -0
  13. package/dist/admin/lib/tile-grids.d.ts +6 -0
  14. package/dist/admin/messages.d.ts +89 -0
  15. package/dist/admin/pages/payments/index.d.ts +1 -2
  16. package/dist/admin/pages/subscriptions/index.d.ts +1 -2
  17. package/dist/{admin-attempts-DyDDt-qw.js → admin-attempts-Dzipkstg.js} +145 -144
  18. package/dist/admin-attempts-Dzipkstg.js.map +1 -0
  19. package/dist/{admin-auth-1aZIgXiS.js → admin-auth-BCl_Tv3t.js} +2 -2
  20. package/dist/{admin-auth-1aZIgXiS.js.map → admin-auth-BCl_Tv3t.js.map} +1 -1
  21. package/dist/{admin-badge-pgG6D9-a.js → admin-badge-kmYQM9Ge.js} +2 -2
  22. package/dist/{admin-badge-pgG6D9-a.js.map → admin-badge-kmYQM9Ge.js.map} +1 -1
  23. package/dist/{admin-button-CrcYk5r0.js → admin-button-Cq9ZfX4R.js} +2 -2
  24. package/dist/{admin-button-CrcYk5r0.js.map → admin-button-Cq9ZfX4R.js.map} +1 -1
  25. package/dist/{admin-capabilities-BDcZeHL_.js → admin-capabilities-k5fQZhN9.js} +35 -14
  26. package/dist/admin-capabilities-k5fQZhN9.js.map +1 -0
  27. package/dist/{admin-card-DvTMc5Se.js → admin-card-C8k67jJv.js} +2 -2
  28. package/dist/{admin-card-DvTMc5Se.js.map → admin-card-C8k67jJv.js.map} +1 -1
  29. package/dist/{admin-catalog-BlF5mnu4.js → admin-catalog-CON-GwKL.js} +286 -286
  30. package/dist/{admin-catalog-BlF5mnu4.js.map → admin-catalog-CON-GwKL.js.map} +1 -1
  31. package/dist/{admin-cursor-pager-CIb3Jw2F.js → admin-cursor-pager-DqFruoNu.js} +6 -6
  32. package/dist/{admin-cursor-pager-CIb3Jw2F.js.map → admin-cursor-pager-DqFruoNu.js.map} +1 -1
  33. package/dist/admin-customer-search-CJHB80rg.js +117 -0
  34. package/dist/admin-customer-search-CJHB80rg.js.map +1 -0
  35. package/dist/{admin-customers-EpfoWDh-.js → admin-customers-CWWOrcVR.js} +18 -17
  36. package/dist/{admin-customers-EpfoWDh-.js.map → admin-customers-CWWOrcVR.js.map} +1 -1
  37. package/dist/admin-dashboard-BiShWFk2.js +456 -0
  38. package/dist/admin-dashboard-BiShWFk2.js.map +1 -0
  39. package/dist/admin-data-table-CdsjYJh5.js +107 -0
  40. package/dist/admin-data-table-CdsjYJh5.js.map +1 -0
  41. package/dist/admin-detail-BWSC1aCH.js +338 -0
  42. package/dist/admin-detail-BWSC1aCH.js.map +1 -0
  43. package/dist/admin-detail-CKRtK43V.js +728 -0
  44. package/dist/admin-detail-CKRtK43V.js.map +1 -0
  45. package/dist/admin-detail-CMmhZQ2A.js +346 -0
  46. package/dist/admin-detail-CMmhZQ2A.js.map +1 -0
  47. package/dist/admin-detail-CiONe1Pt.js +1357 -0
  48. package/dist/admin-detail-CiONe1Pt.js.map +1 -0
  49. package/dist/{admin-detail-3wFIDPNB.js → admin-detail-Cyuf_i9U.js} +62 -62
  50. package/dist/{admin-detail-3wFIDPNB.js.map → admin-detail-Cyuf_i9U.js.map} +1 -1
  51. package/dist/{admin-dialog-BSRf9Zre.js → admin-dialog-Ch7rTOCr.js} +3 -3
  52. package/dist/{admin-dialog-BSRf9Zre.js.map → admin-dialog-Ch7rTOCr.js.map} +1 -1
  53. package/dist/admin-dialog-width-CC7QHT1p.js +6 -0
  54. package/dist/admin-dialog-width-CC7QHT1p.js.map +1 -0
  55. package/dist/{admin-dropdown-menu-D0E5rwmn.js → admin-dropdown-menu-Bah3f8AZ.js} +2 -2
  56. package/dist/{admin-dropdown-menu-D0E5rwmn.js.map → admin-dropdown-menu-Bah3f8AZ.js.map} +1 -1
  57. package/dist/{admin-fact-card-BPSVhS15.js → admin-fact-card-Bt__Cd_U.js} +2 -2
  58. package/dist/{admin-fact-card-BPSVhS15.js.map → admin-fact-card-Bt__Cd_U.js.map} +1 -1
  59. package/dist/{admin-health-D0L5Kig7.js → admin-health-pzTO6_0v.js} +249 -248
  60. package/dist/admin-health-pzTO6_0v.js.map +1 -0
  61. package/dist/{admin-imports-CgZB5JAV.js → admin-imports-tT5et8-V.js} +62 -62
  62. package/dist/{admin-imports-CgZB5JAV.js.map → admin-imports-tT5et8-V.js.map} +1 -1
  63. package/dist/{admin-input-DJAK9nmk.js → admin-input-DvRZy_2a.js} +2 -2
  64. package/dist/{admin-input-DJAK9nmk.js.map → admin-input-DvRZy_2a.js.map} +1 -1
  65. package/dist/{admin-label-aviN9Gng.js → admin-label-QZtWJGH-.js} +2 -2
  66. package/dist/{admin-label-aviN9Gng.js.map → admin-label-QZtWJGH-.js.map} +1 -1
  67. package/dist/{admin-linked-table-row-BGr7JXeM.js → admin-linked-table-row-6jkCKwMn.js} +4 -4
  68. package/dist/{admin-linked-table-row-BGr7JXeM.js.map → admin-linked-table-row-6jkCKwMn.js.map} +1 -1
  69. package/dist/{admin-map-dialog-DS2Wz6G3.js → admin-map-dialog-BV54mvMQ.js} +22 -22
  70. package/dist/{admin-map-dialog-DS2Wz6G3.js.map → admin-map-dialog-BV54mvMQ.js.map} +1 -1
  71. package/dist/{admin-metering-D-e-37Jn.js → admin-metering-Bv5EcX6M.js} +306 -306
  72. package/dist/{admin-metering-D-e-37Jn.js.map → admin-metering-Bv5EcX6M.js.map} +1 -1
  73. package/dist/admin-missing-record-BXqGFDt3.js +42 -0
  74. package/dist/admin-missing-record-BXqGFDt3.js.map +1 -0
  75. package/dist/admin-ops-h3RjpcNu.js +356 -0
  76. package/dist/admin-ops-h3RjpcNu.js.map +1 -0
  77. package/dist/admin-orders-DYxPiuTl.js +192 -0
  78. package/dist/admin-orders-DYxPiuTl.js.map +1 -0
  79. package/dist/{admin-parked-B8xHkV2e.js → admin-parked-ClKA60d5.js} +51 -51
  80. package/dist/{admin-parked-B8xHkV2e.js.map → admin-parked-ClKA60d5.js.map} +1 -1
  81. package/dist/admin-payments-BlIuy3wL.js +220 -0
  82. package/dist/admin-payments-BlIuy3wL.js.map +1 -0
  83. package/dist/{admin-price-detail-CSI5oKdb.js → admin-price-detail-BjWYU5A-.js} +98 -98
  84. package/dist/{admin-price-detail-CSI5oKdb.js.map → admin-price-detail-BjWYU5A-.js.map} +1 -1
  85. package/dist/{admin-price-wizard-CBEcNGvP.js → admin-price-wizard-CTbkbmYc.js} +61 -61
  86. package/dist/{admin-price-wizard-CBEcNGvP.js.map → admin-price-wizard-CTbkbmYc.js.map} +1 -1
  87. package/dist/{admin-proposals-Cuj7tvaM.js → admin-proposals-Ci9Q8j7Y.js} +64 -64
  88. package/dist/{admin-proposals-Cuj7tvaM.js.map → admin-proposals-Ci9Q8j7Y.js.map} +1 -1
  89. package/dist/{admin-provider-prices-B6vwnVPi.js → admin-provider-prices-B6Ayq-eN.js} +66 -66
  90. package/dist/{admin-provider-prices-B6vwnVPi.js.map → admin-provider-prices-B6Ayq-eN.js.map} +1 -1
  91. package/dist/{admin-range-picker-De36L-AP.js → admin-range-picker-nfflPp21.js} +9 -9
  92. package/dist/{admin-range-picker-De36L-AP.js.map → admin-range-picker-nfflPp21.js.map} +1 -1
  93. package/dist/{admin-records-H0MlhEVY.js → admin-records-CrTCorWH.js} +43 -43
  94. package/dist/{admin-records-H0MlhEVY.js.map → admin-records-CrTCorWH.js.map} +1 -1
  95. package/dist/{admin-reports-BFGS_PWf.js → admin-reports-BO6wrvtw.js} +50 -50
  96. package/dist/{admin-reports-BFGS_PWf.js.map → admin-reports-BO6wrvtw.js.map} +1 -1
  97. package/dist/{admin-select-BUcEU5Rg.js → admin-select-DvfJ80Rg.js} +2 -2
  98. package/dist/{admin-select-BUcEU5Rg.js.map → admin-select-DvfJ80Rg.js.map} +1 -1
  99. package/dist/{admin-settings-DYC-c7mJ.js → admin-settings-BOoTzhyf.js} +332 -332
  100. package/dist/admin-settings-BOoTzhyf.js.map +1 -0
  101. package/dist/{admin-shared-lfIUEbPY.js → admin-shared-BbGT_qTo.js} +21 -21
  102. package/dist/{admin-shared-lfIUEbPY.js.map → admin-shared-BbGT_qTo.js.map} +1 -1
  103. package/dist/{admin-skeleton-B0yzYY_X.js → admin-skeleton-B2a4ScVE.js} +2 -2
  104. package/dist/{admin-skeleton-B0yzYY_X.js.map → admin-skeleton-B2a4ScVE.js.map} +1 -1
  105. package/dist/admin-status-badge-Bp6cssXY.js +51 -0
  106. package/dist/admin-status-badge-Bp6cssXY.js.map +1 -0
  107. package/dist/admin-subscriptions-D9JmoicC.js +275 -0
  108. package/dist/admin-subscriptions-D9JmoicC.js.map +1 -0
  109. package/dist/{admin-switch-DDorugaw.js → admin-switch-DBBxJRZP.js} +2 -2
  110. package/dist/{admin-switch-DDorugaw.js.map → admin-switch-DBBxJRZP.js.map} +1 -1
  111. package/dist/{admin-table-BU6Tie69.js → admin-table-CPDoVfK4.js} +2 -2
  112. package/dist/{admin-table-BU6Tie69.js.map → admin-table-CPDoVfK4.js.map} +1 -1
  113. package/dist/{admin-tabs-D5lqdVcC.js → admin-tabs-DDUv3kiu.js} +2 -2
  114. package/dist/{admin-tabs-D5lqdVcC.js.map → admin-tabs-DDUv3kiu.js.map} +1 -1
  115. package/dist/{admin-textarea-Dc6lnEub.js → admin-textarea-d3fu_waS.js} +2 -2
  116. package/dist/{admin-textarea-Dc6lnEub.js.map → admin-textarea-d3fu_waS.js.map} +1 -1
  117. package/dist/admin-tile-grids-CzGpidd9.js +6 -0
  118. package/dist/admin-tile-grids-CzGpidd9.js.map +1 -0
  119. package/dist/{admin-typed-confirm-dialog-Bk6XxmPb.js → admin-typed-confirm-dialog-BVklYjFo.js} +11 -11
  120. package/dist/{admin-typed-confirm-dialog-Bk6XxmPb.js.map → admin-typed-confirm-dialog-BVklYjFo.js.map} +1 -1
  121. package/dist/{admin-utils-B9eEBNsR.js → admin-utils-DTT53IpS.js} +266 -223
  122. package/dist/admin-utils-DTT53IpS.js.map +1 -0
  123. package/dist/{admin-widget-viz-8aukE3v_.js → admin-widget-viz-Exsqz3Dw.js} +165 -128
  124. package/dist/admin-widget-viz-Exsqz3Dw.js.map +1 -0
  125. package/dist/admin.css +1 -1
  126. package/dist/admin.js +531 -405
  127. package/dist/admin.js.map +1 -1
  128. package/dist/index.js +1 -1
  129. package/dist/styles.css +1 -1
  130. package/package.json +1 -1
  131. package/dist/admin-attempts-DyDDt-qw.js.map +0 -1
  132. package/dist/admin-capabilities-BDcZeHL_.js.map +0 -1
  133. package/dist/admin-dashboard-CJE63yz4.js +0 -420
  134. package/dist/admin-dashboard-CJE63yz4.js.map +0 -1
  135. package/dist/admin-data-table-hvFcJepL.js +0 -96
  136. package/dist/admin-data-table-hvFcJepL.js.map +0 -1
  137. package/dist/admin-detail-BRP6pL7t.js +0 -328
  138. package/dist/admin-detail-BRP6pL7t.js.map +0 -1
  139. package/dist/admin-detail-CRzFb_pa.js +0 -1331
  140. package/dist/admin-detail-CRzFb_pa.js.map +0 -1
  141. package/dist/admin-detail-QLxU8r-5.js +0 -344
  142. package/dist/admin-detail-QLxU8r-5.js.map +0 -1
  143. package/dist/admin-detail-pPC8Q9l-.js +0 -710
  144. package/dist/admin-detail-pPC8Q9l-.js.map +0 -1
  145. package/dist/admin-dialog-width-BPrgdYlj.js +0 -6
  146. package/dist/admin-dialog-width-BPrgdYlj.js.map +0 -1
  147. package/dist/admin-health-D0L5Kig7.js.map +0 -1
  148. package/dist/admin-ops-CQP4TzWM.js +0 -235
  149. package/dist/admin-ops-CQP4TzWM.js.map +0 -1
  150. package/dist/admin-orders-BJ7W5S8P.js +0 -192
  151. package/dist/admin-orders-BJ7W5S8P.js.map +0 -1
  152. package/dist/admin-payments-CzkzqYA1.js +0 -246
  153. package/dist/admin-payments-CzkzqYA1.js.map +0 -1
  154. package/dist/admin-settings-DYC-c7mJ.js.map +0 -1
  155. package/dist/admin-status-badge-0-K37EfN.js +0 -43
  156. package/dist/admin-status-badge-0-K37EfN.js.map +0 -1
  157. package/dist/admin-subscriptions-CvW-YFs0.js +0 -301
  158. package/dist/admin-subscriptions-CvW-YFs0.js.map +0 -1
  159. package/dist/admin-utils-B9eEBNsR.js.map +0 -1
  160. package/dist/admin-widget-viz-8aukE3v_.js.map +0 -1
@@ -0,0 +1,728 @@
1
+ import { E as e, O as t, c as n, p as r, r as i, s as a, w as o } from "./admin-utils-DTT53IpS.js";
2
+ import { t as s } from "./admin-button-Cq9ZfX4R.js";
3
+ import { t as c } from "./admin-input-DvRZy_2a.js";
4
+ import { a as l } from "./admin-capabilities-k5fQZhN9.js";
5
+ import { i as u, o as d, r as f, s as p, u as m } from "./admin-format-DoohJ7Fg.js";
6
+ import { t as h } from "./admin-badge-kmYQM9Ge.js";
7
+ import { t as g } from "./admin-status-badge-Bp6cssXY.js";
8
+ import { t as _ } from "./admin-form-field-errors-hbUMIriS.js";
9
+ import { a as v, i as y, n as b, r as x, t as S } from "./admin-select-DvfJ80Rg.js";
10
+ import { a as C, n as w, o as T, r as E, s as D, t as O } from "./admin-table-CPDoVfK4.js";
11
+ import { a as k, i as ee, n as te, o as ne, r as re, s as ie, t as ae } from "./admin-dialog-Ch7rTOCr.js";
12
+ import { t as A } from "./admin-label-QZtWJGH-.js";
13
+ import { i as oe, r as se } from "./admin-dialog-width-CC7QHT1p.js";
14
+ import { n as j } from "./admin-price-format-BVUpDoSC.js";
15
+ import { a as ce, o as le, r as ue, t as de } from "./admin-card-C8k67jJv.js";
16
+ import { t as M } from "./admin-fact-card-Bt__Cd_U.js";
17
+ import { t as N } from "./admin-tile-grids-CzGpidd9.js";
18
+ import { t as fe } from "./admin-dunning-B2zgtrOo.js";
19
+ import { t as pe } from "./admin-missing-record-BXqGFDt3.js";
20
+ import { t as P } from "./admin-typed-confirm-dialog-BVklYjFo.js";
21
+ import * as F from "react";
22
+ import { useMutation as I, useQuery as L, useQueryClient as R } from "@tanstack/react-query";
23
+ import { Fragment as z, jsx as B, jsxs as V } from "react/jsx-runtime";
24
+ import { HugeiconsIcon as H } from "@hugeicons/react";
25
+ import { ArrowLeft01Icon as me } from "@hugeicons/core-free-icons";
26
+ import { useForm as U, useStore as W } from "@tanstack/react-form";
27
+ //#region src/admin/pages/subscriptions/subscription-change-options.ts
28
+ function he(e) {
29
+ let t = e.price, n = `${p(t.unit_amount, t.currency)}${t.quantity ? " per seat" : ""}`;
30
+ return [
31
+ e.product.display_name,
32
+ e.direction,
33
+ `${n} ${j(t)}`,
34
+ t.key
35
+ ].join(" · ");
36
+ }
37
+ function ge(e, t) {
38
+ let n = e.quantity;
39
+ return n ? t !== null && t >= n.min && t <= n.max ? t : n.min : null;
40
+ }
41
+ function _e({ rail: e, status: t, collectionPolicy: n, scheduledChange: r }) {
42
+ if (t !== "active" && t !== "past_due") return "Only active or past-due subscriptions can change";
43
+ if (r && n !== "engine") return "Its provider already bills a scheduled change";
44
+ if (e === "ccbill") return "CCBill changes require customer self-service";
45
+ if (e === "solana") return "Solana changes require the customer's wallet signature";
46
+ }
47
+ function ve({ currentProduct: e, currentPrice: t, currentCurrency: n, products: r, prices: i, scheduledChange: a }) {
48
+ let o = e && t && (t.quantity || a) ? [{
49
+ direction: "current",
50
+ price: t,
51
+ product: e
52
+ }] : [], s = e?.tier_group?.trim(), c = n?.trim().toLowerCase();
53
+ if (!e || !s || !c || a?.source === "migration") return o;
54
+ let l = new Map(r.filter((t) => !t.archived && t.id !== e.id && t.tier_group?.trim() === s).map((e) => [e.id, e]));
55
+ return o.concat(i.flatMap((t) => {
56
+ let n = l.get(t.product_id);
57
+ return !n || t.archived || !t.billing_interval_hours || t.currency.trim().toLowerCase() !== c ? [] : [{
58
+ direction: n.tier_rank < e.tier_rank ? "downgrade" : "upgrade",
59
+ price: t,
60
+ product: n
61
+ }];
62
+ }).sort((e, t) => e.product.tier_rank - t.product.tier_rank || e.product.display_name.localeCompare(t.product.display_name) || e.price.id.localeCompare(t.price.id)));
63
+ }
64
+ //#endregion
65
+ //#region src/admin/pages/subscriptions/change-subscription-dialog.tsx
66
+ function G(e) {
67
+ let { selectedMerchant: t } = r();
68
+ return /* @__PURE__ */ B(K, { ...e }, `${t() ?? ""}:${e.subscriptionId}`);
69
+ }
70
+ function K({ subscriptionId: n, customerId: i, productId: a, priceId: l, quantity: u, currency: f, collectionPolicy: m, scheduledChange: g, rail: _, status: C }) {
71
+ let { toast: w, toastApiError: T, adminMutations: E, adminQueries: D } = r(), { id: O, text: se } = t(), [j, ce] = F.useState(!1), [le, ue] = F.useState(""), [de, M] = F.useState(""), [N, fe] = F.useState(""), [pe, P] = F.useState(""), z = F.useRef(/* @__PURE__ */ new Map()), H = F.useRef(0);
72
+ F.useEffect(() => () => {
73
+ H.current++;
74
+ }, []);
75
+ let me = R(), U = I(E.previewSubscriptionChange(n)), W = I(E.changeSubscription(me, n, i)), G = L({
76
+ ...D.allProducts({ errorAction: "Load subscription plans" }),
77
+ enabled: j
78
+ }), K = L({
79
+ ...D.allPrices({ errorAction: "Load subscription prices" }),
80
+ enabled: j
81
+ }), ye = G.data?.data ?? [], be = K.data?.data ?? [], xe = ye.find((e) => e.id === a), Se = be.find((e) => e.id === l), q = ve({
82
+ currentProduct: xe,
83
+ currentPrice: Se,
84
+ currentCurrency: f ?? Se?.currency,
85
+ products: ye,
86
+ prices: be,
87
+ scheduledChange: g
88
+ }), J = q.find((e) => e.price.id === le), Y = J?.price.quantity, X = Number(de), Ce = !Y || Number.isInteger(X) && X >= Y.min && X <= Y.max, Z = J && Ce ? {
89
+ price_id: J.price.id,
90
+ ...Y ? { quantity: X } : {}
91
+ } : void 0, we = J?.direction === "current" && !g && (!Y || X === u), Q = Z ? JSON.stringify(Z) : "", $ = Q && pe === Q ? U.data : void 0, Te = _e({
92
+ rail: _,
93
+ status: C,
94
+ collectionPolicy: m,
95
+ scheduledChange: g
96
+ }), Ee = (e) => {
97
+ H.current++, ce(e);
98
+ }, De = (e) => {
99
+ H.current++;
100
+ let t = q.find((t) => t.price.id === e)?.price;
101
+ ue(e ?? ""), M(String(t ? ge(t, u) ?? "" : "")), P(""), U.reset(), W.reset();
102
+ }, Oe = (e) => {
103
+ H.current++, M(e), P(""), U.reset(), W.reset();
104
+ }, ke = U.error instanceof Error ? U.error.message : "", Ae = W.error instanceof Error ? W.error.message : "", je = W.data?.message, Me = W.data?.next_action?.url ?? void 0;
105
+ return /* @__PURE__ */ V(ae, {
106
+ open: j,
107
+ onOpenChange: Ee,
108
+ children: [/* @__PURE__ */ B(ie, { render: /* @__PURE__ */ B(s, {
109
+ variant: "outline",
110
+ size: "sm",
111
+ disabled: !!Te && !W.variables,
112
+ title: Te,
113
+ children: /* @__PURE__ */ B(e, { id: "Change subscription" })
114
+ }) }), /* @__PURE__ */ V(te, {
115
+ className: oe,
116
+ children: [
117
+ /* @__PURE__ */ V(k, { children: [/* @__PURE__ */ B(ne, { children: /* @__PURE__ */ B(e, { id: "Change subscription" }) }), /* @__PURE__ */ B(re, { children: /* @__PURE__ */ B(e, { id: "Schedule the customer's plan or seats for the next renewal. No card is charged now. Choosing the current plan and seats clears a pending change. The customer is told." }) })] }),
118
+ /* @__PURE__ */ V("div", {
119
+ className: "grid gap-5",
120
+ children: [
121
+ /* @__PURE__ */ V("div", {
122
+ className: "grid gap-1.5",
123
+ children: [
124
+ /* @__PURE__ */ B(A, {
125
+ htmlFor: O("subscription-tier"),
126
+ children: /* @__PURE__ */ B(e, { id: "New plan" })
127
+ }),
128
+ /* @__PURE__ */ V(S, {
129
+ value: le,
130
+ onValueChange: De,
131
+ children: [/* @__PURE__ */ B(y, {
132
+ id: O("subscription-tier"),
133
+ className: "w-full",
134
+ disabled: G.isPending || K.isPending,
135
+ children: /* @__PURE__ */ B(v, { placeholder: G.isPending || K.isPending ? "Loading plans…" : "Choose a plan" })
136
+ }), /* @__PURE__ */ B(b, { children: q.map((e) => /* @__PURE__ */ B(x, {
137
+ value: e.price.id,
138
+ children: he(e)
139
+ }, e.price.id)) })]
140
+ }),
141
+ !G.isPending && !K.isPending && !G.isError && !K.isError && q.length === 0 && /* @__PURE__ */ B("p", {
142
+ className: "text-xs text-muted-foreground",
143
+ children: /* @__PURE__ */ B(e, { id: "No eligible recurring plans share this tier group and currency." })
144
+ }),
145
+ (G.isError || K.isError) && /* @__PURE__ */ B("p", {
146
+ className: "text-xs text-destructive",
147
+ role: "alert",
148
+ children: /* @__PURE__ */ B(e, { id: "Could not load the available plans." })
149
+ })
150
+ ]
151
+ }),
152
+ Y && /* @__PURE__ */ V("div", {
153
+ className: "grid gap-1.5",
154
+ children: [
155
+ /* @__PURE__ */ B(A, {
156
+ htmlFor: O("subscription-seats"),
157
+ children: /* @__PURE__ */ B(e, { id: "Seats" })
158
+ }),
159
+ /* @__PURE__ */ B(c, {
160
+ id: O("subscription-seats"),
161
+ type: "number",
162
+ inputMode: "numeric",
163
+ min: Y.min,
164
+ max: Y.max,
165
+ value: de,
166
+ onChange: (e) => Oe(e.target.value)
167
+ }),
168
+ /* @__PURE__ */ V("p", {
169
+ className: "text-xs text-muted-foreground",
170
+ children: [
171
+ Y.min,
172
+ /* @__PURE__ */ B(e, { id: " to " }),
173
+ Y.max,
174
+ /* @__PURE__ */ B(e, { id: " seats." })
175
+ ]
176
+ })
177
+ ]
178
+ }),
179
+ /* @__PURE__ */ V("div", {
180
+ className: "grid gap-1.5",
181
+ children: [
182
+ /* @__PURE__ */ B(A, {
183
+ htmlFor: O("subscription-change-reason"),
184
+ children: /* @__PURE__ */ B(e, { id: "Reason" })
185
+ }),
186
+ /* @__PURE__ */ B(c, {
187
+ id: O("subscription-change-reason"),
188
+ value: N,
189
+ maxLength: 500,
190
+ placeholder: se("What the customer asked for"),
191
+ onChange: (e) => fe(e.target.value)
192
+ }),
193
+ /* @__PURE__ */ B("p", {
194
+ className: "text-xs text-muted-foreground",
195
+ children: /* @__PURE__ */ B(e, { id: "Kept with the scheduled change." })
196
+ })
197
+ ]
198
+ }),
199
+ $ && J && /* @__PURE__ */ V("div", {
200
+ className: "grid gap-3",
201
+ "aria-live": "polite",
202
+ children: [
203
+ /* @__PURE__ */ V("div", {
204
+ className: "flex items-center justify-between gap-4",
205
+ children: [/* @__PURE__ */ B("span", {
206
+ className: "text-sm font-medium",
207
+ children: /* @__PURE__ */ B(e, { id: "Review" })
208
+ }), /* @__PURE__ */ B(h, {
209
+ variant: "secondary",
210
+ children: $.effective === "now" ? "Immediate" : "At renewal"
211
+ })]
212
+ }),
213
+ /* @__PURE__ */ V("dl", {
214
+ className: "grid grid-cols-2 gap-x-8 gap-y-3 border-y py-4 text-sm",
215
+ children: [
216
+ $.quantity !== null && /* @__PURE__ */ V("div", {
217
+ className: "grid gap-1",
218
+ children: [/* @__PURE__ */ B("dt", {
219
+ className: "text-xs text-muted-foreground",
220
+ children: /* @__PURE__ */ B(e, { id: "Seats" })
221
+ }), /* @__PURE__ */ B("dd", {
222
+ className: "font-medium tabular-nums",
223
+ children: $.quantity
224
+ })]
225
+ }),
226
+ /* @__PURE__ */ V("div", {
227
+ className: "grid gap-1",
228
+ children: [/* @__PURE__ */ B("dt", {
229
+ className: "text-xs text-muted-foreground",
230
+ children: /* @__PURE__ */ B(e, { id: "Due now" })
231
+ }), /* @__PURE__ */ B("dd", {
232
+ className: "font-medium tabular-nums",
233
+ children: p($.amount_due_now, $.currency)
234
+ })]
235
+ }),
236
+ /* @__PURE__ */ V("div", {
237
+ className: "grid gap-1",
238
+ children: [/* @__PURE__ */ B("dt", {
239
+ className: "text-xs text-muted-foreground",
240
+ children: /* @__PURE__ */ B(e, { id: "Next charge" })
241
+ }), /* @__PURE__ */ B("dd", {
242
+ className: "font-medium tabular-nums",
243
+ children: p($.next_charge_amount, $.currency)
244
+ })]
245
+ }),
246
+ /* @__PURE__ */ V("div", {
247
+ className: "grid gap-1",
248
+ children: [/* @__PURE__ */ B("dt", {
249
+ className: "text-xs text-muted-foreground",
250
+ children: /* @__PURE__ */ B(e, { id: "Effective" })
251
+ }), /* @__PURE__ */ B("dd", {
252
+ className: "font-medium",
253
+ children: $.effective === "now" ? "Immediately" : d($.next_charge_date)
254
+ })]
255
+ }),
256
+ /* @__PURE__ */ V("div", {
257
+ className: "grid gap-1",
258
+ children: [/* @__PURE__ */ B("dt", {
259
+ className: "text-xs text-muted-foreground",
260
+ children: /* @__PURE__ */ B(e, { id: "Next billing date" })
261
+ }), /* @__PURE__ */ B("dd", {
262
+ className: "font-medium tabular-nums",
263
+ children: d($.next_charge_date)
264
+ })]
265
+ })
266
+ ]
267
+ }),
268
+ $.is_estimate && /* @__PURE__ */ B("p", {
269
+ className: "text-xs text-muted-foreground",
270
+ children: /* @__PURE__ */ B(e, { id: "The payment provider calculates the final prorated amount." })
271
+ })
272
+ ]
273
+ }),
274
+ (ke || Ae) && /* @__PURE__ */ B("p", {
275
+ className: "text-sm text-destructive",
276
+ role: "alert",
277
+ children: Ae || ke
278
+ }),
279
+ W.data && W.data.status !== "succeeded" && /* @__PURE__ */ V("div", {
280
+ className: "grid gap-2 rounded-lg bg-muted px-3 py-2.5 text-sm",
281
+ "aria-live": "polite",
282
+ children: [/* @__PURE__ */ B("p", { children: je ?? "This change needs another step." }), Me && /* @__PURE__ */ B("a", {
283
+ href: Me,
284
+ target: "_blank",
285
+ rel: "noreferrer",
286
+ className: "w-fit font-medium text-primary underline underline-offset-4",
287
+ children: /* @__PURE__ */ B(e, { id: "Continue with payment provider" })
288
+ })]
289
+ })
290
+ ]
291
+ }),
292
+ /* @__PURE__ */ V(ee, { children: [/* @__PURE__ */ B(s, {
293
+ type: "button",
294
+ variant: "outline",
295
+ onClick: () => Ee(!1),
296
+ children: /* @__PURE__ */ B(e, { id: "Cancel" })
297
+ }), $ ? /* @__PURE__ */ B(s, {
298
+ type: "button",
299
+ disabled: W.isPending || !N.trim() || !!W.data && W.data?.status !== "processing",
300
+ onClick: async () => {
301
+ if (!Z) return;
302
+ let e = H.current, t = z.current.get(Q) ?? crypto.randomUUID();
303
+ z.current.set(Q, t);
304
+ let n = () => {
305
+ z.current.get(Q) === t && z.current.delete(Q);
306
+ };
307
+ try {
308
+ let r = await W.mutateAsync({
309
+ change: {
310
+ ...Z,
311
+ reason: N.trim()
312
+ },
313
+ idempotencyKey: t
314
+ });
315
+ if ((r.status === "succeeded" || r.status === "blocked") && n(), H.current !== e) return;
316
+ r.status === "succeeded" && (w.success(r.effective === "now" ? "Subscription changed" : "Change scheduled for the next renewal"), Ee(!1), ue(""), M(""), fe(""), P(""), U.reset(), W.reset()), r.status === "processing" && w.info("The provider is still confirming this change. Check again to read the result.");
317
+ } catch (t) {
318
+ t instanceof o && (t.status === 402 || t.status === 409 && (t.code === "subscription_change_refused" || t.code === "subscription_change_idempotency_conflict")) && n(), H.current === e && T(t, "Change subscription");
319
+ }
320
+ },
321
+ children: W.isPending ? "Applying…" : W.data ? W.data.status === "processing" ? "Check result" : W.data.status === "blocked" ? "Change blocked" : "Action required" : "Confirm change"
322
+ }) : /* @__PURE__ */ B(s, {
323
+ type: "button",
324
+ disabled: !Z || we || U.isPending,
325
+ onClick: async () => {
326
+ if (!Z) return;
327
+ let e = H.current;
328
+ try {
329
+ if (await U.mutateAsync(Z), H.current !== e) return;
330
+ P(Q);
331
+ } catch (t) {
332
+ H.current === e && T(t, "Preview subscription change");
333
+ }
334
+ },
335
+ children: U.isPending ? "Reviewing…" : "Review change"
336
+ })] })
337
+ ]
338
+ })]
339
+ });
340
+ }
341
+ //#endregion
342
+ //#region src/admin/pages/subscriptions/detail.tsx
343
+ var ye = (e) => new Date(e).toLocaleDateString(void 0, { dateStyle: "medium" });
344
+ function be() {
345
+ let { text: o } = t(), { adminQueries: c } = r(), u = l(), { id: _ = "" } = n(), v = a(), { data: y, isPending: b, error: x } = L(c.subscription(_)), { data: S } = L(c.payments({ subscription_id: _ }, 20)), k = S?.data ?? [], { data: ee } = L(c.customer(y?.customer_id ?? ""));
346
+ if (b) return /* @__PURE__ */ B("p", {
347
+ className: "text-sm text-muted-foreground",
348
+ children: /* @__PURE__ */ B(e, { id: "Loading…" })
349
+ });
350
+ if (!y) return /* @__PURE__ */ B(pe, {
351
+ title: "Subscription not found",
352
+ error: x,
353
+ back: "/subscriptions",
354
+ backLabel: "Subscriptions"
355
+ });
356
+ let te = y.status === "active" || y.status === "past_due" || y.status === "awaiting_method" || y.status === "unverified", ne = y.status === "active" || y.status === "past_due", re = ne || y.status === "awaiting_method", ie = y.collection_policy === "engine" ? (y.rail === "nmi" || y.rail === "stripe") && (re || y.resumable) : y.rail === "nmi" && re, ae = ee ? f(ee) : void 0, A = y.product?.display_name;
357
+ return /* @__PURE__ */ V("div", {
358
+ className: "flex flex-col gap-4",
359
+ children: [
360
+ /* @__PURE__ */ V("div", {
361
+ className: "flex flex-wrap items-center gap-3",
362
+ children: [
363
+ /* @__PURE__ */ B(s, {
364
+ variant: "ghost",
365
+ size: "icon",
366
+ onClick: () => v(-1),
367
+ "aria-label": o("Back"),
368
+ children: /* @__PURE__ */ B(H, {
369
+ icon: me,
370
+ className: "size-4"
371
+ })
372
+ }),
373
+ /* @__PURE__ */ V("div", {
374
+ className: "min-w-0",
375
+ children: [/* @__PURE__ */ V("h1", {
376
+ className: "flex flex-wrap items-center gap-2 text-2xl font-semibold tracking-tight",
377
+ children: [A ?? o("Subscription"), /* @__PURE__ */ B(g, { status: y.status })]
378
+ }), /* @__PURE__ */ V("p", {
379
+ className: "text-xs [overflow-wrap:anywhere] text-muted-foreground",
380
+ children: [
381
+ y.id,
382
+ " · ",
383
+ y.rail,
384
+ y.rail_subscription_id ? ` · ${y.rail_subscription_id}` : ""
385
+ ]
386
+ })]
387
+ }),
388
+ /* @__PURE__ */ V("div", {
389
+ className: "flex flex-wrap gap-2 sm:ml-auto",
390
+ children: [
391
+ u && y.resumable && /* @__PURE__ */ B(q, {
392
+ id: y.id,
393
+ customerId: y.customer_id
394
+ }),
395
+ u && ne && /* @__PURE__ */ B(G, {
396
+ subscriptionId: y.id,
397
+ customerId: y.customer_id,
398
+ productId: y.product_id,
399
+ priceId: y.price_id,
400
+ quantity: y.quantity,
401
+ currency: y.price?.currency,
402
+ collectionPolicy: y.collection_policy,
403
+ scheduledChange: y.scheduled_change,
404
+ rail: y.rail,
405
+ status: y.status
406
+ }),
407
+ u && ie && /* @__PURE__ */ B(Y, {
408
+ subscriptionId: y.id,
409
+ customerId: y.customer_id,
410
+ rail: y.rail
411
+ }),
412
+ u && te && /* @__PURE__ */ B(Se, {
413
+ id: y.id,
414
+ customerId: y.customer_id,
415
+ customer: ae,
416
+ plan: A,
417
+ periodEnd: y.current_period_ends_at
418
+ })
419
+ ]
420
+ })
421
+ ]
422
+ }),
423
+ /* @__PURE__ */ V("div", {
424
+ className: N,
425
+ children: [
426
+ /* @__PURE__ */ B(M, {
427
+ label: o("Customer"),
428
+ children: y.customer_id ? /* @__PURE__ */ B(i, {
429
+ className: "text-xs underline-offset-2 hover:underline",
430
+ to: `/customers/${y.customer_id}`,
431
+ children: ae ?? m(y.customer_id, 13)
432
+ }) : "—"
433
+ }),
434
+ /* @__PURE__ */ B(M, {
435
+ label: o("Started"),
436
+ children: d(y.started_at)
437
+ }),
438
+ /* @__PURE__ */ V(M, {
439
+ label: o("Current period"),
440
+ children: [
441
+ d(y.current_period_starts_at),
442
+ " →",
443
+ " ",
444
+ d(y.current_period_ends_at)
445
+ ]
446
+ }),
447
+ /* @__PURE__ */ B(M, {
448
+ label: o("Price"),
449
+ children: /* @__PURE__ */ V("div", {
450
+ className: "flex flex-col gap-1",
451
+ children: [
452
+ /* @__PURE__ */ V("span", {
453
+ className: "flex items-center gap-2",
454
+ children: [y.price?.unit_amount !== void 0 && y.price?.currency ? /* @__PURE__ */ B(i, {
455
+ className: "underline-offset-2 hover:underline",
456
+ to: `/catalog/prices/${encodeURIComponent(y.price_id)}`,
457
+ children: p(y.price.unit_amount, y.price.currency)
458
+ }) : /* @__PURE__ */ B(i, {
459
+ className: "text-xs underline-offset-2 hover:underline",
460
+ to: `/catalog/prices/${encodeURIComponent(y.price_id)}`,
461
+ children: m(y.price_id ?? "—", 13)
462
+ }), y.price?.archived && /* @__PURE__ */ B(h, {
463
+ variant: "secondary",
464
+ title: o("Pinned to an archived (prior) version"),
465
+ children: /* @__PURE__ */ B(e, { id: "prior version" })
466
+ })]
467
+ }),
468
+ y.price?.key && /* @__PURE__ */ B("span", {
469
+ className: "text-xs text-muted-foreground",
470
+ children: y.price.key
471
+ }),
472
+ y.scheduled_change && /* @__PURE__ */ B(X, { change: y.scheduled_change })
473
+ ]
474
+ })
475
+ }),
476
+ y.quantity !== null && /* @__PURE__ */ V(M, {
477
+ label: o("Seats"),
478
+ children: [y.quantity, y.scheduled_change?.quantity != null && ` → ${y.scheduled_change.quantity} at renewal`]
479
+ }),
480
+ /* @__PURE__ */ B(M, {
481
+ label: o("Dunning"),
482
+ children: y.dunning ? fe(y.dunning) : "—"
483
+ }),
484
+ /* @__PURE__ */ B(M, {
485
+ label: y.dunning?.waiting_for_new_card ? "Card deadline" : "Final retry",
486
+ children: d(y.dunning?.final_retry_at)
487
+ }),
488
+ /* @__PURE__ */ B(M, {
489
+ label: o("Last decline"),
490
+ children: y.dunning?.last_failure_reason ?? "—"
491
+ }),
492
+ /* @__PURE__ */ B(M, {
493
+ label: o("Canceled"),
494
+ children: y.canceled_at ? /* @__PURE__ */ V(z, { children: [d(y.canceled_at), y.cancel_type && /* @__PURE__ */ B("span", {
495
+ className: "block text-xs text-muted-foreground",
496
+ children: o(xe[y.cancel_type] ?? y.cancel_type)
497
+ })] }) : "—"
498
+ })
499
+ ]
500
+ }),
501
+ /* @__PURE__ */ V(de, { children: [/* @__PURE__ */ B(ce, { children: /* @__PURE__ */ B(le, {
502
+ className: "text-sm",
503
+ children: /* @__PURE__ */ B(e, { id: "Payments" })
504
+ }) }), /* @__PURE__ */ B(ue, { children: k.length ? /* @__PURE__ */ V(O, { children: [/* @__PURE__ */ B(T, { children: /* @__PURE__ */ V(D, {
505
+ className: "hover:bg-transparent",
506
+ children: [
507
+ /* @__PURE__ */ B(C, {
508
+ className: "text-muted-foreground",
509
+ children: /* @__PURE__ */ B(e, { id: "Payment" })
510
+ }),
511
+ /* @__PURE__ */ B(C, {
512
+ className: "text-muted-foreground",
513
+ children: /* @__PURE__ */ B(e, { id: "Status" })
514
+ }),
515
+ /* @__PURE__ */ B(C, {
516
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
517
+ children: /* @__PURE__ */ B(e, { id: "Kind" })
518
+ }),
519
+ /* @__PURE__ */ B(C, {
520
+ className: "text-muted-foreground",
521
+ children: /* @__PURE__ */ B(e, { id: "Amount" })
522
+ }),
523
+ /* @__PURE__ */ B(C, {
524
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
525
+ children: /* @__PURE__ */ B(e, { id: "Created" })
526
+ })
527
+ ]
528
+ }) }), /* @__PURE__ */ B(w, { children: k.map((e) => /* @__PURE__ */ V(D, { children: [
529
+ /* @__PURE__ */ B(E, { children: /* @__PURE__ */ B(i, {
530
+ className: "text-xs underline-offset-2 hover:underline",
531
+ to: `/payments/${e.id}`,
532
+ children: m(e.id, 13)
533
+ }) }),
534
+ /* @__PURE__ */ B(E, { children: /* @__PURE__ */ B(g, { status: e.status }) }),
535
+ /* @__PURE__ */ B(E, {
536
+ className: "@max-[36rem]/page:hidden",
537
+ children: e.kind
538
+ }),
539
+ /* @__PURE__ */ B(E, { children: p(e.amount, e.currency) }),
540
+ /* @__PURE__ */ B(E, {
541
+ className: "@max-[36rem]/page:hidden",
542
+ children: d(e.created_at)
543
+ })
544
+ ] }, e.id)) })] }) : /* @__PURE__ */ B("p", {
545
+ className: "text-sm text-muted-foreground",
546
+ children: /* @__PURE__ */ B(e, { id: "No payments recorded." })
547
+ }) })] })
548
+ ]
549
+ });
550
+ }
551
+ var xe = {
552
+ user: "By the customer",
553
+ merchant: "By staff",
554
+ expired: "Renewal payment failed",
555
+ chargeback: "After a chargeback",
556
+ upgrade: "Replaced by an upgrade"
557
+ };
558
+ function Se({ id: n, customerId: i, customer: a, plan: o, periodEnd: l }) {
559
+ let { toast: u, toastApiError: d, adminMutations: f } = r(), { text: p, id: m } = t(), [h, g] = F.useState(!1), _ = R(), v = I(f.cancelSubscription(_, n, i)), y = U({ defaultValues: {
560
+ reason: "",
561
+ revokeAccess: !1
562
+ } }), b = W(y.store, (e) => e.values.revokeAccess), x = a ?? p("The customer"), S = o ?? p("their access");
563
+ return /* @__PURE__ */ V(z, { children: [/* @__PURE__ */ B(s, {
564
+ variant: "destructive",
565
+ size: "sm",
566
+ onClick: () => g(!0),
567
+ children: /* @__PURE__ */ B(e, { id: "Cancel membership" })
568
+ }), /* @__PURE__ */ B(P, {
569
+ open: h,
570
+ onOpenChange: (e) => {
571
+ g(e), e || (y.reset(), v.reset());
572
+ },
573
+ title: p("Cancel this membership?"),
574
+ description: `${p("Renewal stops now and can't be restarted from here.")} ${b ? `${x} ${p("loses")} ${S} ${p("now. No refund is made.")}` : `${x} ${p("keeps")} ${S} ${l ? `${p("until")} ${ye(l)}.` : p("until the current period ends.")}`}`,
575
+ confirmationWord: "CANCEL",
576
+ actionLabel: p("Cancel membership"),
577
+ onConfirm: async () => {
578
+ try {
579
+ await v.mutateAsync(y.state.values), u.success("Subscription canceled");
580
+ } catch (e) {
581
+ throw d(e, "Cancel subscription"), e;
582
+ }
583
+ },
584
+ children: /* @__PURE__ */ V("div", {
585
+ className: "grid gap-3",
586
+ children: [/* @__PURE__ */ B(y.Field, {
587
+ name: "reason",
588
+ children: (t) => /* @__PURE__ */ V("div", {
589
+ className: "grid gap-1.5",
590
+ children: [/* @__PURE__ */ B(A, {
591
+ htmlFor: m("cancel-reason"),
592
+ children: /* @__PURE__ */ B(e, { id: "Reason" })
593
+ }), /* @__PURE__ */ B(c, {
594
+ id: m("cancel-reason"),
595
+ value: t.state.value,
596
+ onBlur: t.handleBlur,
597
+ onChange: (e) => t.handleChange(e.target.value),
598
+ placeholder: p("why is this being canceled?")
599
+ })]
600
+ })
601
+ }), /* @__PURE__ */ B(y.Field, {
602
+ name: "revokeAccess",
603
+ children: (t) => /* @__PURE__ */ V(A, {
604
+ className: "flex min-h-10 items-center gap-2 font-normal",
605
+ children: [/* @__PURE__ */ B("input", {
606
+ type: "checkbox",
607
+ className: "size-4 accent-destructive",
608
+ checked: t.state.value,
609
+ onChange: (e) => t.handleChange(e.target.checked)
610
+ }), /* @__PURE__ */ B(e, { id: "End access now instead (no refund is made)" })]
611
+ })
612
+ })]
613
+ })
614
+ })] });
615
+ }
616
+ function q({ id: e, customerId: t }) {
617
+ let { toast: n, toastApiError: i, adminMutations: a } = r(), o = R(), c = I(a.resumeSubscription(o, e, t));
618
+ return /* @__PURE__ */ B(s, {
619
+ variant: "outline",
620
+ size: "sm",
621
+ disabled: c.isPending,
622
+ onClick: async () => {
623
+ try {
624
+ await c.mutateAsync(), n.success("Resume queued");
625
+ } catch (e) {
626
+ i(e, "Resume subscription");
627
+ }
628
+ },
629
+ children: c.isPending ? "Queuing…" : "Resume"
630
+ });
631
+ }
632
+ var J = "default";
633
+ function Y({ subscriptionId: n, customerId: i, rail: a }) {
634
+ let { toast: o, toastApiError: c, adminMutations: l, adminQueries: d } = r(), { id: f, text: p } = t(), [m, h] = F.useState(!1), g = R(), C = I(l.changeSubscriptionPaymentMethod(g, n, i)), { data: w } = L(d.customerPaymentMethods(m ? i : void 0)), T = U({
635
+ defaultValues: { paymentMethodId: "" },
636
+ onSubmit: async ({ value: e }) => {
637
+ try {
638
+ await C.mutateAsync(e.paymentMethodId === J ? null : e.paymentMethodId), o.success("Payment method updated"), E(!1);
639
+ } catch (e) {
640
+ c(e, "Change payment method");
641
+ }
642
+ }
643
+ }), E = (e) => {
644
+ h(e), e || (T.reset(), C.reset());
645
+ };
646
+ return /* @__PURE__ */ V(ae, {
647
+ open: m,
648
+ onOpenChange: E,
649
+ children: [/* @__PURE__ */ B(ie, { render: /* @__PURE__ */ B(s, {
650
+ variant: "outline",
651
+ size: "sm",
652
+ children: /* @__PURE__ */ B(e, { id: "Change payment method" })
653
+ }) }), /* @__PURE__ */ V(te, {
654
+ className: se,
655
+ children: [/* @__PURE__ */ V(k, { children: [/* @__PURE__ */ B(ne, { children: /* @__PURE__ */ B(e, { id: "Change payment method" }) }), /* @__PURE__ */ B(re, { children: /* @__PURE__ */ B(e, { id: "Points future renewals of this subscription at another of the customer&apos;s stored cards (same rail), or back at their default card for its currency." }) })] }), /* @__PURE__ */ V("form", {
656
+ onSubmit: (e) => {
657
+ e.preventDefault(), e.stopPropagation(), T.handleSubmit();
658
+ },
659
+ className: "grid gap-4",
660
+ children: [/* @__PURE__ */ B(T.Field, {
661
+ name: "paymentMethodId",
662
+ validators: { onChange: ({ value: e }) => e ? void 0 : "Pick a stored payment method" },
663
+ children: (t) => /* @__PURE__ */ V("div", {
664
+ className: "grid gap-1.5",
665
+ children: [
666
+ /* @__PURE__ */ B(A, {
667
+ htmlFor: f("subscription-payment-method"),
668
+ children: /* @__PURE__ */ B(e, { id: "Payment method" })
669
+ }),
670
+ /* @__PURE__ */ V(S, {
671
+ value: t.state.value,
672
+ onValueChange: (e) => t.handleChange(e ?? ""),
673
+ children: [/* @__PURE__ */ B(y, {
674
+ className: "w-full",
675
+ id: f("subscription-payment-method"),
676
+ "aria-invalid": t.state.meta.errors.length > 0,
677
+ children: /* @__PURE__ */ B(v, { placeholder: p("Pick a stored payment method") })
678
+ }), /* @__PURE__ */ V(b, { children: [/* @__PURE__ */ B(x, {
679
+ value: J,
680
+ children: /* @__PURE__ */ B(e, { id: "The customer&apos;s default card" })
681
+ }), (w ?? []).filter((e) => e.rail === a).map((e) => /* @__PURE__ */ V(x, {
682
+ value: e.id,
683
+ children: [
684
+ u(e.card),
685
+ " (",
686
+ e.rail,
687
+ ")"
688
+ ]
689
+ }, e.id))] })]
690
+ }),
691
+ /* @__PURE__ */ B(_, { errors: t.state.meta.errors })
692
+ ]
693
+ })
694
+ }), /* @__PURE__ */ B(ee, { children: /* @__PURE__ */ B(T.Subscribe, {
695
+ selector: (e) => [
696
+ e.values.paymentMethodId,
697
+ e.canSubmit,
698
+ e.isSubmitting
699
+ ],
700
+ children: ([e, t, n]) => /* @__PURE__ */ B(s, {
701
+ type: "submit",
702
+ disabled: !e || !t || n,
703
+ children: n ? "Updating…" : "Update"
704
+ })
705
+ }) })]
706
+ })]
707
+ })]
708
+ });
709
+ }
710
+ function X({ change: t }) {
711
+ let { adminQueries: n } = r(), { data: i } = L(n.price(t.price_id));
712
+ return /* @__PURE__ */ V(h, {
713
+ className: "bg-held-surface text-held",
714
+ children: [
715
+ t.source === "migration" ? "migrates" : "changes",
716
+ /* @__PURE__ */ B(e, { id: " to" }),
717
+ " ",
718
+ i ? p(i.unit_amount, i.currency) : m(t.price_id, 9),
719
+ " ",
720
+ /* @__PURE__ */ B(e, { id: "at the first renewal from " }),
721
+ d(t.effective_at)
722
+ ]
723
+ });
724
+ }
725
+ //#endregion
726
+ export { be as SubscriptionDetailPage };
727
+
728
+ //# sourceMappingURL=admin-detail-CKRtK43V.js.map