@openrails/billing-ui 0.273.0 → 0.275.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 (207) 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 +34 -2
  5. package/dist/admin/lib/api/endpoints.d.ts +4 -1
  6. package/dist/admin/lib/api/index.d.ts +3 -0
  7. package/dist/admin/lib/api/order-endpoints.d.ts +1 -0
  8. package/dist/admin/lib/api/types.d.ts +4 -12
  9. package/dist/admin/lib/capabilities.d.ts +4 -0
  10. package/dist/admin/lib/dialog-width.d.ts +4 -3
  11. package/dist/admin/lib/error-text.d.ts +4 -0
  12. package/dist/admin/lib/format.d.ts +5 -1
  13. package/dist/admin/lib/mutations.d.ts +6 -1
  14. package/dist/admin/lib/order-queries.d.ts +3 -0
  15. package/dist/admin/lib/queries.d.ts +6 -0
  16. package/dist/admin/lib/tile-grids.d.ts +6 -0
  17. package/dist/admin/messages.d.ts +102 -8
  18. package/dist/admin/pages/dashboard/lib.d.ts +1 -0
  19. package/dist/admin/pages/imports/shared.d.ts +1 -0
  20. package/dist/admin/pages/payments/index.d.ts +1 -2
  21. package/dist/admin/pages/subscriptions/change-subscription-dialog.d.ts +4 -7
  22. package/dist/admin/pages/subscriptions/index.d.ts +1 -2
  23. package/dist/admin/pages/subscriptions/subscription-change-options.d.ts +6 -15
  24. package/dist/admin-attempts-CP5CWyNR.js +419 -0
  25. package/dist/admin-attempts-CP5CWyNR.js.map +1 -0
  26. package/dist/{admin-auth-1aZIgXiS.js → admin-auth-DlIOmwPo.js} +2 -2
  27. package/dist/{admin-auth-1aZIgXiS.js.map → admin-auth-DlIOmwPo.js.map} +1 -1
  28. package/dist/{admin-badge-pgG6D9-a.js → admin-badge-DR_8AhdC.js} +2 -2
  29. package/dist/{admin-badge-pgG6D9-a.js.map → admin-badge-DR_8AhdC.js.map} +1 -1
  30. package/dist/{admin-button-CrcYk5r0.js → admin-button-DBzTD6By.js} +2 -2
  31. package/dist/{admin-button-CrcYk5r0.js.map → admin-button-DBzTD6By.js.map} +1 -1
  32. package/dist/{admin-capabilities-BDcZeHL_.js → admin-capabilities-CZdT1Pxe.js} +35 -14
  33. package/dist/admin-capabilities-CZdT1Pxe.js.map +1 -0
  34. package/dist/{admin-card-DvTMc5Se.js → admin-card-mZl4-s5d.js} +2 -2
  35. package/dist/{admin-card-DvTMc5Se.js.map → admin-card-mZl4-s5d.js.map} +1 -1
  36. package/dist/{admin-catalog-BlF5mnu4.js → admin-catalog-DpTjS0Yo.js} +298 -298
  37. package/dist/{admin-catalog-BlF5mnu4.js.map → admin-catalog-DpTjS0Yo.js.map} +1 -1
  38. package/dist/{admin-cursor-pager-CIb3Jw2F.js → admin-cursor-pager-C-KjCIy9.js} +6 -6
  39. package/dist/{admin-cursor-pager-CIb3Jw2F.js.map → admin-cursor-pager-C-KjCIy9.js.map} +1 -1
  40. package/dist/{admin-customers-EpfoWDh-.js → admin-customers-BE3N839X.js} +22 -21
  41. package/dist/{admin-customers-EpfoWDh-.js.map → admin-customers-BE3N839X.js.map} +1 -1
  42. package/dist/admin-dashboard-BxjkV15J.js +464 -0
  43. package/dist/admin-dashboard-BxjkV15J.js.map +1 -0
  44. package/dist/admin-data-table-D89AwWz_.js +107 -0
  45. package/dist/admin-data-table-D89AwWz_.js.map +1 -0
  46. package/dist/admin-detail-BKe9xqPd.js +338 -0
  47. package/dist/admin-detail-BKe9xqPd.js.map +1 -0
  48. package/dist/admin-detail-C8lD7U2t.js +699 -0
  49. package/dist/admin-detail-C8lD7U2t.js.map +1 -0
  50. package/dist/admin-detail-D6zD085K.js +354 -0
  51. package/dist/admin-detail-D6zD085K.js.map +1 -0
  52. package/dist/{admin-detail-3wFIDPNB.js → admin-detail-Ln56otK0.js} +83 -83
  53. package/dist/{admin-detail-3wFIDPNB.js.map → admin-detail-Ln56otK0.js.map} +1 -1
  54. package/dist/admin-detail-P-UnNvXJ.js +1357 -0
  55. package/dist/admin-detail-P-UnNvXJ.js.map +1 -0
  56. package/dist/{admin-dialog-BSRf9Zre.js → admin-dialog-Dn2FRJu4.js} +3 -3
  57. package/dist/{admin-dialog-BSRf9Zre.js.map → admin-dialog-Dn2FRJu4.js.map} +1 -1
  58. package/dist/admin-dialog-width-CC7QHT1p.js +6 -0
  59. package/dist/admin-dialog-width-CC7QHT1p.js.map +1 -0
  60. package/dist/{admin-dropdown-menu-D0E5rwmn.js → admin-dropdown-menu-DLUn6Uj3.js} +2 -2
  61. package/dist/{admin-dropdown-menu-D0E5rwmn.js.map → admin-dropdown-menu-DLUn6Uj3.js.map} +1 -1
  62. package/dist/{admin-dunning-B2zgtrOo.js → admin-dunning-COaHzrmN.js} +2 -2
  63. package/dist/{admin-dunning-B2zgtrOo.js.map → admin-dunning-COaHzrmN.js.map} +1 -1
  64. package/dist/{admin-fact-card-BPSVhS15.js → admin-fact-card-DKvBnUXB.js} +2 -2
  65. package/dist/{admin-fact-card-BPSVhS15.js.map → admin-fact-card-DKvBnUXB.js.map} +1 -1
  66. package/dist/admin-format-BbiTCqUG.js +171 -0
  67. package/dist/admin-format-BbiTCqUG.js.map +1 -0
  68. package/dist/{admin-health-D0L5Kig7.js → admin-health-DmnI4e8K.js} +249 -248
  69. package/dist/admin-health-DmnI4e8K.js.map +1 -0
  70. package/dist/{admin-imports-CgZB5JAV.js → admin-imports-C0aMP6sj.js} +65 -65
  71. package/dist/{admin-imports-CgZB5JAV.js.map → admin-imports-C0aMP6sj.js.map} +1 -1
  72. package/dist/{admin-input-DJAK9nmk.js → admin-input-JKrQIGfD.js} +2 -2
  73. package/dist/{admin-input-DJAK9nmk.js.map → admin-input-JKrQIGfD.js.map} +1 -1
  74. package/dist/{admin-label-aviN9Gng.js → admin-label-CHWsVIZC.js} +2 -2
  75. package/dist/{admin-label-aviN9Gng.js.map → admin-label-CHWsVIZC.js.map} +1 -1
  76. package/dist/{admin-linked-table-row-BGr7JXeM.js → admin-linked-table-row-BMZYYsuk.js} +4 -4
  77. package/dist/{admin-linked-table-row-BGr7JXeM.js.map → admin-linked-table-row-BMZYYsuk.js.map} +1 -1
  78. package/dist/{admin-map-dialog-DS2Wz6G3.js → admin-map-dialog-BHUGdCcv.js} +24 -24
  79. package/dist/{admin-map-dialog-DS2Wz6G3.js.map → admin-map-dialog-BHUGdCcv.js.map} +1 -1
  80. package/dist/{admin-metering-D-e-37Jn.js → admin-metering-CDqueHUh.js} +307 -307
  81. package/dist/{admin-metering-D-e-37Jn.js.map → admin-metering-CDqueHUh.js.map} +1 -1
  82. package/dist/admin-missing-record-BPFs3MmO.js +42 -0
  83. package/dist/admin-missing-record-BPFs3MmO.js.map +1 -0
  84. package/dist/admin-ops-CL2kjDwi.js +359 -0
  85. package/dist/admin-ops-CL2kjDwi.js.map +1 -0
  86. package/dist/admin-orders-C1Sf2qhc.js +192 -0
  87. package/dist/admin-orders-C1Sf2qhc.js.map +1 -0
  88. package/dist/admin-parked-a0tB5bhG.js +193 -0
  89. package/dist/admin-parked-a0tB5bhG.js.map +1 -0
  90. package/dist/admin-payments-DJcjwRA4.js +221 -0
  91. package/dist/admin-payments-DJcjwRA4.js.map +1 -0
  92. package/dist/{admin-price-detail-CSI5oKdb.js → admin-price-detail-BOmeWw15.js} +103 -103
  93. package/dist/{admin-price-detail-CSI5oKdb.js.map → admin-price-detail-BOmeWw15.js.map} +1 -1
  94. package/dist/{admin-price-format-BVUpDoSC.js → admin-price-format-CqOmHrIn.js} +2 -2
  95. package/dist/{admin-price-format-BVUpDoSC.js.map → admin-price-format-CqOmHrIn.js.map} +1 -1
  96. package/dist/{admin-price-wizard-CBEcNGvP.js → admin-price-wizard-B6s5OJeO.js} +63 -63
  97. package/dist/{admin-price-wizard-CBEcNGvP.js.map → admin-price-wizard-B6s5OJeO.js.map} +1 -1
  98. package/dist/{admin-proposals-Cuj7tvaM.js → admin-proposals-DVrl-ym4.js} +70 -70
  99. package/dist/{admin-proposals-Cuj7tvaM.js.map → admin-proposals-DVrl-ym4.js.map} +1 -1
  100. package/dist/admin-provider-prices-BVVogH7Q.js +241 -0
  101. package/dist/admin-provider-prices-BVVogH7Q.js.map +1 -0
  102. package/dist/{admin-range-picker-De36L-AP.js → admin-range-picker-C6BtSm2B.js} +9 -9
  103. package/dist/{admin-range-picker-De36L-AP.js.map → admin-range-picker-C6BtSm2B.js.map} +1 -1
  104. package/dist/{admin-records-H0MlhEVY.js → admin-records-DKtcgN11.js} +50 -50
  105. package/dist/{admin-records-H0MlhEVY.js.map → admin-records-DKtcgN11.js.map} +1 -1
  106. package/dist/{admin-reports-BFGS_PWf.js → admin-reports-CtPoiceH.js} +50 -50
  107. package/dist/{admin-reports-BFGS_PWf.js.map → admin-reports-CtPoiceH.js.map} +1 -1
  108. package/dist/{admin-select-BUcEU5Rg.js → admin-select-6Yuh5M1Q.js} +2 -2
  109. package/dist/{admin-select-BUcEU5Rg.js.map → admin-select-6Yuh5M1Q.js.map} +1 -1
  110. package/dist/admin-settings-DscHu4ww.js +1823 -0
  111. package/dist/admin-settings-DscHu4ww.js.map +1 -0
  112. package/dist/{admin-shared-lfIUEbPY.js → admin-shared-BywM-MMp.js} +28 -24
  113. package/dist/{admin-shared-lfIUEbPY.js.map → admin-shared-BywM-MMp.js.map} +1 -1
  114. package/dist/{admin-skeleton-B0yzYY_X.js → admin-skeleton-lndmw89u.js} +2 -2
  115. package/dist/{admin-skeleton-B0yzYY_X.js.map → admin-skeleton-lndmw89u.js.map} +1 -1
  116. package/dist/admin-status-badge-IL8ofZ_6.js +51 -0
  117. package/dist/admin-status-badge-IL8ofZ_6.js.map +1 -0
  118. package/dist/admin-subscriptions-Cd5CGrue.js +271 -0
  119. package/dist/admin-subscriptions-Cd5CGrue.js.map +1 -0
  120. package/dist/{admin-switch-DDorugaw.js → admin-switch-DpwQSzEm.js} +2 -2
  121. package/dist/{admin-switch-DDorugaw.js.map → admin-switch-DpwQSzEm.js.map} +1 -1
  122. package/dist/{admin-table-BU6Tie69.js → admin-table-D-GdGM1m.js} +2 -2
  123. package/dist/{admin-table-BU6Tie69.js.map → admin-table-D-GdGM1m.js.map} +1 -1
  124. package/dist/admin-tabs-B--1flzO.js +158 -0
  125. package/dist/admin-tabs-B--1flzO.js.map +1 -0
  126. package/dist/{admin-textarea-Dc6lnEub.js → admin-textarea-xsp5V9xM.js} +2 -2
  127. package/dist/{admin-textarea-Dc6lnEub.js.map → admin-textarea-xsp5V9xM.js.map} +1 -1
  128. package/dist/admin-tile-grids-CzGpidd9.js +6 -0
  129. package/dist/admin-tile-grids-CzGpidd9.js.map +1 -0
  130. package/dist/{admin-typed-confirm-dialog-Bk6XxmPb.js → admin-typed-confirm-dialog-NiEDwX_0.js} +11 -11
  131. package/dist/{admin-typed-confirm-dialog-Bk6XxmPb.js.map → admin-typed-confirm-dialog-NiEDwX_0.js.map} +1 -1
  132. package/dist/{admin-utils-B9eEBNsR.js → admin-utils-wuPUD0uh.js} +341 -283
  133. package/dist/admin-utils-wuPUD0uh.js.map +1 -0
  134. package/dist/admin-widget-viz-kHHVmDEx.js +646 -0
  135. package/dist/admin-widget-viz-kHHVmDEx.js.map +1 -0
  136. package/dist/admin.css +1 -1
  137. package/dist/admin.js +544 -413
  138. package/dist/admin.js.map +1 -1
  139. package/dist/client/generated/routes.d.ts +17 -0
  140. package/dist/client/generated/wire.d.ts +4 -0
  141. package/dist/client/types.d.ts +6 -0
  142. package/dist/{client-BYgnI6_h.js → client-ctrbivyN.js} +3 -2
  143. package/dist/client-ctrbivyN.js.map +1 -0
  144. package/dist/client.js +1 -1
  145. package/dist/{hooks-t2tSrCpa.js → hooks-KpTetx6F.js} +2 -2
  146. package/dist/{hooks-t2tSrCpa.js.map → hooks-KpTetx6F.js.map} +1 -1
  147. package/dist/index.js +750 -711
  148. package/dist/index.js.map +1 -1
  149. package/dist/lib/card-brands.d.ts +1 -0
  150. package/dist/locales/de.js +3 -0
  151. package/dist/locales/de.js.map +1 -1
  152. package/dist/locales/en.d.ts +3 -0
  153. package/dist/locales/en.js +3 -0
  154. package/dist/locales/en.js.map +1 -1
  155. package/dist/locales/es.js +3 -0
  156. package/dist/locales/es.js.map +1 -1
  157. package/dist/locales/ja.js +3 -0
  158. package/dist/locales/ja.js.map +1 -1
  159. package/dist/locales/ko.js +3 -0
  160. package/dist/locales/ko.js.map +1 -1
  161. package/dist/locales/zh.js +3 -0
  162. package/dist/locales/zh.js.map +1 -1
  163. package/dist/react.js +1 -1
  164. package/dist/styles.css +1 -1
  165. package/package.json +1 -1
  166. package/dist/admin-attempts-DyDDt-qw.js +0 -418
  167. package/dist/admin-attempts-DyDDt-qw.js.map +0 -1
  168. package/dist/admin-capabilities-BDcZeHL_.js.map +0 -1
  169. package/dist/admin-dashboard-CJE63yz4.js +0 -420
  170. package/dist/admin-dashboard-CJE63yz4.js.map +0 -1
  171. package/dist/admin-data-table-hvFcJepL.js +0 -96
  172. package/dist/admin-data-table-hvFcJepL.js.map +0 -1
  173. package/dist/admin-detail-BRP6pL7t.js +0 -328
  174. package/dist/admin-detail-BRP6pL7t.js.map +0 -1
  175. package/dist/admin-detail-CRzFb_pa.js +0 -1331
  176. package/dist/admin-detail-CRzFb_pa.js.map +0 -1
  177. package/dist/admin-detail-QLxU8r-5.js +0 -344
  178. package/dist/admin-detail-QLxU8r-5.js.map +0 -1
  179. package/dist/admin-detail-pPC8Q9l-.js +0 -710
  180. package/dist/admin-detail-pPC8Q9l-.js.map +0 -1
  181. package/dist/admin-dialog-width-BPrgdYlj.js +0 -6
  182. package/dist/admin-dialog-width-BPrgdYlj.js.map +0 -1
  183. package/dist/admin-format-DoohJ7Fg.js +0 -136
  184. package/dist/admin-format-DoohJ7Fg.js.map +0 -1
  185. package/dist/admin-health-D0L5Kig7.js.map +0 -1
  186. package/dist/admin-ops-CQP4TzWM.js +0 -235
  187. package/dist/admin-ops-CQP4TzWM.js.map +0 -1
  188. package/dist/admin-orders-BJ7W5S8P.js +0 -192
  189. package/dist/admin-orders-BJ7W5S8P.js.map +0 -1
  190. package/dist/admin-parked-B8xHkV2e.js +0 -193
  191. package/dist/admin-parked-B8xHkV2e.js.map +0 -1
  192. package/dist/admin-payments-CzkzqYA1.js +0 -246
  193. package/dist/admin-payments-CzkzqYA1.js.map +0 -1
  194. package/dist/admin-provider-prices-B6vwnVPi.js +0 -246
  195. package/dist/admin-provider-prices-B6vwnVPi.js.map +0 -1
  196. package/dist/admin-settings-DYC-c7mJ.js +0 -1813
  197. package/dist/admin-settings-DYC-c7mJ.js.map +0 -1
  198. package/dist/admin-status-badge-0-K37EfN.js +0 -43
  199. package/dist/admin-status-badge-0-K37EfN.js.map +0 -1
  200. package/dist/admin-subscriptions-CvW-YFs0.js +0 -301
  201. package/dist/admin-subscriptions-CvW-YFs0.js.map +0 -1
  202. package/dist/admin-tabs-D5lqdVcC.js +0 -46
  203. package/dist/admin-tabs-D5lqdVcC.js.map +0 -1
  204. package/dist/admin-utils-B9eEBNsR.js.map +0 -1
  205. package/dist/admin-widget-viz-8aukE3v_.js +0 -581
  206. package/dist/admin-widget-viz-8aukE3v_.js.map +0 -1
  207. package/dist/client-BYgnI6_h.js.map +0 -1
