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