@@ -0,0 +1,1357 @@
1
+ import { E as e, O as t, _ as n, c as r, f as i, p as a, r as o, s, t as c } from "./admin-utils-wuPUD0uh.js";
2
+ import { t as l } from "./admin-button-DBzTD6By.js";
3
+ import { t as u } from "./admin-input-JKrQIGfD.js";
4
+ import { a as d, s as f } from "./admin-capabilities-CZdT1Pxe.js";
5
+ import { t as p } from "./admin-auth-DlIOmwPo.js";
6
+ import { a as m, d as h, i as g, n as _, o as v, s as y, t as b } from "./admin-format-BbiTCqUG.js";
7
+ import { n as x } from "./admin-confirm-katGq0Qo.js";
8
+ import { t as S } from "./admin-badge-DR_8AhdC.js";
9
+ import { t as C } from "./admin-status-badge-IL8ofZ_6.js";
10
+ import { t as w } from "./admin-form-field-errors-hbUMIriS.js";
11
+ import { a as T, i as E, n as D, r as O, t as k } from "./admin-select-6Yuh5M1Q.js";
12
+ import { n as A, t as j } from "./admin-cursor-pager-C-KjCIy9.js";
13
+ import { a as M, n as N, o as P, r as F, s as I, t as L } from "./admin-table-D-GdGM1m.js";
14
+ import { t as R } from "./admin-linked-table-row-BMZYYsuk.js";
15
+ import { a as z, i as B, n as V, o as H, r as ee, s as te, t as ne } from "./admin-dialog-Dn2FRJu4.js";
16
+ import { t as U } from "./admin-label-CHWsVIZC.js";
17
+ import { n as re, r as ie } from "./admin-dialog-width-CC7QHT1p.js";
18
+ import { a as W, o as G, r as K, t as q } from "./admin-card-mZl4-s5d.js";
19
+ import "./admin-tile-grids-CzGpidd9.js";
20
+ import { n as ae, t as oe } from "./admin-invoice-profile-model-Cgjy3zV8.js";
21
+ import { t as se } from "./admin-dunning-COaHzrmN.js";
22
+ import { t as ce } from "./admin-missing-record-BPFs3MmO.js";
23
+ import * as J from "react";
24
+ import { useState as le } from "react";
25
+ import { useMutation as Y, useQuery as X, useQueryClient as Z } from "@tanstack/react-query";
26
+ import { Fragment as ue, jsx as Q, jsxs as $ } from "react/jsx-runtime";
27
+ import { HugeiconsIcon as de } from "@hugeicons/react";
28
+ import { Add01Icon as fe, ArrowLeft01Icon as pe, Delete02Icon as me, Refresh01Icon as he } from "@hugeicons/core-free-icons";
29
+ import { useForm as ge } from "@tanstack/react-form";
30
+ //#region src/admin/pages/customers/invoice-profile.tsx
31
+ function _e({ customerId: t }) {
32
+ let { orderQueries: r } = a(), i = d(), s = X(r.profile(t));
33
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, { children: /* @__PURE__ */ Q(G, { children: /* @__PURE__ */ Q(e, { id: "Invoice profile" }) }) }), /* @__PURE__ */ $(K, { children: [/* @__PURE__ */ Q(o, {
34
+ className: "text-sm underline",
35
+ to: `/orders?customer_id=${t}&origin=usage`,
36
+ children: /* @__PURE__ */ Q(e, { id: "View customer usage orders" })
37
+ }), s.isPending ? /* @__PURE__ */ Q("p", { children: /* @__PURE__ */ Q(e, { id: "Loading invoice profile…" }) }) : s.error ? /* @__PURE__ */ Q("p", {
38
+ role: "alert",
39
+ className: "text-destructive",
40
+ children: n(s.error).text
41
+ }) : /* @__PURE__ */ Q(ve, {
42
+ customerId: t,
43
+ profile: s.data,
44
+ readOnly: !i
45
+ }, t)] })] });
46
+ }
47
+ function ve({ customerId: n, profile: r, readOnly: i = !1 }) {
48
+ let { id: o, text: s } = t(), { invoiceProfileMutation: c } = a(), [d, f] = le(() => ae(r)), [p, m] = le(null), [h, g] = le(!1), _ = Z(), v = Y(c(_, n)), y = (e) => {
49
+ f((t) => ({
50
+ ...t,
51
+ ...e
52
+ })), g(!1);
53
+ };
54
+ async function b() {
55
+ m(null), g(!1);
56
+ try {
57
+ await v.mutateAsync(oe(d, r)), g(!0);
58
+ } catch (e) {
59
+ m(e instanceof Error ? e.message : "Invoice profile update failed.");
60
+ }
61
+ }
62
+ return /* @__PURE__ */ $("form", {
63
+ className: "mt-4 space-y-4",
64
+ onSubmit: (e) => {
65
+ e.preventDefault(), v.isPending || b();
66
+ },
67
+ children: [
68
+ /* @__PURE__ */ Q("p", {
69
+ className: "text-sm text-muted-foreground",
70
+ children: /* @__PURE__ */ Q(e, { id: "Terms and billing facts for future usage orders. Billed orders keep their original snapshots. Tax details are recorded; no tax is calculated." })
71
+ }),
72
+ /* @__PURE__ */ $("fieldset", {
73
+ disabled: i || v.isPending,
74
+ className: "space-y-4",
75
+ children: [
76
+ /* @__PURE__ */ $("div", {
77
+ className: "grid gap-3 sm:grid-cols-2",
78
+ children: [/* @__PURE__ */ $("div", { children: [/* @__PURE__ */ Q(U, {
79
+ htmlFor: o("invoice-profile-terms"),
80
+ children: /* @__PURE__ */ Q(e, { id: "Payment terms (days)" })
81
+ }), /* @__PURE__ */ Q(u, {
82
+ id: o("invoice-profile-terms"),
83
+ type: "number",
84
+ min: 0,
85
+ step: 1,
86
+ value: d.terms,
87
+ onChange: (e) => y({ terms: e.target.value })
88
+ })] }), /* @__PURE__ */ $("div", { children: [/* @__PURE__ */ Q(U, {
89
+ htmlFor: o("invoice-profile-method"),
90
+ children: /* @__PURE__ */ Q(e, { id: "Collection method" })
91
+ }), /* @__PURE__ */ $("select", {
92
+ id: o("invoice-profile-method"),
93
+ className: "h-9 w-full rounded-md border bg-background px-2",
94
+ value: d.method,
95
+ onChange: (e) => y({ method: e.target.value }),
96
+ children: [/* @__PURE__ */ Q("option", {
97
+ value: "charge_automatically",
98
+ children: /* @__PURE__ */ Q(e, { id: "Saved payment method" })
99
+ }), /* @__PURE__ */ Q("option", {
100
+ value: "send_invoice",
101
+ children: /* @__PURE__ */ Q(e, { id: "Manual remittance" })
102
+ })]
103
+ })] })]
104
+ }),
105
+ /* @__PURE__ */ $("div", { children: [/* @__PURE__ */ Q(U, {
106
+ htmlFor: o("invoice-profile-po"),
107
+ children: /* @__PURE__ */ Q(e, { id: "Purchase order" })
108
+ }), /* @__PURE__ */ Q(u, {
109
+ id: o("invoice-profile-po"),
110
+ value: d.po,
111
+ onChange: (e) => y({ po: e.target.value })
112
+ })] }),
113
+ /* @__PURE__ */ $("div", { children: [/* @__PURE__ */ Q(U, {
114
+ htmlFor: o("invoice-profile-memo"),
115
+ children: /* @__PURE__ */ Q(e, { id: "Invoice memo" })
116
+ }), /* @__PURE__ */ Q(u, {
117
+ id: o("invoice-profile-memo"),
118
+ value: d.memo,
119
+ onChange: (e) => y({ memo: e.target.value })
120
+ })] }),
121
+ /* @__PURE__ */ $("div", {
122
+ className: "space-y-2",
123
+ children: [
124
+ /* @__PURE__ */ Q("p", {
125
+ className: "text-sm font-medium",
126
+ children: /* @__PURE__ */ Q(e, { id: "Billing contacts" })
127
+ }),
128
+ d.contacts.map((t, n) => /* @__PURE__ */ $("div", {
129
+ className: "flex gap-2",
130
+ children: [
131
+ /* @__PURE__ */ Q(u, {
132
+ "aria-label": `Contact ${n + 1} name`,
133
+ placeholder: s("Name"),
134
+ value: t.name,
135
+ onChange: (e) => y({ contacts: d.contacts.map((t, r) => r === n ? {
136
+ ...t,
137
+ name: e.target.value
138
+ } : t) })
139
+ }),
140
+ /* @__PURE__ */ Q(u, {
141
+ "aria-label": `Contact ${n + 1} email`,
142
+ type: "email",
143
+ placeholder: s("Email"),
144
+ value: t.email,
145
+ onChange: (e) => y({ contacts: d.contacts.map((t, r) => r === n ? {
146
+ ...t,
147
+ email: e.target.value
148
+ } : t) })
149
+ }),
150
+ /* @__PURE__ */ Q(l, {
151
+ type: "button",
152
+ variant: "outline",
153
+ "aria-label": `Remove contact ${n + 1}`,
154
+ onClick: () => y({ contacts: d.contacts.filter((e, t) => t !== n) }),
155
+ children: /* @__PURE__ */ Q(e, { id: "Remove" })
156
+ })
157
+ ]
158
+ }, n)),
159
+ /* @__PURE__ */ Q(l, {
160
+ type: "button",
161
+ variant: "outline",
162
+ onClick: () => y({ contacts: [...d.contacts, {
163
+ name: "",
164
+ email: ""
165
+ }] }),
166
+ children: /* @__PURE__ */ Q(e, { id: "Add contact" })
167
+ })
168
+ ]
169
+ }),
170
+ /* @__PURE__ */ $("div", {
171
+ className: "space-y-2",
172
+ children: [
173
+ /* @__PURE__ */ Q("p", {
174
+ className: "text-sm font-medium",
175
+ children: /* @__PURE__ */ Q(e, { id: "Tax details" })
176
+ }),
177
+ d.tax.map((t, n) => /* @__PURE__ */ $("div", {
178
+ className: "flex gap-2",
179
+ children: [
180
+ /* @__PURE__ */ Q(u, {
181
+ "aria-label": `Tax detail ${n + 1} name`,
182
+ placeholder: s("Name, such as tax_id"),
183
+ value: t.key,
184
+ onChange: (e) => y({ tax: d.tax.map((t, r) => r === n ? {
185
+ ...t,
186
+ key: e.target.value
187
+ } : t) })
188
+ }),
189
+ /* @__PURE__ */ Q(u, {
190
+ "aria-label": `Tax detail ${n + 1} value`,
191
+ placeholder: s("Value"),
192
+ value: t.value,
193
+ onChange: (e) => y({ tax: d.tax.map((t, r) => r === n ? {
194
+ ...t,
195
+ value: e.target.value
196
+ } : t) })
197
+ }),
198
+ /* @__PURE__ */ Q(l, {
199
+ type: "button",
200
+ variant: "outline",
201
+ "aria-label": `Remove tax detail ${n + 1}`,
202
+ onClick: () => y({ tax: d.tax.filter((e, t) => t !== n) }),
203
+ children: /* @__PURE__ */ Q(e, { id: "Remove" })
204
+ })
205
+ ]
206
+ }, n)),
207
+ /* @__PURE__ */ Q(l, {
208
+ type: "button",
209
+ variant: "outline",
210
+ onClick: () => y({ tax: [...d.tax, {
211
+ key: "",
212
+ value: ""
213
+ }] }),
214
+ children: /* @__PURE__ */ Q(e, { id: "Add tax detail" })
215
+ })
216
+ ]
217
+ })
218
+ ]
219
+ }),
220
+ p && /* @__PURE__ */ Q("p", {
221
+ role: "alert",
222
+ className: "text-destructive",
223
+ children: p
224
+ }),
225
+ h && /* @__PURE__ */ Q("p", {
226
+ role: "status",
227
+ className: "text-sm",
228
+ children: /* @__PURE__ */ Q(e, { id: "Invoice profile saved. Billed orders were not changed." })
229
+ }),
230
+ !i && /* @__PURE__ */ Q(l, {
231
+ type: "submit",
232
+ disabled: v.isPending,
233
+ children: v.isPending ? "Saving…" : "Save invoice profile"
234
+ })
235
+ ]
236
+ });
237
+ }
238
+ //#endregion
239
+ //#region src/admin/pages/customers/default-card-badges.tsx
240
+ function ye({ currencies: t = [] }) {
241
+ return /* @__PURE__ */ Q(ue, { children: t.map((t) => /* @__PURE__ */ $(S, {
242
+ variant: "secondary",
243
+ className: "mt-1 mr-1",
244
+ children: [/* @__PURE__ */ Q(e, { id: "Default · " }), t]
245
+ }, t)) });
246
+ }
247
+ //#endregion
248
+ //#region src/admin/pages/customers/credit-form.ts
249
+ function be(e, t = Date.now()) {
250
+ let n = b(e.amount, e.decimals);
251
+ if (n === null || BigInt(n) <= 0n) throw Error(`Enter a positive amount with at most ${e.decimals} decimal places, within the supported range.`);
252
+ let r = e.currency.trim();
253
+ if (!r) throw Error("Select a currency.");
254
+ let i;
255
+ if (e.expires) {
256
+ let n = new Date(e.expires).getTime();
257
+ if (!Number.isFinite(n) || n <= t) throw Error("Expiry must be a valid future date.");
258
+ i = new Date(n).toISOString();
259
+ }
260
+ return {
261
+ amount: n,
262
+ currency: r,
263
+ source: "admin",
264
+ source_id: e.sourceID,
265
+ expires_at: i,
266
+ description: e.description.trim() || void 0
267
+ };
268
+ }
269
+ function xe(e) {
270
+ return (e.state === "active" || e.state === "scheduled") && /^\d+$/.test(e.remaining_amount) && BigInt(e.remaining_amount) > 0n;
271
+ }
272
+ function Se(e, t) {
273
+ if (!xe(e)) throw Error("This grant has no remaining credit to revoke.");
274
+ if (t = t.trim(), !t || t.length > 500) throw Error("Enter a reason of up to 500 characters.");
275
+ return {
276
+ grant: e.id,
277
+ reason: t
278
+ };
279
+ }
280
+ //#endregion
281
+ //#region src/admin/pages/customers/credits.tsx
282
+ function Ce({ customerId: e, currencies: t }) {
283
+ let { activeMerchant: n } = p(), r = n?.slug ?? "";
284
+ return /* @__PURE__ */ Q(we, {
285
+ merchant: r,
286
+ customer: e,
287
+ initialCurrency: t[0] ?? "USD"
288
+ }, `${r}:${e}`);
289
+ }
290
+ function we({ merchant: r, customer: i, initialCurrency: o }) {
291
+ let { id: s, text: c } = t(), { creditQueries: f } = a(), p = d(), [m, g] = J.useState(o), [b, x] = J.useState(o), S = A(m, 25), C = A(m, 25), [w, T] = J.useState(!1), [E, D] = J.useState(null), O = X(f.grants(r, i, m, S.size, S.cursor)), k = X(f.transactions(r, i, m, C.size, C.cursor)), R = _(m);
292
+ return /* @__PURE__ */ $(q, { children: [
293
+ /* @__PURE__ */ $(W, {
294
+ className: "gap-3",
295
+ children: [
296
+ /* @__PURE__ */ $("div", {
297
+ className: "flex items-center justify-between gap-3",
298
+ children: [/* @__PURE__ */ Q(G, {
299
+ className: "text-sm",
300
+ children: /* @__PURE__ */ Q(e, { id: "Credits" })
301
+ }), p && /* @__PURE__ */ Q(l, {
302
+ variant: "outline",
303
+ size: "sm",
304
+ disabled: R === void 0,
305
+ onClick: () => T(!0),
306
+ children: /* @__PURE__ */ Q(e, { id: "Grant credit" })
307
+ })]
308
+ }),
309
+ /* @__PURE__ */ $("form", {
310
+ className: "flex max-w-sm items-end gap-2",
311
+ onSubmit: (e) => {
312
+ e.preventDefault();
313
+ let t = b.trim();
314
+ t && g(t.toUpperCase());
315
+ },
316
+ children: [/* @__PURE__ */ $("div", {
317
+ className: "grid gap-1",
318
+ children: [/* @__PURE__ */ Q(U, {
319
+ htmlFor: s("credit-currency"),
320
+ children: /* @__PURE__ */ Q(e, { id: "Currency" })
321
+ }), /* @__PURE__ */ Q(u, {
322
+ id: s("credit-currency"),
323
+ value: b,
324
+ onChange: (e) => x(e.target.value),
325
+ placeholder: c("USD")
326
+ })]
327
+ }), /* @__PURE__ */ Q(l, {
328
+ type: "submit",
329
+ variant: "outline",
330
+ size: "sm",
331
+ children: /* @__PURE__ */ Q(e, { id: "View" })
332
+ })]
333
+ }),
334
+ R === void 0 && /* @__PURE__ */ $("p", {
335
+ className: "text-xs text-muted-foreground",
336
+ children: [m, /* @__PURE__ */ Q(e, { id: " is not a supported currency." })]
337
+ })
338
+ ]
339
+ }),
340
+ /* @__PURE__ */ $(K, {
341
+ className: "grid gap-6",
342
+ children: [/* @__PURE__ */ $("section", {
343
+ "aria-label": c("Credit grants"),
344
+ children: [
345
+ /* @__PURE__ */ $("h3", {
346
+ className: "mb-2 text-sm font-medium",
347
+ children: [/* @__PURE__ */ Q(e, { id: "Grants · " }), m]
348
+ }),
349
+ O.isLoading ? /* @__PURE__ */ Q("p", {
350
+ className: "text-sm text-muted-foreground",
351
+ children: /* @__PURE__ */ Q(e, { id: "Loading grants…" })
352
+ }) : O.error ? /* @__PURE__ */ Q("p", {
353
+ role: "alert",
354
+ className: "text-sm text-destructive",
355
+ children: n(O.error).text
356
+ }) : O.data?.data.length ? /* @__PURE__ */ Q("div", {
357
+ className: "overflow-x-auto",
358
+ children: /* @__PURE__ */ $(L, { children: [/* @__PURE__ */ Q(P, { children: /* @__PURE__ */ $(I, { children: [
359
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Grant" }) }),
360
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Original" }) }),
361
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Remaining" }) }),
362
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Spent" }) }),
363
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Expired" }) }),
364
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Revoked" }) }),
365
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "State" }) }),
366
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Expires" }) }),
367
+ /* @__PURE__ */ Q(M, {})
368
+ ] }) }), /* @__PURE__ */ Q(N, { children: O.data.data.map((t) => /* @__PURE__ */ $(I, { children: [
369
+ /* @__PURE__ */ $(F, { children: [
370
+ /* @__PURE__ */ Q("span", {
371
+ title: t.id,
372
+ children: h(t.id)
373
+ }),
374
+ /* @__PURE__ */ Q("div", {
375
+ className: "text-xs text-muted-foreground",
376
+ children: v(t.created_at)
377
+ }),
378
+ /* @__PURE__ */ Q("div", {
379
+ className: "text-xs text-muted-foreground",
380
+ children: t.description ?? t.source_type
381
+ })
382
+ ] }),
383
+ [
384
+ t.amount,
385
+ t.remaining_amount,
386
+ t.spent_amount,
387
+ t.expired_amount,
388
+ t.revoked_amount
389
+ ].map((e, n) => /* @__PURE__ */ Q(F, {
390
+ className: "tabular-nums",
391
+ children: y(e, t.currency)
392
+ }, n)),
393
+ /* @__PURE__ */ Q(F, { children: t.state }),
394
+ /* @__PURE__ */ Q(F, { children: t.expires_at ? v(t.expires_at) : "No expiry" }),
395
+ /* @__PURE__ */ Q(F, { children: p && /* @__PURE__ */ Q(l, {
396
+ size: "sm",
397
+ variant: "outline",
398
+ disabled: !xe(t),
399
+ onClick: () => D(t),
400
+ children: /* @__PURE__ */ Q(e, { id: "Revoke" })
401
+ }) })
402
+ ] }, t.id)) })] })
403
+ }) : /* @__PURE__ */ Q("p", {
404
+ className: "text-sm text-muted-foreground",
405
+ children: /* @__PURE__ */ Q(e, { id: "No credit grants in this currency." })
406
+ }),
407
+ /* @__PURE__ */ Q(j, {
408
+ pages: S,
409
+ rows: O.data?.data?.length ?? 0,
410
+ nextCursor: O.data?.next_cursor,
411
+ busy: O.isFetching
412
+ })
413
+ ]
414
+ }), /* @__PURE__ */ $("section", {
415
+ "aria-label": c("Credit transaction ledger"),
416
+ children: [
417
+ /* @__PURE__ */ $("h3", {
418
+ className: "mb-2 text-sm font-medium",
419
+ children: [/* @__PURE__ */ Q(e, { id: "Transaction ledger · " }), m]
420
+ }),
421
+ k.isLoading ? /* @__PURE__ */ Q("p", {
422
+ className: "text-sm text-muted-foreground",
423
+ children: /* @__PURE__ */ Q(e, { id: "Loading transactions…" })
424
+ }) : k.error ? /* @__PURE__ */ Q("p", {
425
+ role: "alert",
426
+ className: "text-sm text-destructive",
427
+ children: n(k.error).text
428
+ }) : k.data?.data.length ? /* @__PURE__ */ $(L, { children: [/* @__PURE__ */ Q(P, { children: /* @__PURE__ */ $(I, { children: [
429
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Date" }) }),
430
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Type" }) }),
431
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Amount" }) }),
432
+ /* @__PURE__ */ Q(M, { children: /* @__PURE__ */ Q(e, { id: "Source" }) })
433
+ ] }) }), /* @__PURE__ */ Q(N, { children: k.data.data.map((e) => /* @__PURE__ */ $(I, { children: [
434
+ /* @__PURE__ */ Q(F, {
435
+ title: e.id,
436
+ children: v(e.created_at)
437
+ }),
438
+ /* @__PURE__ */ Q(F, { children: e.type.replaceAll("_", " ") }),
439
+ /* @__PURE__ */ Q(F, {
440
+ className: "tabular-nums",
441
+ children: y(e.amount, e.currency)
442
+ }),
443
+ /* @__PURE__ */ Q(F, { children: e.source || "—" })
444
+ ] }, e.id)) })] }) : /* @__PURE__ */ Q("p", {
445
+ className: "text-sm text-muted-foreground",
446
+ children: /* @__PURE__ */ Q(e, { id: "No transactions in this currency." })
447
+ }),
448
+ /* @__PURE__ */ Q(j, {
449
+ pages: C,
450
+ rows: k.data?.data?.length ?? 0,
451
+ nextCursor: k.data?.next_cursor,
452
+ busy: k.isFetching
453
+ })
454
+ ]
455
+ })]
456
+ }),
457
+ w && R !== void 0 && /* @__PURE__ */ Q(Te, {
458
+ merchant: r,
459
+ customer: i,
460
+ currency: m,
461
+ decimals: R,
462
+ onClose: () => T(!1)
463
+ }),
464
+ E && /* @__PURE__ */ Q(Ee, {
465
+ merchant: r,
466
+ customer: i,
467
+ grant: E,
468
+ onClose: () => D(null)
469
+ })
470
+ ] });
471
+ }
472
+ function Te({ merchant: r, customer: i, currency: o, decimals: s, onClose: c }) {
473
+ let { toast: d, creditMutations: f } = a(), { id: p } = t(), m = Z(), h = Y(f.grant(m, r, i)), [g, _] = J.useState(""), [v, y] = J.useState(""), [b, x] = J.useState(""), [S] = J.useState(() => crypto.randomUUID()), [C, w] = J.useState("");
474
+ return /* @__PURE__ */ Q(ne, {
475
+ open: !0,
476
+ onOpenChange: (e) => {
477
+ !e && !h.isPending && c();
478
+ },
479
+ children: /* @__PURE__ */ $(V, {
480
+ className: re,
481
+ children: [/* @__PURE__ */ $(z, { children: [/* @__PURE__ */ Q(H, { children: /* @__PURE__ */ Q(e, { id: "Grant credit" }) }), /* @__PURE__ */ $(ee, { children: [
482
+ /* @__PURE__ */ Q(e, { id: "Add credit in " }),
483
+ o,
484
+ /* @__PURE__ */ Q(e, { id: " to this customer." })
485
+ ] })] }), /* @__PURE__ */ $("form", {
486
+ className: "grid gap-4",
487
+ onSubmit: async (e) => {
488
+ e.preventDefault(), w("");
489
+ try {
490
+ let e = be({
491
+ amount: g,
492
+ currency: o,
493
+ decimals: s,
494
+ expires: v,
495
+ description: b,
496
+ sourceID: S
497
+ });
498
+ await h.mutateAsync(e), d.success("Credit granted"), c();
499
+ } catch (e) {
500
+ w(n(e).text);
501
+ }
502
+ },
503
+ children: [
504
+ /* @__PURE__ */ $("div", {
505
+ className: "grid gap-1",
506
+ children: [/* @__PURE__ */ $(U, {
507
+ htmlFor: p("grant-amount"),
508
+ children: [
509
+ /* @__PURE__ */ Q(e, { id: "Amount (" }),
510
+ o,
511
+ ")"
512
+ ]
513
+ }), /* @__PURE__ */ Q(u, {
514
+ id: p("grant-amount"),
515
+ inputMode: "decimal",
516
+ value: g,
517
+ onChange: (e) => _(e.target.value),
518
+ autoFocus: !0
519
+ })]
520
+ }),
521
+ /* @__PURE__ */ $("div", {
522
+ className: "grid gap-1",
523
+ children: [/* @__PURE__ */ Q(U, {
524
+ htmlFor: p("grant-expiry"),
525
+ children: /* @__PURE__ */ Q(e, { id: "Expires (optional)" })
526
+ }), /* @__PURE__ */ Q(u, {
527
+ id: p("grant-expiry"),
528
+ type: "datetime-local",
529
+ value: v,
530
+ onChange: (e) => y(e.target.value)
531
+ })]
532
+ }),
533
+ /* @__PURE__ */ $("div", {
534
+ className: "grid gap-1",
535
+ children: [/* @__PURE__ */ Q(U, {
536
+ htmlFor: p("grant-description"),
537
+ children: /* @__PURE__ */ Q(e, { id: "Description (optional)" })
538
+ }), /* @__PURE__ */ Q(u, {
539
+ id: p("grant-description"),
540
+ value: b,
541
+ onChange: (e) => x(e.target.value),
542
+ maxLength: 500
543
+ })]
544
+ }),
545
+ C && /* @__PURE__ */ Q("p", {
546
+ role: "alert",
547
+ className: "text-sm text-destructive",
548
+ children: C
549
+ }),
550
+ /* @__PURE__ */ $(B, { children: [/* @__PURE__ */ Q(l, {
551
+ type: "button",
552
+ variant: "outline",
553
+ disabled: h.isPending,
554
+ onClick: c,
555
+ children: /* @__PURE__ */ Q(e, { id: "Cancel" })
556
+ }), /* @__PURE__ */ Q(l, {
557
+ type: "submit",
558
+ disabled: h.isPending,
559
+ children: h.isPending ? "Granting…" : "Grant credit"
560
+ })] })
561
+ ]
562
+ })]
563
+ })
564
+ });
565
+ }
566
+ function Ee({ merchant: r, customer: i, grant: o, onClose: s }) {
567
+ let { toast: c, creditMutations: d } = a(), { id: f } = t(), p = Z(), m = Y(d.revoke(p, r, i)), [h, g] = J.useState(""), [_, v] = J.useState("");
568
+ return /* @__PURE__ */ Q(ne, {
569
+ open: !0,
570
+ onOpenChange: (e) => {
571
+ !e && !m.isPending && s();
572
+ },
573
+ children: /* @__PURE__ */ $(V, {
574
+ className: re,
575
+ children: [/* @__PURE__ */ $(z, { children: [/* @__PURE__ */ Q(H, { children: /* @__PURE__ */ Q(e, { id: "Revoke remaining credit" }) }), /* @__PURE__ */ $(ee, { children: [
576
+ /* @__PURE__ */ Q(e, { id: "Revoke the unspent remainder of" }),
577
+ " ",
578
+ y(o.remaining_amount, o.currency),
579
+ /* @__PURE__ */ Q(e, { id: ". Active holds may prevent revocation. Payment refunds are managed separately." })
580
+ ] })] }), /* @__PURE__ */ $("form", {
581
+ className: "grid gap-4",
582
+ onSubmit: async (e) => {
583
+ e.preventDefault(), v("");
584
+ try {
585
+ let e = await m.mutateAsync(Se(o, h));
586
+ c.success(e.replayed ? "Credit was already revoked" : `${y(e.revoked_amount, e.currency)} revoked`), s();
587
+ } catch (e) {
588
+ v(n(e).text);
589
+ }
590
+ },
591
+ children: [
592
+ /* @__PURE__ */ $("div", {
593
+ className: "grid gap-1",
594
+ children: [/* @__PURE__ */ Q(U, {
595
+ htmlFor: f("revoke-reason"),
596
+ children: /* @__PURE__ */ Q(e, { id: "Reason" })
597
+ }), /* @__PURE__ */ Q(u, {
598
+ id: f("revoke-reason"),
599
+ value: h,
600
+ onChange: (e) => g(e.target.value),
601
+ maxLength: 500,
602
+ autoFocus: !0
603
+ })]
604
+ }),
605
+ _ && /* @__PURE__ */ Q("p", {
606
+ role: "alert",
607
+ className: "text-sm text-destructive",
608
+ children: _
609
+ }),
610
+ /* @__PURE__ */ $(B, { children: [/* @__PURE__ */ Q(l, {
611
+ type: "button",
612
+ variant: "outline",
613
+ disabled: m.isPending,
614
+ onClick: s,
615
+ children: /* @__PURE__ */ Q(e, { id: "Cancel" })
616
+ }), /* @__PURE__ */ Q(l, {
617
+ type: "submit",
618
+ variant: "destructive",
619
+ disabled: !xe(o) || m.isPending,
620
+ children: m.isPending ? "Revoking…" : "Revoke credit"
621
+ })] })
622
+ ]
623
+ })]
624
+ })
625
+ });
626
+ }
627
+ //#endregion
628
+ //#region src/admin/pages/customers/grant-duration.ts
629
+ var De = [
630
+ {
631
+ value: "1",
632
+ label: "1 day",
633
+ days: 1
634
+ },
635
+ {
636
+ value: "7",
637
+ label: "7 days",
638
+ days: 7
639
+ },
640
+ {
641
+ value: "30",
642
+ label: "30 days",
643
+ days: 30
644
+ },
645
+ {
646
+ value: "365",
647
+ label: "365 days",
648
+ days: 365
649
+ },
650
+ {
651
+ value: "until",
652
+ label: "Until a date"
653
+ },
654
+ {
655
+ value: "never",
656
+ label: "Never expires"
657
+ }
658
+ ], Oe = (e) => e.toISOString().slice(0, 10);
659
+ function ke(e, t, n = /* @__PURE__ */ new Date()) {
660
+ if (e === "never") return {};
661
+ if (e === "until") {
662
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(t) || t < Oe(n)) return null;
663
+ let e = /* @__PURE__ */ new Date(`${t}T00:00:00Z`);
664
+ return e.setUTCDate(e.getUTCDate() + 1), { endsAt: e.toISOString() };
665
+ }
666
+ let r = De.find((t) => t.value === e);
667
+ return r && "days" in r ? { hours: r.days * 24 } : null;
668
+ }
669
+ //#endregion
670
+ //#region src/admin/pages/customers/detail.tsx
671
+ function Ae() {
672
+ let { text: n } = t(), { props: c } = i(), { adminQueries: u } = a(), p = d(), m = f(), { customerId: h = "" } = r(), g = s(), { data: _, isPending: b, error: x } = X(u.customer(h));
673
+ return b ? /* @__PURE__ */ Q("p", {
674
+ className: "text-sm text-muted-foreground",
675
+ children: /* @__PURE__ */ Q(e, { id: "Loading…" })
676
+ }) : _ ? /* @__PURE__ */ $("div", {
677
+ className: "flex min-w-0 flex-col gap-4",
678
+ children: [
679
+ /* @__PURE__ */ $("div", {
680
+ className: "flex flex-wrap items-center gap-3",
681
+ children: [
682
+ /* @__PURE__ */ Q(l, {
683
+ variant: "ghost",
684
+ size: "icon",
685
+ onClick: () => g(-1),
686
+ "aria-label": n("Back"),
687
+ children: /* @__PURE__ */ Q(de, {
688
+ icon: pe,
689
+ className: "size-4"
690
+ })
691
+ }),
692
+ /* @__PURE__ */ $("div", {
693
+ className: "min-w-0 flex-1",
694
+ children: [/* @__PURE__ */ Q("h1", {
695
+ className: "text-2xl font-semibold tracking-tight [overflow-wrap:anywhere]",
696
+ children: _.contact?.name || _.contact?.email || "Customer"
697
+ }), /* @__PURE__ */ $("p", {
698
+ className: "text-xs [overflow-wrap:anywhere] text-muted-foreground",
699
+ children: [
700
+ _.id,
701
+ /* @__PURE__ */ Q(e, { id: " · since " }),
702
+ v(_.created_at),
703
+ /* @__PURE__ */ Q(e, { id: " · last seen" }),
704
+ " ",
705
+ v(_.last_seen_at)
706
+ ]
707
+ })]
708
+ }),
709
+ p && /* @__PURE__ */ Q("div", {
710
+ className: "flex gap-2 @max-[36rem]/page:w-full",
711
+ children: /* @__PURE__ */ Q(Le, { customerId: h })
712
+ })
713
+ ]
714
+ }),
715
+ /* @__PURE__ */ Q(Re, { contact: _.contact }),
716
+ c.userHref && /* @__PURE__ */ Q("a", {
717
+ className: "underline",
718
+ href: c.userHref(_.id),
719
+ children: /* @__PURE__ */ Q(e, { id: "View user account" })
720
+ }),
721
+ c.customerPanels?.(_),
722
+ _.balances.length > 0 && /* @__PURE__ */ Q("div", {
723
+ className: "grid gap-3 grid-cols-[minmax(0,1fr)] @min-[20.75rem]/page:grid-cols-2 @min-[42.25rem]/page:grid-cols-4",
724
+ children: _.balances.map((t) => /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, {
725
+ className: "pb-1",
726
+ children: /* @__PURE__ */ $(G, {
727
+ className: "text-xs font-normal text-muted-foreground uppercase",
728
+ children: [t.currency, /* @__PURE__ */ Q(e, { id: " balance" })]
729
+ })
730
+ }), /* @__PURE__ */ $(K, { children: [/* @__PURE__ */ Q("p", {
731
+ className: "text-lg font-semibold",
732
+ children: y(t.balance_amount, t.currency)
733
+ }), /* @__PURE__ */ $("p", {
734
+ className: "text-xs text-muted-foreground",
735
+ children: [
736
+ /* @__PURE__ */ Q(e, { id: "held " }),
737
+ y(t.held_amount, t.currency),
738
+ /* @__PURE__ */ Q(e, { id: " · owed" }),
739
+ " ",
740
+ y(t.owed_amount, t.currency)
741
+ ]
742
+ })] })] }, t.currency))
743
+ }),
744
+ _.balances.some((e) => BigInt(e.owed_amount) > 0n) && /* @__PURE__ */ Q("p", {
745
+ className: "text-sm",
746
+ children: /* @__PURE__ */ Q(o, {
747
+ className: "underline-offset-2 hover:underline",
748
+ to: `/orders?customer_id=${_.id}&origin=usage&overdue=true`,
749
+ children: /* @__PURE__ */ Q(e, { id: "Overdue usage orders" })
750
+ })
751
+ }),
752
+ m?.credit && /* @__PURE__ */ Q(Ce, {
753
+ customerId: h,
754
+ currencies: _.balances.map((e) => e.currency)
755
+ }),
756
+ m?.usage && /* @__PURE__ */ Q(_e, { customerId: h }),
757
+ /* @__PURE__ */ $("div", {
758
+ className: "grid gap-4 @min-[56rem]/page:grid-cols-3 @min-[56rem]/page:items-start",
759
+ children: [/* @__PURE__ */ $("div", {
760
+ className: "grid gap-4 @min-[56rem]/page:col-span-2",
761
+ children: [
762
+ /* @__PURE__ */ Q(je, { customerId: h }),
763
+ /* @__PURE__ */ Q(Me, { customerId: h }),
764
+ /* @__PURE__ */ Q(Ne, { customerId: h })
765
+ ]
766
+ }), /* @__PURE__ */ $("div", {
767
+ className: "grid gap-4",
768
+ children: [/* @__PURE__ */ Q(Pe, { customerId: h }), /* @__PURE__ */ Q(Fe, { customerId: h })]
769
+ })]
770
+ })
771
+ ]
772
+ }) : /* @__PURE__ */ Q(ce, {
773
+ title: "Customer not found",
774
+ error: x,
775
+ back: "/customers",
776
+ backLabel: "Customers"
777
+ });
778
+ }
779
+ function je({ customerId: t }) {
780
+ let { adminQueries: n } = a(), r = A(t, 25), { data: i, isFetching: s } = X(n.customerSubscriptions(t, r.size, r.cursor)), c = i?.data ?? [];
781
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, { children: /* @__PURE__ */ Q(G, {
782
+ className: "text-sm",
783
+ children: /* @__PURE__ */ Q(e, { id: "Subscriptions" })
784
+ }) }), /* @__PURE__ */ $(K, {
785
+ className: "grid gap-3",
786
+ children: [c.length === 0 ? /* @__PURE__ */ Q("p", {
787
+ className: "text-sm text-muted-foreground",
788
+ children: /* @__PURE__ */ Q(e, { id: "No subscriptions." })
789
+ }) : /* @__PURE__ */ $(L, { children: [/* @__PURE__ */ Q(P, { children: /* @__PURE__ */ $(I, {
790
+ className: "hover:bg-transparent",
791
+ children: [
792
+ /* @__PURE__ */ Q(M, {
793
+ className: "text-muted-foreground",
794
+ children: /* @__PURE__ */ Q(e, { id: "Subscription" })
795
+ }),
796
+ /* @__PURE__ */ Q(M, {
797
+ className: "text-muted-foreground",
798
+ children: /* @__PURE__ */ Q(e, { id: "Status" })
799
+ }),
800
+ /* @__PURE__ */ Q(M, {
801
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
802
+ children: /* @__PURE__ */ Q(e, { id: "Rail" })
803
+ }),
804
+ /* @__PURE__ */ Q(M, {
805
+ className: "text-muted-foreground",
806
+ children: /* @__PURE__ */ Q(e, { id: "Period ends" })
807
+ }),
808
+ /* @__PURE__ */ Q(M, {
809
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
810
+ children: /* @__PURE__ */ Q(e, { id: "Dunning" })
811
+ })
812
+ ]
813
+ }) }), /* @__PURE__ */ Q(N, { children: c.map((e) => /* @__PURE__ */ $(R, {
814
+ to: `/subscriptions/${e.id}`,
815
+ children: [
816
+ /* @__PURE__ */ Q(F, { children: /* @__PURE__ */ Q(o, {
817
+ className: "text-xs underline-offset-2 hover:underline",
818
+ to: `/subscriptions/${e.id}`,
819
+ children: e.product?.display_name ?? h(e.id, 13)
820
+ }) }),
821
+ /* @__PURE__ */ Q(F, { children: /* @__PURE__ */ Q(C, { status: e.status }) }),
822
+ /* @__PURE__ */ Q(F, {
823
+ className: "@max-[36rem]/page:hidden",
824
+ children: e.rail
825
+ }),
826
+ /* @__PURE__ */ Q(F, {
827
+ className: "tabular-nums @max-[36rem]/page:whitespace-normal",
828
+ children: v(e.current_period_ends_at)
829
+ }),
830
+ /* @__PURE__ */ Q(F, {
831
+ className: "text-xs @max-[36rem]/page:hidden",
832
+ children: e.dunning ? se(e.dunning) : "—"
833
+ })
834
+ ]
835
+ }, e.id)) })] }), /* @__PURE__ */ Q(j, {
836
+ pages: r,
837
+ rows: i?.data?.length ?? 0,
838
+ nextCursor: i?.next_cursor,
839
+ busy: s
840
+ })]
841
+ })] });
842
+ }
843
+ function Me({ customerId: t }) {
844
+ let { adminQueries: n, orderQueries: r } = a(), i = A(t, 25), { data: s, isFetching: c } = X(n.customerPayments(t, i.size, i.cursor)), l = s?.data ?? [], u = [...new Set(l.flatMap((e) => e.order_id ? [e.order_id] : []))], { data: d } = X(r.byIds(u)), f = new Map((d?.data ?? []).map((e) => [e.id, e.lines[0]?.description]));
845
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, { children: /* @__PURE__ */ Q(G, {
846
+ className: "text-sm",
847
+ children: /* @__PURE__ */ Q(e, { id: "Payments" })
848
+ }) }), /* @__PURE__ */ $(K, {
849
+ className: "grid gap-3",
850
+ children: [l.length === 0 ? /* @__PURE__ */ Q("p", {
851
+ className: "text-sm text-muted-foreground",
852
+ children: /* @__PURE__ */ Q(e, { id: "No payments." })
853
+ }) : /* @__PURE__ */ $(L, { children: [/* @__PURE__ */ Q(P, { children: /* @__PURE__ */ $(I, {
854
+ className: "hover:bg-transparent",
855
+ children: [
856
+ /* @__PURE__ */ Q(M, {
857
+ className: "text-muted-foreground",
858
+ children: /* @__PURE__ */ Q(e, { id: "Payment" })
859
+ }),
860
+ /* @__PURE__ */ Q(M, {
861
+ className: "text-muted-foreground",
862
+ children: /* @__PURE__ */ Q(e, { id: "Status" })
863
+ }),
864
+ /* @__PURE__ */ Q(M, {
865
+ className: "text-muted-foreground",
866
+ children: /* @__PURE__ */ Q(e, { id: "Amount" })
867
+ }),
868
+ /* @__PURE__ */ Q(M, {
869
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
870
+ children: /* @__PURE__ */ Q(e, { id: "Kind" })
871
+ }),
872
+ /* @__PURE__ */ Q(M, {
873
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
874
+ children: /* @__PURE__ */ Q(e, { id: "Rail" })
875
+ }),
876
+ /* @__PURE__ */ Q(M, {
877
+ className: "text-muted-foreground @max-[36rem]/page:hidden",
878
+ children: /* @__PURE__ */ Q(e, { id: "Purchased" })
879
+ })
880
+ ]
881
+ }) }), /* @__PURE__ */ Q(N, { children: l.map((e) => /* @__PURE__ */ $(R, {
882
+ to: `/payments/${e.id}`,
883
+ children: [
884
+ /* @__PURE__ */ Q(F, { children: /* @__PURE__ */ Q(o, {
885
+ className: "text-xs underline-offset-2 hover:underline",
886
+ to: `/payments/${e.id}`,
887
+ children: e.order_id && f.get(e.order_id) || h(e.id, 13)
888
+ }) }),
889
+ /* @__PURE__ */ Q(F, { children: /* @__PURE__ */ Q(C, { status: e.status }) }),
890
+ /* @__PURE__ */ Q(F, {
891
+ className: "tabular-nums",
892
+ children: y(e.amount, e.currency)
893
+ }),
894
+ /* @__PURE__ */ Q(F, {
895
+ className: "@max-[36rem]/page:hidden",
896
+ children: e.kind
897
+ }),
898
+ /* @__PURE__ */ Q(F, {
899
+ className: "@max-[36rem]/page:hidden",
900
+ children: e.rail ?? e.channel
901
+ }),
902
+ /* @__PURE__ */ Q(F, {
903
+ className: "tabular-nums @max-[36rem]/page:hidden",
904
+ children: v(e.created_at)
905
+ })
906
+ ]
907
+ }, e.id)) })] }), /* @__PURE__ */ Q(j, {
908
+ pages: i,
909
+ rows: s?.data?.length ?? 0,
910
+ nextCursor: s?.next_cursor,
911
+ busy: c
912
+ })]
913
+ })] });
914
+ }
915
+ function Ne({ customerId: n }) {
916
+ let { adminQueries: r, queryKeys: i, deleteCustomerPaymentMethod: o, toast: s, toastApiError: u } = a(), { text: f } = t(), p = d(), h = x(), _ = Z(), v = Y({
917
+ mutationFn: (e) => o(n, e),
918
+ onSuccess: () => _.invalidateQueries({ queryKey: [...i.customer(n), "payment-methods"] }),
919
+ onError: (e) => u(e, "Remove payment method")
920
+ }), y = A(n, 25), { data: b, isFetching: C } = X(r.customerPaymentMethodsPage(n, y.size, y.cursor)), w = b?.data ?? [];
921
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ $(W, { children: [/* @__PURE__ */ Q(G, {
922
+ className: "text-sm",
923
+ children: /* @__PURE__ */ Q(e, { id: "Payment methods" })
924
+ }), /* @__PURE__ */ $(l, {
925
+ variant: "ghost",
926
+ size: "sm",
927
+ disabled: C,
928
+ onClick: async () => {
929
+ await _.invalidateQueries({ queryKey: [...i.customer(n), "payment-methods"] }), s.success(f("Payment methods are up to date"));
930
+ },
931
+ children: [/* @__PURE__ */ Q(de, {
932
+ icon: he,
933
+ className: c("size-3.5", C && "animate-spin")
934
+ }), f(C ? "Refreshing…" : "Refresh payment methods")]
935
+ })] }), /* @__PURE__ */ $(K, {
936
+ className: "grid gap-3",
937
+ children: [w.length === 0 ? /* @__PURE__ */ Q("p", {
938
+ className: "text-sm text-muted-foreground",
939
+ children: /* @__PURE__ */ Q(e, { id: "No payment methods on file." })
940
+ }) : /* @__PURE__ */ Q("div", {
941
+ className: "flex flex-wrap gap-3",
942
+ children: w.map((t) => /* @__PURE__ */ $("div", {
943
+ className: "rounded-md border p-3 text-sm",
944
+ children: [
945
+ /* @__PURE__ */ Q("p", {
946
+ className: "font-medium",
947
+ children: g(t.card)
948
+ }),
949
+ /* @__PURE__ */ $("p", {
950
+ className: "text-xs text-muted-foreground",
951
+ children: [
952
+ t.rail,
953
+ /* @__PURE__ */ Q(e, { id: " · exp " }),
954
+ m(t.card)
955
+ ]
956
+ }),
957
+ /* @__PURE__ */ Q(ye, { currencies: t.default_currencies ?? [] }),
958
+ p && t.rail === "nmi" && t.status !== "removed" && /* @__PURE__ */ Q(l, {
959
+ size: "sm",
960
+ variant: "outline",
961
+ className: "mt-2",
962
+ disabled: v.isPending,
963
+ onClick: async () => {
964
+ await h({
965
+ title: "Remove this saved card?",
966
+ description: "The vault will remove the card once no active subscription or payment uses it. Transaction history remains.",
967
+ confirmLabel: "Remove saved card"
968
+ }) && v.mutate(t.id);
969
+ },
970
+ children: "Remove saved card"
971
+ }),
972
+ t.health.expiry_status && t.health.expiry_status !== "valid" && /* @__PURE__ */ Q(S, {
973
+ variant: "secondary",
974
+ className: "bg-held-surface text-held mt-1",
975
+ children: t.health.expiry_status
976
+ })
977
+ ]
978
+ }, t.id))
979
+ }), /* @__PURE__ */ Q(j, {
980
+ pages: y,
981
+ rows: b?.data?.length ?? 0,
982
+ nextCursor: b?.next_cursor,
983
+ busy: C
984
+ })]
985
+ })] });
986
+ }
987
+ function Pe({ customerId: t }) {
988
+ let { adminQueries: n } = a(), r = A(t, 25), { data: i, isFetching: o } = X(n.customerEntitlements(t, r.size, r.cursor)), s = i?.data ?? [];
989
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, { children: /* @__PURE__ */ Q(G, {
990
+ className: "text-sm",
991
+ children: /* @__PURE__ */ Q(e, { id: "Entitlements" })
992
+ }) }), /* @__PURE__ */ $(K, {
993
+ className: "grid gap-3",
994
+ children: [
995
+ /* @__PURE__ */ Q("p", {
996
+ className: "text-xs text-muted-foreground",
997
+ children: /* @__PURE__ */ Q(e, { id: "The keys of the products this customer holds now." })
998
+ }),
999
+ s.length === 0 ? /* @__PURE__ */ Q("p", {
1000
+ className: "text-sm text-muted-foreground",
1001
+ children: /* @__PURE__ */ Q(e, { id: "No entitlements." })
1002
+ }) : /* @__PURE__ */ Q("div", {
1003
+ className: "flex flex-wrap gap-2",
1004
+ children: s.map((e) => /* @__PURE__ */ Q(S, {
1005
+ variant: "secondary",
1006
+ children: e.entitlement
1007
+ }, e.entitlement))
1008
+ }),
1009
+ /* @__PURE__ */ Q(j, {
1010
+ pages: r,
1011
+ rows: i?.data?.length ?? 0,
1012
+ nextCursor: i?.next_cursor,
1013
+ busy: o
1014
+ })
1015
+ ]
1016
+ })] });
1017
+ }
1018
+ function Fe({ customerId: n }) {
1019
+ let { text: r } = t(), { adminQueries: i } = a(), o = d(), s = A(n, 25), { data: c, isFetching: l } = X(i.customerProductAccess(n, s.size, s.cursor)), u = c?.data ?? [];
1020
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, { children: /* @__PURE__ */ Q(G, {
1021
+ className: "text-sm",
1022
+ children: /* @__PURE__ */ Q(e, { id: "Product access" })
1023
+ }) }), /* @__PURE__ */ $(K, {
1024
+ className: "grid gap-3",
1025
+ children: [u.length === 0 ? /* @__PURE__ */ Q("p", {
1026
+ className: "text-sm text-muted-foreground",
1027
+ children: /* @__PURE__ */ Q(e, { id: "No product access." })
1028
+ }) : /* @__PURE__ */ Q("div", {
1029
+ className: "grid gap-4",
1030
+ children: u.map((e) => /* @__PURE__ */ $("div", {
1031
+ className: "flex min-w-0 items-start gap-3",
1032
+ children: [/* @__PURE__ */ $("div", {
1033
+ className: "min-w-0 flex-1",
1034
+ children: [
1035
+ /* @__PURE__ */ $("div", {
1036
+ className: "flex min-w-0 items-center gap-2",
1037
+ children: [/* @__PURE__ */ Q("p", {
1038
+ className: "truncate text-sm font-medium",
1039
+ children: e.product_name || h(e.product_id, 13)
1040
+ }), /* @__PURE__ */ Q(C, { status: e.status })]
1041
+ }),
1042
+ /* @__PURE__ */ Q("p", {
1043
+ className: "mt-1 text-xs text-muted-foreground",
1044
+ children: e.source_type === "grant" ? `Granted (${e.grant_reason ?? "staff"})${e.note ? `: ${e.note}` : ""}` : e.source_type
1045
+ }),
1046
+ /* @__PURE__ */ Q("p", {
1047
+ className: "text-xs text-muted-foreground tabular-nums",
1048
+ children: e.ends_at ? `Ends ${v(e.ends_at)}` : "No end date"
1049
+ })
1050
+ ]
1051
+ }), o && /* @__PURE__ */ Q(Ie, {
1052
+ customerId: n,
1053
+ grantId: e.id,
1054
+ label: r("Revoke product access")
1055
+ })]
1056
+ }, e.id))
1057
+ }), /* @__PURE__ */ Q(j, {
1058
+ pages: s,
1059
+ rows: c?.data?.length ?? 0,
1060
+ nextCursor: c?.next_cursor,
1061
+ busy: l
1062
+ })]
1063
+ })] });
1064
+ }
1065
+ function Ie({ customerId: n, grantId: r, label: i }) {
1066
+ let { toast: o, toastApiError: s, adminMutations: c } = a(), { id: d } = t(), f = Z(), p = Y(c.revokeCustomerProductAccess(f, n)), [m, h] = J.useState(!1), [g, _] = J.useState("");
1067
+ return /* @__PURE__ */ $(ne, {
1068
+ open: m,
1069
+ onOpenChange: h,
1070
+ children: [/* @__PURE__ */ Q(te, { render: /* @__PURE__ */ Q(l, {
1071
+ variant: "ghost",
1072
+ size: "icon",
1073
+ "aria-label": i,
1074
+ children: /* @__PURE__ */ Q(de, {
1075
+ icon: me,
1076
+ className: "size-4 text-destructive"
1077
+ })
1078
+ }) }), /* @__PURE__ */ $(V, {
1079
+ className: ie,
1080
+ children: [
1081
+ /* @__PURE__ */ $(z, { children: [/* @__PURE__ */ Q(H, { children: /* @__PURE__ */ Q(e, { id: "Take the product back" }) }), /* @__PURE__ */ Q(ee, { children: /* @__PURE__ */ Q(e, { id: "The customer loses its entitlements now. The grant stays on record with your reason." }) })] }),
1082
+ /* @__PURE__ */ $("div", {
1083
+ className: "flex flex-col gap-1.5",
1084
+ children: [/* @__PURE__ */ Q(U, {
1085
+ htmlFor: d("revoke-access-reason"),
1086
+ children: /* @__PURE__ */ Q(e, { id: "Reason" })
1087
+ }), /* @__PURE__ */ Q(u, {
1088
+ id: d("revoke-access-reason"),
1089
+ value: g,
1090
+ onChange: (e) => _(e.target.value),
1091
+ maxLength: 500
1092
+ })]
1093
+ }),
1094
+ /* @__PURE__ */ $(B, { children: [/* @__PURE__ */ Q(l, {
1095
+ variant: "outline",
1096
+ onClick: () => h(!1),
1097
+ children: /* @__PURE__ */ Q(e, { id: "Cancel" })
1098
+ }), /* @__PURE__ */ Q(l, {
1099
+ variant: "destructive",
1100
+ disabled: !g.trim() || p.isPending,
1101
+ onClick: async () => {
1102
+ try {
1103
+ await p.mutateAsync({
1104
+ grantId: r,
1105
+ reason: g.trim()
1106
+ }), o.success("Product access revoked"), h(!1);
1107
+ } catch (e) {
1108
+ s(e, i);
1109
+ }
1110
+ },
1111
+ children: p.isPending ? "Revoking…" : "Revoke"
1112
+ })] })
1113
+ ]
1114
+ })]
1115
+ });
1116
+ }
1117
+ function Le({ customerId: n }) {
1118
+ let { toast: r, toastApiError: i, adminMutations: o, adminQueries: s } = a(), { id: c, text: d } = t(), [f, p] = J.useState(!1), m = Z(), h = Y(o.grantCustomerProductAccess(m, n)), { data: g } = X({
1119
+ ...s.allProducts(),
1120
+ enabled: f
1121
+ }), _ = ge({
1122
+ defaultValues: {
1123
+ productId: "",
1124
+ duration: "30",
1125
+ until: "",
1126
+ note: ""
1127
+ },
1128
+ onSubmit: async ({ value: e }) => {
1129
+ let t = ke(e.duration, e.until);
1130
+ if (t) try {
1131
+ await h.mutateAsync({
1132
+ productId: e.productId,
1133
+ ...t,
1134
+ note: e.note.trim() || void 0
1135
+ }), r.success("Product access granted"), v(!1);
1136
+ } catch (e) {
1137
+ i(e, "Grant product access");
1138
+ }
1139
+ }
1140
+ }), v = (e) => {
1141
+ p(e), e || (_.reset(), h.reset());
1142
+ };
1143
+ return /* @__PURE__ */ $(ne, {
1144
+ open: f,
1145
+ onOpenChange: v,
1146
+ children: [/* @__PURE__ */ Q(te, { render: /* @__PURE__ */ $(l, {
1147
+ variant: "outline",
1148
+ size: "sm",
1149
+ children: [/* @__PURE__ */ Q(de, {
1150
+ icon: fe,
1151
+ className: "size-4"
1152
+ }), /* @__PURE__ */ Q(e, { id: " Product access" })]
1153
+ }) }), /* @__PURE__ */ $(V, {
1154
+ className: ie,
1155
+ children: [/* @__PURE__ */ $(z, { children: [/* @__PURE__ */ Q(H, { children: /* @__PURE__ */ Q(e, { id: "Grant product access" }) }), /* @__PURE__ */ Q(ee, { children: /* @__PURE__ */ Q(e, { id: "Give this customer one of your products without a payment. They hold its keys while the grant lasts, including keys you add to the product later." }) })] }), /* @__PURE__ */ $("form", {
1156
+ onSubmit: (e) => {
1157
+ e.preventDefault(), e.stopPropagation(), _.handleSubmit();
1158
+ },
1159
+ className: "grid gap-4",
1160
+ children: [/* @__PURE__ */ $("div", {
1161
+ className: "grid gap-3",
1162
+ children: [
1163
+ /* @__PURE__ */ Q(_.Field, {
1164
+ name: "productId",
1165
+ validators: { onChange: ({ value: e }) => e ? void 0 : "Pick a product" },
1166
+ children: (t) => /* @__PURE__ */ $("div", {
1167
+ className: "grid gap-1.5",
1168
+ children: [
1169
+ /* @__PURE__ */ Q(U, {
1170
+ htmlFor: c("pa-product"),
1171
+ children: /* @__PURE__ */ Q(e, { id: "Product" })
1172
+ }),
1173
+ /* @__PURE__ */ $(k, {
1174
+ value: t.state.value,
1175
+ onValueChange: (e) => t.handleChange(e ?? ""),
1176
+ children: [/* @__PURE__ */ Q(E, {
1177
+ className: "w-full",
1178
+ id: c("pa-product"),
1179
+ "aria-invalid": t.state.meta.errors.length > 0,
1180
+ children: /* @__PURE__ */ Q(T, { placeholder: d("Pick a product") })
1181
+ }), /* @__PURE__ */ Q(D, { children: (g?.data ?? []).map((e) => /* @__PURE__ */ $(O, {
1182
+ value: e.id,
1183
+ children: [
1184
+ e.display_name,
1185
+ " (",
1186
+ e.key,
1187
+ ")"
1188
+ ]
1189
+ }, e.id)) })]
1190
+ }),
1191
+ /* @__PURE__ */ Q(w, { errors: t.state.meta.errors })
1192
+ ]
1193
+ })
1194
+ }),
1195
+ /* @__PURE__ */ Q(_.Field, {
1196
+ name: "duration",
1197
+ children: (t) => /* @__PURE__ */ $("div", {
1198
+ className: "grid gap-1.5",
1199
+ children: [
1200
+ /* @__PURE__ */ Q(U, {
1201
+ htmlFor: c("pa-duration"),
1202
+ children: /* @__PURE__ */ Q(e, { id: "How long it lasts" })
1203
+ }),
1204
+ /* @__PURE__ */ Q("p", {
1205
+ className: "text-[13px] text-muted-foreground",
1206
+ children: /* @__PURE__ */ Q(e, { id: "Days are added after any access they already have." })
1207
+ }),
1208
+ /* @__PURE__ */ $(k, {
1209
+ items: De.map((e) => ({
1210
+ value: e.value,
1211
+ label: e.label
1212
+ })),
1213
+ value: t.state.value,
1214
+ onValueChange: (e) => {
1215
+ e && t.handleChange(e);
1216
+ },
1217
+ children: [/* @__PURE__ */ Q(E, {
1218
+ className: "w-full",
1219
+ id: c("pa-duration"),
1220
+ children: /* @__PURE__ */ Q(T, {})
1221
+ }), /* @__PURE__ */ Q(D, { children: De.map((e) => /* @__PURE__ */ Q(O, {
1222
+ value: e.value,
1223
+ children: e.label
1224
+ }, e.value)) })]
1225
+ })
1226
+ ]
1227
+ })
1228
+ }),
1229
+ /* @__PURE__ */ Q(_.Subscribe, {
1230
+ selector: (e) => e.values.duration,
1231
+ children: (t) => t === "until" ? /* @__PURE__ */ Q(_.Field, {
1232
+ name: "until",
1233
+ validators: { onChange: ({ value: e }) => ke("until", e) ? void 0 : "Pick today or a later date" },
1234
+ children: (t) => /* @__PURE__ */ $("div", {
1235
+ className: "grid gap-1.5",
1236
+ children: [
1237
+ /* @__PURE__ */ Q(U, {
1238
+ htmlFor: c("pa-until"),
1239
+ children: /* @__PURE__ */ Q(e, { id: "Last day (UTC)" })
1240
+ }),
1241
+ /* @__PURE__ */ Q(u, {
1242
+ id: c("pa-until"),
1243
+ type: "date",
1244
+ min: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
1245
+ value: t.state.value,
1246
+ onBlur: t.handleBlur,
1247
+ onChange: (e) => t.handleChange(e.target.value),
1248
+ "aria-invalid": t.state.meta.errors.length > 0
1249
+ }),
1250
+ /* @__PURE__ */ Q(w, { errors: t.state.meta.errors })
1251
+ ]
1252
+ })
1253
+ }) : null
1254
+ }),
1255
+ /* @__PURE__ */ Q(_.Field, {
1256
+ name: "note",
1257
+ children: (t) => /* @__PURE__ */ $("div", {
1258
+ className: "grid gap-1.5",
1259
+ children: [/* @__PURE__ */ Q(U, {
1260
+ htmlFor: c("pa-note"),
1261
+ children: /* @__PURE__ */ Q(e, { id: "Note" })
1262
+ }), /* @__PURE__ */ Q(u, {
1263
+ id: c("pa-note"),
1264
+ value: t.state.value,
1265
+ onBlur: t.handleBlur,
1266
+ onChange: (e) => t.handleChange(e.target.value),
1267
+ placeholder: d("Why it was granted")
1268
+ })]
1269
+ })
1270
+ })
1271
+ ]
1272
+ }), /* @__PURE__ */ Q(B, { children: /* @__PURE__ */ Q(_.Subscribe, {
1273
+ selector: (e) => [
1274
+ e.values.productId,
1275
+ e.canSubmit,
1276
+ e.isSubmitting,
1277
+ ke(e.values.duration, e.values.until) !== null
1278
+ ],
1279
+ children: ([t, n, r, i]) => /* @__PURE__ */ $(ue, { children: [/* @__PURE__ */ Q(l, {
1280
+ type: "button",
1281
+ variant: "outline",
1282
+ disabled: r,
1283
+ onClick: () => v(!1),
1284
+ children: /* @__PURE__ */ Q(e, { id: "Cancel" })
1285
+ }), /* @__PURE__ */ Q(l, {
1286
+ type: "submit",
1287
+ disabled: !t || !n || r || !i,
1288
+ children: r ? "Granting…" : "Grant access"
1289
+ })] })
1290
+ }) })]
1291
+ })]
1292
+ })]
1293
+ });
1294
+ }
1295
+ function Re({ contact: n }) {
1296
+ let { text: r } = t();
1297
+ return /* @__PURE__ */ $(q, { children: [/* @__PURE__ */ Q(W, {
1298
+ className: "pb-1",
1299
+ children: /* @__PURE__ */ Q(G, {
1300
+ className: "text-sm",
1301
+ children: /* @__PURE__ */ Q(e, { id: "Contact" })
1302
+ })
1303
+ }), /* @__PURE__ */ Q(K, {
1304
+ className: "text-sm",
1305
+ children: n ? /* @__PURE__ */ $("dl", {
1306
+ className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1",
1307
+ children: [
1308
+ /* @__PURE__ */ Q("dt", {
1309
+ className: "text-muted-foreground",
1310
+ children: /* @__PURE__ */ Q(e, { id: "Email" })
1311
+ }),
1312
+ /* @__PURE__ */ Q("dd", {
1313
+ className: "truncate",
1314
+ children: n.email ?? "—"
1315
+ }),
1316
+ /* @__PURE__ */ Q("dt", {
1317
+ className: "text-muted-foreground",
1318
+ children: /* @__PURE__ */ Q(e, { id: "Name" })
1319
+ }),
1320
+ /* @__PURE__ */ Q("dd", {
1321
+ className: "truncate",
1322
+ children: n.name ?? "—"
1323
+ }),
1324
+ /* @__PURE__ */ Q("dt", {
1325
+ className: "text-muted-foreground",
1326
+ children: /* @__PURE__ */ Q(e, { id: "Username" })
1327
+ }),
1328
+ /* @__PURE__ */ Q("dd", {
1329
+ className: "truncate",
1330
+ children: n.username ?? "—"
1331
+ }),
1332
+ n.active !== null && /* @__PURE__ */ $(ue, { children: [/* @__PURE__ */ Q("dt", {
1333
+ className: "text-muted-foreground",
1334
+ children: /* @__PURE__ */ Q(e, { id: "Directory" })
1335
+ }), /* @__PURE__ */ Q("dd", { children: /* @__PURE__ */ Q(S, {
1336
+ variant: n.active ? "secondary" : "outline",
1337
+ children: n.active ? "Active" : "Deactivated"
1338
+ }) })] }),
1339
+ /* @__PURE__ */ Q("dt", {
1340
+ className: "text-muted-foreground",
1341
+ children: /* @__PURE__ */ Q(e, { id: "Last updated" })
1342
+ }),
1343
+ /* @__PURE__ */ Q("dd", {
1344
+ className: "tabular-nums",
1345
+ children: n.synced_at ? v(n.synced_at) : r("Current, read from your directory")
1346
+ })
1347
+ ]
1348
+ }) : /* @__PURE__ */ Q("p", {
1349
+ className: "text-muted-foreground",
1350
+ children: /* @__PURE__ */ Q(e, { id: "Your directory holds no contact for this customer." })
1351
+ })
1352
+ })] });
1353
+ }
1354
+ //#endregion
1355
+ export { Ae as CustomerDetailPage };
1356
+
1357
+ //# sourceMappingURL=admin-detail-P-UnNvXJ.js.map