@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,1716 @@
1
+ import { J as e, K as t, O as n, P as r, X as i, _ as a, c as o, k as s, l as c, m as l, n as u, p as d, w as f } from "./admin-format-Bc4NWK0F.js";
2
+ import { n as p, t as m } from "./admin-cursor-pager-dkNj-gb6.js";
3
+ import { n as h } from "./admin-confirm-DWq-edDC.js";
4
+ import { t as g } from "./admin-linked-table-row-ChxhVptQ.js";
5
+ import { t as _ } from "./admin-badge-C_-j7ANF.js";
6
+ import { t as v } from "./admin-button-BV5MAL2H.js";
7
+ import { t as y } from "./admin-input-BZ2ExV_5.js";
8
+ import { t as b } from "./admin-skeleton-DdqwXcr4.js";
9
+ import { a as x, n as ee, o as te, r as S, s as C, t as w } from "./admin-table-ByPfWNq8.js";
10
+ import { c as T } from "./admin-capabilities-B3ZfkA49.js";
11
+ import { t as E } from "./admin-form-field-errors-Cuhy38F1.js";
12
+ import { a as ne, i as re, n as ie, o as ae, r as oe, s as se, t as ce } from "./admin-dialog-BxRcYcQM.js";
13
+ import { t as D } from "./admin-label-DecDO0oV.js";
14
+ import { a as O, i as k, n as A, r as j, t as M } from "./admin-select-CgZq2j0G.js";
15
+ import { i as le, r as ue } from "./admin-dialog-width-C_WFpow0.js";
16
+ import { t as de } from "./admin-switch-CyYmt8wi.js";
17
+ import * as N from "react";
18
+ import { useMutation as fe, useQuery as pe, useQueryClient as me } from "@tanstack/react-query";
19
+ import { Fragment as P, jsx as F, jsxs as I } from "react/jsx-runtime";
20
+ import { HugeiconsIcon as L } from "@hugeicons/react";
21
+ import { Activity01Icon as he, Add01Icon as R, ArrowLeft01Icon as ge, ArrowRight01Icon as _e, Delete02Icon as z, Edit02Icon as ve, InformationCircleIcon as ye, Money03Icon as be, Search01Icon as xe } from "@hugeicons/core-free-icons";
22
+ import { useForm as Se } from "@tanstack/react-form";
23
+ // src/admin/pages/catalog/metering-model.ts
24
+ var Ce = class extends Error {
25
+ fieldId;
26
+ constructor(e, t) {
27
+ super(t), this.name = "RateCardFormError", this.fieldId = e;
28
+ }
29
+ };
30
+ function we(e) {
31
+ return e.pending ? "loading" : e.error?.status === 403 ? "permission" : e.error ? "error" : e.count === 0 ? "empty" : "ready";
32
+ }
33
+ function Te(e) {
34
+ return e.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[-_]+|[-_]+$/g, "");
35
+ }
36
+ function Ee(e) {
37
+ return {
38
+ key: e?.key ?? "",
39
+ eventType: e?.event_type ?? "",
40
+ aggregation: e?.aggregation === "count" ? "count" : "sum",
41
+ valueProperty: e?.value_property ?? "",
42
+ unit: e?.unit ?? "",
43
+ groupBy: Object.entries(e?.group_by ?? {}).map(([e, t]) => ({
44
+ key: e,
45
+ value: t
46
+ }))
47
+ };
48
+ }
49
+ function De(e) {
50
+ let t = Te(e.key);
51
+ if (!t) throw Error("Enter a meter key.");
52
+ let n = e.eventType.trim(), r = e.valueProperty.trim();
53
+ if (e.aggregation === "sum" && !r) throw Error("Sum meters require a value property.");
54
+ let i = Me(e.groupBy, "group");
55
+ return {
56
+ key: t,
57
+ meter: {
58
+ event_type: n,
59
+ aggregation: e.aggregation,
60
+ value_property: e.aggregation === "sum" ? r : "",
61
+ unit: e.unit.trim() || void 0,
62
+ group_by: i
63
+ }
64
+ };
65
+ }
66
+ function Oe(e) {
67
+ let t = e?.price, n = t?.per_unit?.matrix, r = e?.allowance, i = r?.included === void 0 ? "none" : "included", a = t?.currency ?? "USD";
68
+ return {
69
+ productId: e?.product_id ?? "",
70
+ model: t?.model && t.model !== "flat" ? t.model : "per_unit",
71
+ currency: a,
72
+ unitAmount: U(a, t?.per_unit?.unit_amount),
73
+ divideBy: W(t?.per_unit?.divide_by, "1"),
74
+ round: t?.per_unit?.round ?? "half_up",
75
+ maximumAmount: U(a, t?.per_unit?.maximum_amount),
76
+ matrixEnabled: !!n,
77
+ matrixDimension: n?.dimension ?? "",
78
+ matrixCells: Object.entries(n?.cells ?? {}).map(([e, t]) => ({
79
+ key: e,
80
+ unitAmount: U(a, t.unit_amount),
81
+ maximumAmount: U(a, t.maximum_amount)
82
+ })),
83
+ tierMode: "graduated",
84
+ tiers: (t?.tiered?.tiers ?? [{
85
+ up_to: null,
86
+ unit_amount: "0",
87
+ flat_amount: "0"
88
+ }]).map((e) => ({
89
+ upTo: e.up_to === null ? "" : String(e.up_to),
90
+ unitAmount: U(a, e.unit_amount),
91
+ flatAmount: U(a, e.flat_amount)
92
+ })),
93
+ packageAmount: U(a, t?.package?.amount),
94
+ packageSize: W(t?.package?.package_size, "1"),
95
+ freeUnits: W(t?.package?.free_units),
96
+ filters: Object.entries(e?.filter ?? {}).map(([e, t]) => ({
97
+ key: e,
98
+ value: t.join(", ")
99
+ })),
100
+ allowanceMode: i,
101
+ allowanceIncluded: W(r?.included)
102
+ };
103
+ }
104
+ function ke(e) {
105
+ e.productId || H("rate-product", "Select a product.");
106
+ let t = e.currency.trim().toUpperCase();
107
+ u(t) === void 0 && H("rate-currency", `Use a supported currency: ${a.join(", ")}.`);
108
+ let n = Ae(e, t), r = e.model === "dynamic" ? void 0 : je(e);
109
+ return {
110
+ product_id: e.productId,
111
+ filter: Ne(e.filters),
112
+ price: n,
113
+ ...r ? { allowance: r } : {}
114
+ };
115
+ }
116
+ function Ae(e, t) {
117
+ if (e.model === "dynamic") return {
118
+ model: "dynamic",
119
+ currency: t
120
+ };
121
+ if (e.model === "per_unit") {
122
+ let n = Pe(e.divideBy, "Divisor", "rate-divide-by"), r = V(t, e.maximumAmount, "Maximum amount", "rate-maximum");
123
+ if (e.matrixEnabled) {
124
+ let i = e.matrixDimension.trim();
125
+ i || H("matrix-dimension", "Select a matrix dimension."), e.matrixCells.length === 0 && H("matrix-add-cell", "Add at least one matrix cell.");
126
+ let a = {};
127
+ for (let [n, r] of e.matrixCells.entries()) {
128
+ let e = r.key.trim(), i = `matrix-cell-${n}`;
129
+ e || H(`${i}-value`, "Each matrix cell needs a value."), a[e] && H(`${i}-value`, `Duplicate matrix value “${e}”.`), a[e] = {
130
+ unit_amount: B(t, r.unitAmount, `Price for ${e}`, `${i}-unit-price`, !0),
131
+ ...V(t, r.maximumAmount, `Maximum for ${e}`, `${i}-maximum`) === "0" ? {} : { maximum_amount: V(t, r.maximumAmount, `Maximum for ${e}`, `${i}-maximum`) }
132
+ };
133
+ }
134
+ return {
135
+ model: "per_unit",
136
+ currency: t,
137
+ per_unit: {
138
+ divide_by: n,
139
+ round: e.round,
140
+ ...r === "0" ? {} : { maximum_amount: r },
141
+ matrix: {
142
+ dimension: i,
143
+ cells: a
144
+ }
145
+ }
146
+ };
147
+ }
148
+ return {
149
+ model: "per_unit",
150
+ currency: t,
151
+ per_unit: {
152
+ unit_amount: B(t, e.unitAmount, "Unit price", "rate-unit-amount", !0),
153
+ divide_by: n,
154
+ round: e.round,
155
+ ...r === "0" ? {} : { maximum_amount: r }
156
+ }
157
+ };
158
+ }
159
+ if (e.model === "tiered") {
160
+ e.tiers.length === 0 && H("tier-add", "Add at least one tier.");
161
+ let n = e.tiers.map((n, r) => {
162
+ let i = r === e.tiers.length - 1, a = n.upTo.trim();
163
+ return i && a && H(`tier-${r}-limit`, "The final tier must be unbounded."), !i && !a && H(`tier-${r}-limit`, "Only the final tier can be unbounded."), {
164
+ up_to: i ? null : Pe(a, `Tier ${r + 1} limit`, `tier-${r}-limit`),
165
+ unit_amount: B(t, n.unitAmount, `Tier ${r + 1} unit price`, `tier-${r}-unit-price`, !0),
166
+ flat_amount: V(t, n.flatAmount, `Tier ${r + 1} flat amount`, `tier-${r}-flat-amount`)
167
+ };
168
+ });
169
+ for (let e = 1; e < n.length - 1; e += 1) (n[e].up_to ?? 0) <= (n[e - 1].up_to ?? 0) && H(`tier-${e}-limit`, "Tier limits must increase.");
170
+ return {
171
+ model: "tiered",
172
+ currency: t,
173
+ tiered: {
174
+ mode: e.tierMode,
175
+ tiers: n
176
+ }
177
+ };
178
+ }
179
+ return {
180
+ model: "package",
181
+ currency: t,
182
+ package: {
183
+ amount: B(t, e.packageAmount, "Package price", "package-amount"),
184
+ package_size: Pe(e.packageSize, "Package size", "package-size"),
185
+ free_units: Fe(e.freeUnits, "Free units", "package-free")
186
+ }
187
+ };
188
+ }
189
+ function je(e) {
190
+ if (e.allowanceMode !== "none") return { included: Fe(e.allowanceIncluded, "Included allowance", "allowance-included") };
191
+ }
192
+ function Me(e, t) {
193
+ let n = {};
194
+ for (let r of e) {
195
+ let e = r.key.trim(), i = r.value.trim();
196
+ if (!e || !i) throw Error(`Each ${t} row needs both fields.`);
197
+ if (n[e]) throw Error(`Duplicate ${t} key “${e}”.`);
198
+ n[e] = i;
199
+ }
200
+ return n;
201
+ }
202
+ function Ne(e) {
203
+ let t = {};
204
+ for (let [n, r] of e.entries()) {
205
+ let e = r.key.trim(), i = [...new Set(r.value.split(",").map((e) => e.trim()))].filter(Boolean);
206
+ e || H(`filter-${n}-dimension`, "Select a dimension for this filter."), i.length === 0 && H(`filter-${n}-values`, "Enter at least one value for this filter."), t[e] && H(`filter-${n}-dimension`, `Duplicate filter dimension “${e}”.`), t[e] = i;
207
+ }
208
+ return t;
209
+ }
210
+ function B(e, t, n, r, i = !1) {
211
+ let a = d(t, e);
212
+ return (a === null || BigInt(a) < 0n || !i && BigInt(a) === 0n) && H(r, `${n} must be ${i ? "zero or more" : "greater than zero"}.`), a;
213
+ }
214
+ function V(e, t, n, r) {
215
+ return t.trim() ? B(e, t, n, r, !0) : "0";
216
+ }
217
+ function Pe(e, t, n) {
218
+ let r = Number(e);
219
+ return (!Number.isSafeInteger(r) || r <= 0) && H(n, `${t} must be a positive whole number.`), r;
220
+ }
221
+ function Fe(e, t, n) {
222
+ if (!e.trim()) return 0;
223
+ let r = Number(e);
224
+ return (!Number.isSafeInteger(r) || r < 0) && H(n, `${t} must be zero or a positive whole number.`), r;
225
+ }
226
+ function H(e, t) {
227
+ throw new Ce(e, t);
228
+ }
229
+ function U(e, t) {
230
+ return t && t !== "0" ? l(t, e) : "";
231
+ }
232
+ function W(e, t = "") {
233
+ return e ? String(e) : t;
234
+ }
235
+ function Ie(e) {
236
+ if (!e) return "Not priced";
237
+ let { price: t } = e, n = t.currency ?? "";
238
+ return t.model === "dynamic" ? `Event amount · ${n}` : t.model === "per_unit" && t.per_unit ? t.per_unit.matrix ? `${Object.keys(t.per_unit.matrix.cells ?? {}).length} matrix rates · ${n}` : `${c(t.per_unit.unit_amount ?? "0", n)} per ${t.per_unit.divide_by || 1} units` : t.model === "tiered" && t.tiered ? `${t.tiered.tiers?.length ?? 0} ${t.tiered.mode} tiers · ${n}` : t.model === "package" && t.package ? `${c(t.package.amount ?? "0", n)} per ${(t.package.package_size ?? 1).toLocaleString()} units` : `Unsupported price · ${n}`;
239
+ }
240
+ function Le(e, t) {
241
+ return t ? e.has_activity ? "Meter definitions lock after the first event." : null : "Catalog updates are disabled.";
242
+ }
243
+ // src/admin/pages/catalog/meter-form.tsx
244
+ function Re({ meter: t, writesAllowed: n }) {
245
+ let { toast: a, toastApiError: o, adminMutations: s } = r(), { id: c, text: l } = i(), [u, d] = N.useState(!1), [f, p] = N.useState(""), m = me(), h = fe(s.putUsageMeter(m)), g = t ? Le(t, n) : null, _ = Se({
246
+ defaultValues: Ee(t),
247
+ onSubmit: async ({ value: e }) => {
248
+ p("");
249
+ try {
250
+ let n = De(e);
251
+ n.meter.expected_revision = t?.revision ?? 0, await h.mutateAsync(n), a.success(t ? "Meter updated" : "Meter created"), d(!1), _.reset();
252
+ } catch (e) {
253
+ if (e instanceof Error && !("status" in e)) {
254
+ p(e.message);
255
+ return;
256
+ }
257
+ o(e, t ? "Update meter" : "Create meter");
258
+ }
259
+ }
260
+ });
261
+ return g ? /* @__PURE__ */ I(v, {
262
+ variant: "outline",
263
+ size: "sm",
264
+ disabled: !0,
265
+ title: g,
266
+ children: [/* @__PURE__ */ F(L, {
267
+ icon: ve,
268
+ className: "size-4"
269
+ }), /* @__PURE__ */ F(e, { id: "Edit definition" })]
270
+ }) : /* @__PURE__ */ I(ce, {
271
+ open: u,
272
+ onOpenChange: (e) => {
273
+ d(e), p(""), e || _.reset();
274
+ },
275
+ children: [/* @__PURE__ */ F(se, { render: /* @__PURE__ */ I(v, {
276
+ variant: t ? "outline" : "default",
277
+ size: "sm",
278
+ children: [/* @__PURE__ */ F(L, {
279
+ icon: t ? ve : R,
280
+ className: "size-4"
281
+ }), t ? "Edit definition" : "Create meter"]
282
+ }) }), /* @__PURE__ */ F(ie, {
283
+ className: ue,
284
+ children: /* @__PURE__ */ I("form", {
285
+ className: "grid gap-5",
286
+ onSubmit: (e) => {
287
+ e.preventDefault(), e.stopPropagation(), _.handleSubmit();
288
+ },
289
+ children: [
290
+ /* @__PURE__ */ I(ne, { children: [/* @__PURE__ */ F(ae, { children: t ? "Edit meter" : "Create meter" }), /* @__PURE__ */ F(oe, { children: /* @__PURE__ */ F(e, { id: "Define the event fields OpenRails will aggregate. Your host still reports each event through the usage API." }) })] }),
291
+ /* @__PURE__ */ I("div", {
292
+ className: "grid gap-4",
293
+ children: [
294
+ /* @__PURE__ */ F(_.Field, {
295
+ name: "key",
296
+ validators: { onBlur: ({ value: e }) => e.trim() ? void 0 : "Enter a meter key." },
297
+ children: (n) => /* @__PURE__ */ I("div", {
298
+ className: "grid gap-1.5",
299
+ children: [
300
+ /* @__PURE__ */ F(D, {
301
+ htmlFor: c("meter-key"),
302
+ children: /* @__PURE__ */ F(e, { id: "Key" })
303
+ }),
304
+ /* @__PURE__ */ F(y, {
305
+ id: c("meter-key"),
306
+ value: n.state.value,
307
+ onChange: (e) => n.handleChange(e.target.value),
308
+ onBlur: n.handleBlur,
309
+ disabled: !!t,
310
+ placeholder: l("api-tokens"),
311
+ autoComplete: "off"
312
+ }),
313
+ /* @__PURE__ */ F("p", {
314
+ className: "text-xs text-muted-foreground",
315
+ children: /* @__PURE__ */ F(e, { id: "Stable identifier. It cannot be renamed after creation." })
316
+ }),
317
+ /* @__PURE__ */ F(E, { errors: n.state.meta.errors })
318
+ ]
319
+ })
320
+ }),
321
+ /* @__PURE__ */ I("div", {
322
+ className: "grid gap-4 sm:grid-cols-2",
323
+ children: [/* @__PURE__ */ F(_.Field, {
324
+ name: "eventType",
325
+ children: (t) => /* @__PURE__ */ I("div", {
326
+ className: "grid gap-1.5",
327
+ children: [
328
+ /* @__PURE__ */ F(D, {
329
+ htmlFor: c("meter-event-type"),
330
+ children: /* @__PURE__ */ F(e, { id: "Event type" })
331
+ }),
332
+ /* @__PURE__ */ F(y, {
333
+ id: c("meter-event-type"),
334
+ value: t.state.value,
335
+ onChange: (e) => t.handleChange(e.target.value),
336
+ placeholder: l("token.used"),
337
+ autoComplete: "off"
338
+ }),
339
+ /* @__PURE__ */ F("p", {
340
+ className: "text-xs text-muted-foreground",
341
+ children: /* @__PURE__ */ F(e, { id: "Leave blank to use the meter key." })
342
+ })
343
+ ]
344
+ })
345
+ }), /* @__PURE__ */ F(_.Field, {
346
+ name: "unit",
347
+ children: (t) => /* @__PURE__ */ I("div", {
348
+ className: "grid gap-1.5",
349
+ children: [
350
+ /* @__PURE__ */ F(D, {
351
+ htmlFor: c("meter-unit"),
352
+ children: /* @__PURE__ */ F(e, { id: "Unit" })
353
+ }),
354
+ /* @__PURE__ */ F(y, {
355
+ id: c("meter-unit"),
356
+ value: t.state.value,
357
+ onChange: (e) => t.handleChange(e.target.value),
358
+ placeholder: l("tokens"),
359
+ autoComplete: "off"
360
+ }),
361
+ /* @__PURE__ */ F("p", {
362
+ className: "text-xs text-muted-foreground",
363
+ children: /* @__PURE__ */ F(e, { id: "Human-readable quantity shown in billing." })
364
+ })
365
+ ]
366
+ })
367
+ })]
368
+ }),
369
+ /* @__PURE__ */ I("div", {
370
+ className: "grid gap-4 sm:grid-cols-2",
371
+ children: [/* @__PURE__ */ F(_.Field, {
372
+ name: "aggregation",
373
+ children: (t) => /* @__PURE__ */ I("div", {
374
+ className: "grid gap-1.5",
375
+ children: [/* @__PURE__ */ F(D, {
376
+ htmlFor: c("meter-aggregation"),
377
+ children: /* @__PURE__ */ F(e, { id: "Aggregation" })
378
+ }), /* @__PURE__ */ I(M, {
379
+ value: t.state.value,
380
+ onValueChange: (e) => t.handleChange(e),
381
+ children: [/* @__PURE__ */ F(k, {
382
+ id: c("meter-aggregation"),
383
+ className: "w-full",
384
+ children: /* @__PURE__ */ F(O, {})
385
+ }), /* @__PURE__ */ I(A, { children: [/* @__PURE__ */ F(j, {
386
+ value: "sum",
387
+ children: /* @__PURE__ */ F(e, { id: "Sum a numeric field" })
388
+ }), /* @__PURE__ */ F(j, {
389
+ value: "count",
390
+ children: /* @__PURE__ */ F(e, { id: "Count events" })
391
+ })] })]
392
+ })]
393
+ })
394
+ }), /* @__PURE__ */ F(_.Subscribe, {
395
+ selector: (e) => e.values.aggregation,
396
+ children: (t) => t === "sum" ? /* @__PURE__ */ F(_.Field, {
397
+ name: "valueProperty",
398
+ validators: { onBlur: ({ value: e }) => e.trim() ? void 0 : "Sum meters require a value property." },
399
+ children: (t) => /* @__PURE__ */ I("div", {
400
+ className: "grid gap-1.5",
401
+ children: [
402
+ /* @__PURE__ */ F(D, {
403
+ htmlFor: c("meter-value-property"),
404
+ children: /* @__PURE__ */ F(e, { id: "Value property" })
405
+ }),
406
+ /* @__PURE__ */ F(y, {
407
+ id: c("meter-value-property"),
408
+ value: t.state.value,
409
+ onChange: (e) => t.handleChange(e.target.value),
410
+ onBlur: t.handleBlur,
411
+ placeholder: l("tokens"),
412
+ autoComplete: "off"
413
+ }),
414
+ /* @__PURE__ */ F(E, { errors: t.state.meta.errors })
415
+ ]
416
+ })
417
+ }) : /* @__PURE__ */ F("div", {
418
+ className: "self-end rounded-lg bg-muted/50 px-3 py-2 text-xs text-muted-foreground",
419
+ children: /* @__PURE__ */ F(e, { id: "Count uses one unit for every matching event." })
420
+ })
421
+ })]
422
+ }),
423
+ /* @__PURE__ */ F(_.Field, {
424
+ name: "groupBy",
425
+ mode: "array",
426
+ children: (t) => /* @__PURE__ */ I("fieldset", {
427
+ className: "grid gap-2",
428
+ children: [/* @__PURE__ */ I("div", {
429
+ className: "flex items-center justify-between gap-3",
430
+ children: [/* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F(D, { children: /* @__PURE__ */ F(e, { id: "Dimensions" }) }), /* @__PURE__ */ F("p", {
431
+ className: "text-xs text-muted-foreground",
432
+ children: /* @__PURE__ */ F(e, { id: "Register event properties used by filters or matrix rates." })
433
+ })] }), /* @__PURE__ */ I(v, {
434
+ type: "button",
435
+ variant: "outline",
436
+ size: "sm",
437
+ onClick: () => t.pushValue({
438
+ key: "",
439
+ value: ""
440
+ }),
441
+ children: [/* @__PURE__ */ F(L, {
442
+ icon: R,
443
+ className: "size-4"
444
+ }), /* @__PURE__ */ F(e, { id: "Add dimension" })]
445
+ })]
446
+ }), t.state.value.map((e, n) => /* @__PURE__ */ I("div", {
447
+ className: "grid grid-cols-[1fr_1fr_auto] gap-2",
448
+ children: [
449
+ /* @__PURE__ */ F(y, {
450
+ "aria-label": `Dimension ${n + 1} name`,
451
+ value: e.key,
452
+ onChange: (e) => _.setFieldValue(`groupBy[${n}].key`, e.target.value),
453
+ placeholder: l("model"),
454
+ autoComplete: "off"
455
+ }),
456
+ /* @__PURE__ */ F(y, {
457
+ "aria-label": `Dimension ${n + 1} property`,
458
+ value: e.value,
459
+ onChange: (e) => _.setFieldValue(`groupBy[${n}].value`, e.target.value),
460
+ placeholder: l("metadata.model"),
461
+ autoComplete: "off"
462
+ }),
463
+ /* @__PURE__ */ F(v, {
464
+ type: "button",
465
+ variant: "ghost",
466
+ size: "icon",
467
+ "aria-label": `Remove dimension ${n + 1}`,
468
+ onClick: () => t.removeValue(n),
469
+ children: /* @__PURE__ */ F(L, {
470
+ icon: z,
471
+ className: "size-4"
472
+ })
473
+ })
474
+ ]
475
+ }, n))]
476
+ })
477
+ })
478
+ ]
479
+ }),
480
+ f && /* @__PURE__ */ F("p", {
481
+ role: "alert",
482
+ className: "text-sm text-destructive",
483
+ children: f
484
+ }),
485
+ /* @__PURE__ */ I(re, { children: [/* @__PURE__ */ F(v, {
486
+ type: "button",
487
+ variant: "outline",
488
+ onClick: () => d(!1),
489
+ children: /* @__PURE__ */ F(e, { id: "Cancel" })
490
+ }), /* @__PURE__ */ F(_.Subscribe, {
491
+ selector: (e) => e.isSubmitting,
492
+ children: (e) => /* @__PURE__ */ F(v, {
493
+ type: "submit",
494
+ disabled: e || h.isPending,
495
+ children: e || h.isPending ? "Saving…" : "Save meter"
496
+ })
497
+ })] })
498
+ ]
499
+ })
500
+ })]
501
+ });
502
+ }
503
+ // src/admin/pages/catalog/rate-card-editor.tsx
504
+ var G = N.createContext(null);
505
+ function ze({ meter: t, writesAllowed: n = !1, products: a, productsPending: o = !1, productsError: s = !1, productsForbidden: c = !1 }) {
506
+ let { toast: l, toastApiError: u, adminMutations: d } = r(), { id: p, text: m } = i(), [g, _] = N.useState(!1), [b, x] = N.useState(null), ee = h(), te = me(), S = fe(d.putDefaultUsageRateCard(te)), C = a.filter((e) => !e.archived), w = t.rate_card, T = S.isPending, E = Se({
507
+ defaultValues: Oe(w),
508
+ onSubmit: async ({ value: e }) => {
509
+ x(null);
510
+ try {
511
+ let t = ke(e);
512
+ if (w && !await ee({
513
+ title: "Replace the default rate?",
514
+ description: "Amounts already charged do not change. New events use the new rate; admitted work keeps its pinned rate.",
515
+ confirmLabel: "Replace rate",
516
+ cancelLabel: "Keep current rate"
517
+ })) return;
518
+ await ue(t);
519
+ } catch (e) {
520
+ if (e instanceof Ce) {
521
+ x({
522
+ fieldId: e.fieldId,
523
+ message: e.message
524
+ }), requestAnimationFrame(() => {
525
+ document.getElementById(p(e.fieldId))?.focus();
526
+ });
527
+ return;
528
+ }
529
+ u(e, "Save rate card");
530
+ }
531
+ }
532
+ }), ue = async (e) => {
533
+ try {
534
+ await S.mutateAsync({
535
+ meter: t,
536
+ rateCard: e
537
+ }), l.success(w ? "Default rate replaced" : "Default rate added"), _(!1);
538
+ } catch (e) {
539
+ u(e, "Save default rate");
540
+ }
541
+ };
542
+ return !n || !t.billing_supported ? null : /* @__PURE__ */ F(G.Provider, {
543
+ value: b,
544
+ children: /* @__PURE__ */ I(ce, {
545
+ open: g,
546
+ onOpenChange: (e) => {
547
+ _(e), x(null), e || E.reset();
548
+ },
549
+ children: [/* @__PURE__ */ F(se, { render: /* @__PURE__ */ I(v, {
550
+ variant: w ? "outline" : "default",
551
+ size: "sm",
552
+ children: [/* @__PURE__ */ F(L, {
553
+ icon: w ? ve : be,
554
+ className: "size-4"
555
+ }), w ? "Edit default rate" : "Add default rate"]
556
+ }) }), /* @__PURE__ */ F(ie, {
557
+ className: `${le} max-h-[calc(100dvh-2rem)] overflow-y-auto`,
558
+ children: /* @__PURE__ */ I("form", {
559
+ className: "grid gap-6",
560
+ onChange: () => x(null),
561
+ onSubmit: (e) => {
562
+ e.preventDefault(), e.stopPropagation(), E.handleSubmit();
563
+ },
564
+ children: [
565
+ /* @__PURE__ */ I(ne, { children: [/* @__PURE__ */ F(ae, { children: w ? "Edit default rate" : "Add default rate" }), /* @__PURE__ */ F(oe, { children: /* @__PURE__ */ F(e, { id: "Set the price that charges every customer's usage as it is recorded. Money is entered in major currency units." }) })] }),
566
+ /* @__PURE__ */ I("section", {
567
+ className: "grid gap-4",
568
+ children: [/* @__PURE__ */ F("h3", {
569
+ className: "text-sm font-medium",
570
+ children: /* @__PURE__ */ F(e, { id: "Product and model" })
571
+ }), o ? /* @__PURE__ */ F("div", {
572
+ className: "rounded-lg bg-muted/50 p-3 text-sm text-muted-foreground",
573
+ children: /* @__PURE__ */ F(e, { id: "Loading products…" })
574
+ }) : s ? /* @__PURE__ */ F("div", {
575
+ role: "alert",
576
+ className: "rounded-lg bg-muted/50 p-3 text-sm text-destructive",
577
+ children: c ? "Your role cannot read products for this merchant." : "Products could not be loaded. Close this form and try again."
578
+ }) : C.length === 0 ? /* @__PURE__ */ I("div", {
579
+ className: "rounded-lg bg-muted/50 p-3 text-sm",
580
+ children: [/* @__PURE__ */ F("p", { children: /* @__PURE__ */ F(e, { id: "No active products are available." }) }), /* @__PURE__ */ F(f, {
581
+ className: "text-primary underline underline-offset-3",
582
+ to: "/catalog",
583
+ children: /* @__PURE__ */ F(e, { id: "Create or activate a product first" })
584
+ })]
585
+ }) : /* @__PURE__ */ I("div", {
586
+ className: "grid gap-4 sm:grid-cols-3",
587
+ children: [
588
+ /* @__PURE__ */ F(E.Field, {
589
+ name: "productId",
590
+ children: (t) => /* @__PURE__ */ I("div", {
591
+ className: "grid gap-1.5 sm:col-span-2",
592
+ children: [
593
+ /* @__PURE__ */ F(D, {
594
+ htmlFor: p("rate-product"),
595
+ children: /* @__PURE__ */ F(e, { id: "Product" })
596
+ }),
597
+ /* @__PURE__ */ I(M, {
598
+ value: t.state.value || null,
599
+ onValueChange: (e) => t.handleChange(e ?? ""),
600
+ children: [/* @__PURE__ */ F(k, {
601
+ id: p("rate-product"),
602
+ className: "w-full",
603
+ ...Y("rate-product", b),
604
+ children: /* @__PURE__ */ F(O, { placeholder: m("Select product") })
605
+ }), /* @__PURE__ */ F(A, { children: C.map((e) => /* @__PURE__ */ F(j, {
606
+ value: e.id,
607
+ children: e.display_name
608
+ }, e.id)) })]
609
+ }),
610
+ /* @__PURE__ */ F(X, { fieldId: "rate-product" })
611
+ ]
612
+ })
613
+ }),
614
+ /* @__PURE__ */ F(E.Field, {
615
+ name: "currency",
616
+ children: (t) => /* @__PURE__ */ I("div", {
617
+ className: "grid gap-1.5",
618
+ children: [
619
+ /* @__PURE__ */ F(D, {
620
+ htmlFor: p("rate-currency"),
621
+ children: /* @__PURE__ */ F(e, { id: "Currency" })
622
+ }),
623
+ /* @__PURE__ */ F(y, {
624
+ id: p("rate-currency"),
625
+ value: t.state.value,
626
+ onChange: (e) => t.handleChange(e.target.value.toUpperCase()),
627
+ maxLength: 3,
628
+ placeholder: m("USD"),
629
+ className: "uppercase",
630
+ autoComplete: "off",
631
+ ...Y("rate-currency", b)
632
+ }),
633
+ /* @__PURE__ */ F(X, { fieldId: "rate-currency" })
634
+ ]
635
+ })
636
+ }),
637
+ /* @__PURE__ */ F(Be, {
638
+ form: E,
639
+ meter: t
640
+ })
641
+ ]
642
+ })]
643
+ }),
644
+ /* @__PURE__ */ F(E.Subscribe, {
645
+ selector: (e) => e.values.model,
646
+ children: (n) => /* @__PURE__ */ I("section", {
647
+ className: "grid gap-4 border-t pt-5",
648
+ children: [
649
+ /* @__PURE__ */ F("h3", {
650
+ className: "text-sm font-medium",
651
+ children: /* @__PURE__ */ F(e, { id: "Rate" })
652
+ }),
653
+ n === "per_unit" && /* @__PURE__ */ F(Ve, {
654
+ form: E,
655
+ meter: t
656
+ }),
657
+ n === "tiered" && /* @__PURE__ */ F(Ue, { form: E }),
658
+ n === "package" && /* @__PURE__ */ F(We, { form: E }),
659
+ n === "dynamic" && /* @__PURE__ */ F("p", {
660
+ className: "text-sm text-muted-foreground",
661
+ children: /* @__PURE__ */ F(e, { id: "Charge each event’s stated amount when it reports positive units. Missing amounts or zero units charge nothing." })
662
+ })
663
+ ]
664
+ })
665
+ }),
666
+ /* @__PURE__ */ F(Ge, {
667
+ form: E,
668
+ meter: t
669
+ }),
670
+ /* @__PURE__ */ F(E.Subscribe, {
671
+ selector: (e) => e.values.model,
672
+ children: (e) => e !== "dynamic" && /* @__PURE__ */ F(Ke, { form: E })
673
+ }),
674
+ /* @__PURE__ */ F(E.Subscribe, {
675
+ selector: (e) => e.values,
676
+ children: (e) => /* @__PURE__ */ F(qe, { values: e })
677
+ }),
678
+ b && /* @__PURE__ */ F("p", {
679
+ role: "alert",
680
+ className: "text-sm text-destructive",
681
+ children: b.message
682
+ }),
683
+ /* @__PURE__ */ I(re, { children: [/* @__PURE__ */ F(v, {
684
+ type: "button",
685
+ variant: "outline",
686
+ onClick: () => _(!1),
687
+ children: /* @__PURE__ */ F(e, { id: "Cancel" })
688
+ }), /* @__PURE__ */ F(v, {
689
+ type: "submit",
690
+ disabled: T || o || s || C.length === 0,
691
+ children: T ? "Saving…" : w ? "Review replacement" : "Save default rate"
692
+ })] })
693
+ ]
694
+ })
695
+ })]
696
+ })
697
+ });
698
+ }
699
+ function Be({ form: t, meter: n }) {
700
+ let { id: r } = i();
701
+ return /* @__PURE__ */ F(t.Field, {
702
+ name: "model",
703
+ children: (t) => /* @__PURE__ */ I("div", {
704
+ className: "grid gap-1.5 sm:col-span-3",
705
+ children: [/* @__PURE__ */ F(D, {
706
+ htmlFor: r("rate-model"),
707
+ children: /* @__PURE__ */ F(e, { id: "Pricing model" })
708
+ }), /* @__PURE__ */ I(M, {
709
+ value: t.state.value,
710
+ onValueChange: (e) => t.handleChange(e),
711
+ children: [/* @__PURE__ */ F(k, {
712
+ id: r("rate-model"),
713
+ className: "w-full",
714
+ children: /* @__PURE__ */ F(O, {})
715
+ }), /* @__PURE__ */ I(A, { children: [
716
+ /* @__PURE__ */ F(j, {
717
+ value: "per_unit",
718
+ children: /* @__PURE__ */ F(e, { id: "Per unit" })
719
+ }),
720
+ /* @__PURE__ */ F(j, {
721
+ value: "tiered",
722
+ children: /* @__PURE__ */ F(e, { id: "Tiered" })
723
+ }),
724
+ /* @__PURE__ */ F(j, {
725
+ value: "package",
726
+ children: /* @__PURE__ */ F(e, { id: "Package" })
727
+ }),
728
+ /* @__PURE__ */ F(j, {
729
+ value: "dynamic",
730
+ disabled: n.aggregation !== "sum",
731
+ children: /* @__PURE__ */ F(e, { id: "Dynamic (event amount)" })
732
+ })
733
+ ] })]
734
+ })]
735
+ })
736
+ });
737
+ }
738
+ function Ve({ form: t, meter: n }) {
739
+ let { id: r, text: a } = i();
740
+ return /* @__PURE__ */ I(P, { children: [
741
+ /* @__PURE__ */ F(t.Field, {
742
+ name: "matrixEnabled",
743
+ children: (t) => /* @__PURE__ */ I("div", {
744
+ className: "flex items-center justify-between gap-4 rounded-lg bg-muted/50 px-3 py-2.5",
745
+ children: [/* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F(D, {
746
+ htmlFor: r("rate-matrix"),
747
+ children: /* @__PURE__ */ F(e, { id: "Use matrix rates" })
748
+ }), /* @__PURE__ */ F("p", {
749
+ className: "text-xs text-muted-foreground",
750
+ children: /* @__PURE__ */ F(e, { id: "Price each value of one registered dimension separately." })
751
+ })] }), /* @__PURE__ */ F(de, {
752
+ id: r("rate-matrix"),
753
+ checked: t.state.value,
754
+ onCheckedChange: t.handleChange,
755
+ disabled: Object.keys(n.group_by ?? {}).length === 0
756
+ })]
757
+ })
758
+ }),
759
+ /* @__PURE__ */ F(t.Subscribe, {
760
+ selector: (e) => e.values.matrixEnabled,
761
+ children: (e) => e ? /* @__PURE__ */ F(He, {
762
+ form: t,
763
+ meter: n
764
+ }) : /* @__PURE__ */ F(t.Field, {
765
+ name: "unitAmount",
766
+ children: (e) => /* @__PURE__ */ F(q, {
767
+ id: "rate-unit-amount",
768
+ label: a("Price per divisor"),
769
+ value: e.state.value,
770
+ onChange: e.handleChange,
771
+ placeholder: "0.0025"
772
+ })
773
+ })
774
+ }),
775
+ /* @__PURE__ */ I("div", {
776
+ className: "grid gap-4 sm:grid-cols-3",
777
+ children: [
778
+ /* @__PURE__ */ F(t.Field, {
779
+ name: "divideBy",
780
+ children: (e) => /* @__PURE__ */ F(K, {
781
+ id: "rate-divide-by",
782
+ label: a("Divisor"),
783
+ value: e.state.value,
784
+ onChange: e.handleChange,
785
+ inputMode: "numeric",
786
+ placeholder: "1"
787
+ })
788
+ }),
789
+ /* @__PURE__ */ F(t.Field, {
790
+ name: "round",
791
+ children: (t) => /* @__PURE__ */ I("div", {
792
+ className: "grid gap-1.5",
793
+ children: [/* @__PURE__ */ F(D, {
794
+ htmlFor: r("rate-round"),
795
+ children: /* @__PURE__ */ F(e, { id: "Rounding" })
796
+ }), /* @__PURE__ */ I(M, {
797
+ value: t.state.value,
798
+ onValueChange: (e) => t.handleChange(e),
799
+ children: [/* @__PURE__ */ F(k, {
800
+ id: r("rate-round"),
801
+ className: "w-full",
802
+ children: /* @__PURE__ */ F(O, {})
803
+ }), /* @__PURE__ */ I(A, { children: [
804
+ /* @__PURE__ */ F(j, {
805
+ value: "half_up",
806
+ children: /* @__PURE__ */ F(e, { id: "Nearest" })
807
+ }),
808
+ /* @__PURE__ */ F(j, {
809
+ value: "up",
810
+ children: /* @__PURE__ */ F(e, { id: "Up" })
811
+ }),
812
+ /* @__PURE__ */ F(j, {
813
+ value: "down",
814
+ children: /* @__PURE__ */ F(e, { id: "Down" })
815
+ })
816
+ ] })]
817
+ })]
818
+ })
819
+ }),
820
+ /* @__PURE__ */ F(t.Field, {
821
+ name: "maximumAmount",
822
+ children: (e) => /* @__PURE__ */ F(q, {
823
+ id: "rate-maximum",
824
+ label: a("Period maximum"),
825
+ value: e.state.value,
826
+ onChange: e.handleChange,
827
+ placeholder: a("No maximum")
828
+ })
829
+ })
830
+ ]
831
+ })
832
+ ] });
833
+ }
834
+ function He({ form: t, meter: n }) {
835
+ let { id: r, text: a } = i(), o = N.useContext(G);
836
+ return /* @__PURE__ */ I(P, { children: [/* @__PURE__ */ F(t.Field, {
837
+ name: "matrixDimension",
838
+ children: (t) => /* @__PURE__ */ I("div", {
839
+ className: "grid gap-1.5",
840
+ children: [
841
+ /* @__PURE__ */ F(D, {
842
+ htmlFor: r("matrix-dimension"),
843
+ children: /* @__PURE__ */ F(e, { id: "Dimension" })
844
+ }),
845
+ /* @__PURE__ */ I(M, {
846
+ value: t.state.value || null,
847
+ onValueChange: (e) => t.handleChange(e ?? ""),
848
+ children: [/* @__PURE__ */ F(k, {
849
+ id: r("matrix-dimension"),
850
+ className: "w-full",
851
+ ...Y("matrix-dimension", o),
852
+ children: /* @__PURE__ */ F(O, { placeholder: a("Select dimension") })
853
+ }), /* @__PURE__ */ F(A, { children: Object.keys(n.group_by ?? {}).map((e) => /* @__PURE__ */ F(j, {
854
+ value: e,
855
+ children: e
856
+ }, e)) })]
857
+ }),
858
+ /* @__PURE__ */ F(X, { fieldId: "matrix-dimension" })
859
+ ]
860
+ })
861
+ }), /* @__PURE__ */ F(t.Field, {
862
+ name: "matrixCells",
863
+ mode: "array",
864
+ children: (n) => /* @__PURE__ */ I("div", {
865
+ className: "grid gap-2",
866
+ children: [
867
+ /* @__PURE__ */ I("div", {
868
+ className: "flex items-center justify-between gap-3",
869
+ children: [/* @__PURE__ */ F(D, { children: /* @__PURE__ */ F(e, { id: "Matrix cells" }) }), /* @__PURE__ */ I(v, {
870
+ id: r("matrix-add-cell"),
871
+ type: "button",
872
+ variant: "outline",
873
+ size: "sm",
874
+ onClick: () => n.pushValue({
875
+ key: "",
876
+ unitAmount: "",
877
+ maximumAmount: ""
878
+ }),
879
+ children: [/* @__PURE__ */ F(L, {
880
+ icon: R,
881
+ className: "size-4"
882
+ }), /* @__PURE__ */ F(e, { id: "Add cell" })]
883
+ })]
884
+ }),
885
+ /* @__PURE__ */ F(X, { fieldId: "matrix-add-cell" }),
886
+ n.state.value.length > 0 && /* @__PURE__ */ I("div", {
887
+ className: "hidden gap-2 px-0.5 text-xs text-muted-foreground sm:grid sm:grid-cols-[1fr_1fr_1fr_auto]",
888
+ children: [
889
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Value" }) }),
890
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Unit price" }) }),
891
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Maximum" }) }),
892
+ /* @__PURE__ */ F("span", {
893
+ className: "size-8",
894
+ "aria-hidden": "true"
895
+ })
896
+ ]
897
+ }),
898
+ n.state.value.map((e, r) => /* @__PURE__ */ I("div", {
899
+ className: "grid gap-2 sm:grid-cols-[1fr_1fr_1fr_auto]",
900
+ children: [
901
+ /* @__PURE__ */ F(J, {
902
+ id: `matrix-cell-${r}-value`,
903
+ label: a("Value"),
904
+ value: e.key,
905
+ onChange: (e) => t.setFieldValue(`matrixCells[${r}].key`, e),
906
+ placeholder: a("gpt-5")
907
+ }),
908
+ /* @__PURE__ */ F(J, {
909
+ id: `matrix-cell-${r}-unit-price`,
910
+ label: a("Unit price"),
911
+ value: e.unitAmount,
912
+ onChange: (e) => t.setFieldValue(`matrixCells[${r}].unitAmount`, e),
913
+ inputMode: "decimal",
914
+ placeholder: a("Price")
915
+ }),
916
+ /* @__PURE__ */ F(J, {
917
+ id: `matrix-cell-${r}-maximum`,
918
+ label: a("Maximum"),
919
+ value: e.maximumAmount,
920
+ onChange: (e) => t.setFieldValue(`matrixCells[${r}].maximumAmount`, e),
921
+ inputMode: "decimal",
922
+ placeholder: a("Maximum")
923
+ }),
924
+ /* @__PURE__ */ F(Ye, {
925
+ label: `Remove matrix cell ${r + 1}`,
926
+ onClick: () => n.removeValue(r)
927
+ })
928
+ ]
929
+ }, r))
930
+ ]
931
+ })
932
+ })] });
933
+ }
934
+ function Ue({ form: t }) {
935
+ let { id: n, text: r } = i();
936
+ return /* @__PURE__ */ F(P, { children: /* @__PURE__ */ F(t.Field, {
937
+ name: "tiers",
938
+ mode: "array",
939
+ children: (i) => /* @__PURE__ */ I("div", {
940
+ className: "grid gap-2",
941
+ children: [
942
+ /* @__PURE__ */ I("div", {
943
+ className: "flex items-center justify-between gap-3",
944
+ children: [/* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F(D, { children: /* @__PURE__ */ F(e, { id: "Tiers" }) }), /* @__PURE__ */ F("p", {
945
+ className: "text-xs text-muted-foreground",
946
+ children: /* @__PURE__ */ F(e, { id: "Leave the final limit blank for the unbounded tier." })
947
+ })] }), /* @__PURE__ */ I(v, {
948
+ id: n("tier-add"),
949
+ type: "button",
950
+ variant: "outline",
951
+ size: "sm",
952
+ onClick: () => i.pushValue({
953
+ upTo: "",
954
+ unitAmount: "",
955
+ flatAmount: ""
956
+ }),
957
+ children: [/* @__PURE__ */ F(L, {
958
+ icon: R,
959
+ className: "size-4"
960
+ }), /* @__PURE__ */ F(e, { id: "Add tier" })]
961
+ })]
962
+ }),
963
+ /* @__PURE__ */ F(X, { fieldId: "tier-add" }),
964
+ i.state.value.length > 0 && /* @__PURE__ */ I("div", {
965
+ className: "hidden gap-2 px-0.5 text-xs text-muted-foreground sm:grid sm:grid-cols-[1fr_1fr_1fr_auto]",
966
+ children: [
967
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Upper limit" }) }),
968
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Unit price" }) }),
969
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Flat amount" }) }),
970
+ /* @__PURE__ */ F("span", {
971
+ className: "size-8",
972
+ "aria-hidden": "true"
973
+ })
974
+ ]
975
+ }),
976
+ i.state.value.map((e, n) => /* @__PURE__ */ I("div", {
977
+ className: "grid gap-2 sm:grid-cols-[1fr_1fr_1fr_auto]",
978
+ children: [
979
+ /* @__PURE__ */ F(J, {
980
+ id: `tier-${n}-limit`,
981
+ label: r("Upper limit"),
982
+ value: e.upTo,
983
+ onChange: (e) => t.setFieldValue(`tiers[${n}].upTo`, e),
984
+ inputMode: "numeric",
985
+ placeholder: n === i.state.value.length - 1 ? "No limit" : "Up to"
986
+ }),
987
+ /* @__PURE__ */ F(J, {
988
+ id: `tier-${n}-unit-price`,
989
+ label: r("Unit price"),
990
+ value: e.unitAmount,
991
+ onChange: (e) => t.setFieldValue(`tiers[${n}].unitAmount`, e),
992
+ inputMode: "decimal",
993
+ placeholder: r("Unit price")
994
+ }),
995
+ /* @__PURE__ */ F(J, {
996
+ id: `tier-${n}-flat-amount`,
997
+ label: r("Flat amount"),
998
+ value: e.flatAmount,
999
+ onChange: (e) => t.setFieldValue(`tiers[${n}].flatAmount`, e),
1000
+ inputMode: "decimal",
1001
+ placeholder: r("Flat amount")
1002
+ }),
1003
+ /* @__PURE__ */ F(Ye, {
1004
+ label: `Remove tier ${n + 1}`,
1005
+ onClick: () => i.removeValue(n),
1006
+ disabled: i.state.value.length === 1
1007
+ })
1008
+ ]
1009
+ }, n))
1010
+ ]
1011
+ })
1012
+ }) });
1013
+ }
1014
+ function We({ form: e }) {
1015
+ let { text: t } = i();
1016
+ return /* @__PURE__ */ I("div", {
1017
+ className: "grid gap-4 sm:grid-cols-3",
1018
+ children: [
1019
+ /* @__PURE__ */ F(e.Field, {
1020
+ name: "packageAmount",
1021
+ children: (e) => /* @__PURE__ */ F(q, {
1022
+ id: "package-amount",
1023
+ label: t("Package price"),
1024
+ value: e.state.value,
1025
+ onChange: e.handleChange,
1026
+ placeholder: "10.00"
1027
+ })
1028
+ }),
1029
+ /* @__PURE__ */ F(e.Field, {
1030
+ name: "packageSize",
1031
+ children: (e) => /* @__PURE__ */ F(K, {
1032
+ id: "package-size",
1033
+ label: t("Units per package"),
1034
+ value: e.state.value,
1035
+ onChange: e.handleChange,
1036
+ inputMode: "numeric",
1037
+ placeholder: "1000"
1038
+ })
1039
+ }),
1040
+ /* @__PURE__ */ F(e.Field, {
1041
+ name: "freeUnits",
1042
+ children: (e) => /* @__PURE__ */ F(K, {
1043
+ id: "package-free",
1044
+ label: t("Free units"),
1045
+ value: e.state.value,
1046
+ onChange: e.handleChange,
1047
+ inputMode: "numeric",
1048
+ placeholder: "0"
1049
+ })
1050
+ })
1051
+ ]
1052
+ });
1053
+ }
1054
+ function Ge({ form: t, meter: n }) {
1055
+ let { id: r, text: a } = i(), o = N.useContext(G);
1056
+ return /* @__PURE__ */ I("section", {
1057
+ className: "grid gap-3 border-t pt-5",
1058
+ children: [/* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F("h3", {
1059
+ className: "text-sm font-medium",
1060
+ children: /* @__PURE__ */ F(e, { id: "Event filters" })
1061
+ }), /* @__PURE__ */ F("p", {
1062
+ className: "text-xs text-muted-foreground",
1063
+ children: /* @__PURE__ */ F(e, { id: "Optional. Only events with one of the listed dimension values are rated." })
1064
+ })] }), /* @__PURE__ */ F(t.Field, {
1065
+ name: "filters",
1066
+ mode: "array",
1067
+ children: (i) => /* @__PURE__ */ I("div", {
1068
+ className: "grid gap-2",
1069
+ children: [
1070
+ i.state.value.length > 0 && /* @__PURE__ */ I("div", {
1071
+ className: "hidden gap-2 px-0.5 text-xs text-muted-foreground sm:grid sm:grid-cols-[1fr_2fr_auto]",
1072
+ children: [
1073
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Dimension" }) }),
1074
+ /* @__PURE__ */ F("span", { children: /* @__PURE__ */ F(e, { id: "Values" }) }),
1075
+ /* @__PURE__ */ F("span", {
1076
+ className: "size-8",
1077
+ "aria-hidden": "true"
1078
+ })
1079
+ ]
1080
+ }),
1081
+ i.state.value.map((s, c) => /* @__PURE__ */ I("div", {
1082
+ className: "grid gap-2 sm:grid-cols-[1fr_2fr_auto]",
1083
+ children: [
1084
+ /* @__PURE__ */ I("div", {
1085
+ className: "grid gap-1.5",
1086
+ children: [
1087
+ /* @__PURE__ */ F(D, {
1088
+ htmlFor: r(`filter-${c}-dimension`),
1089
+ className: "text-xs text-muted-foreground sm:sr-only",
1090
+ children: /* @__PURE__ */ F(e, { id: "Dimension" })
1091
+ }),
1092
+ /* @__PURE__ */ I(M, {
1093
+ value: s.key || null,
1094
+ onValueChange: (e) => t.setFieldValue(`filters[${c}].key`, e ?? ""),
1095
+ children: [/* @__PURE__ */ F(k, {
1096
+ id: r(`filter-${c}-dimension`),
1097
+ className: "w-full",
1098
+ ...Y(`filter-${c}-dimension`, o),
1099
+ children: /* @__PURE__ */ F(O, { placeholder: a("Dimension") })
1100
+ }), /* @__PURE__ */ F(A, { children: Object.keys(n.group_by ?? {}).map((e) => /* @__PURE__ */ F(j, {
1101
+ value: e,
1102
+ children: e
1103
+ }, e)) })]
1104
+ }),
1105
+ /* @__PURE__ */ F(X, { fieldId: `filter-${c}-dimension` })
1106
+ ]
1107
+ }),
1108
+ /* @__PURE__ */ F(J, {
1109
+ id: `filter-${c}-values`,
1110
+ label: a("Values"),
1111
+ value: s.value,
1112
+ onChange: (e) => t.setFieldValue(`filters[${c}].value`, e),
1113
+ placeholder: a("eu, us")
1114
+ }),
1115
+ /* @__PURE__ */ F(Ye, {
1116
+ label: `Remove filter ${c + 1}`,
1117
+ onClick: () => i.removeValue(c)
1118
+ })
1119
+ ]
1120
+ }, c)),
1121
+ /* @__PURE__ */ I(v, {
1122
+ type: "button",
1123
+ variant: "outline",
1124
+ size: "sm",
1125
+ className: "w-fit",
1126
+ disabled: Object.keys(n.group_by ?? {}).length === 0,
1127
+ onClick: () => i.pushValue({
1128
+ key: "",
1129
+ value: ""
1130
+ }),
1131
+ children: [/* @__PURE__ */ F(L, {
1132
+ icon: R,
1133
+ className: "size-4"
1134
+ }), /* @__PURE__ */ F(e, { id: "Add filter" })]
1135
+ })
1136
+ ]
1137
+ })
1138
+ })]
1139
+ });
1140
+ }
1141
+ function Ke({ form: t }) {
1142
+ let { id: n, text: r } = i();
1143
+ return /* @__PURE__ */ I("section", {
1144
+ className: "grid gap-4 border-t pt-5",
1145
+ children: [
1146
+ /* @__PURE__ */ F("h3", {
1147
+ className: "text-sm font-medium",
1148
+ children: /* @__PURE__ */ F(e, { id: "Allowance" })
1149
+ }),
1150
+ /* @__PURE__ */ F(t.Field, {
1151
+ name: "allowanceMode",
1152
+ children: (t) => /* @__PURE__ */ I("div", {
1153
+ className: "grid gap-1.5",
1154
+ children: [/* @__PURE__ */ F(D, {
1155
+ htmlFor: n("allowance-mode"),
1156
+ children: /* @__PURE__ */ F(e, { id: "Included usage" })
1157
+ }), /* @__PURE__ */ I(M, {
1158
+ value: t.state.value,
1159
+ onValueChange: (e) => t.handleChange(e),
1160
+ children: [/* @__PURE__ */ F(k, {
1161
+ id: n("allowance-mode"),
1162
+ className: "w-full",
1163
+ children: /* @__PURE__ */ F(O, {})
1164
+ }), /* @__PURE__ */ I(A, { children: [/* @__PURE__ */ F(j, {
1165
+ value: "none",
1166
+ children: /* @__PURE__ */ F(e, { id: "No allowance" })
1167
+ }), /* @__PURE__ */ F(j, {
1168
+ value: "included",
1169
+ children: /* @__PURE__ */ F(e, { id: "Fixed included units" })
1170
+ })] })]
1171
+ })]
1172
+ })
1173
+ }),
1174
+ /* @__PURE__ */ F(t.Subscribe, {
1175
+ selector: (e) => e.values.allowanceMode,
1176
+ children: (e) => e === "included" ? /* @__PURE__ */ F(t.Field, {
1177
+ name: "allowanceIncluded",
1178
+ children: (e) => /* @__PURE__ */ F(K, {
1179
+ id: "allowance-included",
1180
+ label: r("Included units per period"),
1181
+ value: e.state.value,
1182
+ onChange: e.handleChange,
1183
+ inputMode: "numeric",
1184
+ placeholder: "1000"
1185
+ })
1186
+ }) : null
1187
+ })
1188
+ ]
1189
+ });
1190
+ }
1191
+ function qe({ values: t }) {
1192
+ let n = "Complete the required fields to preview this rate.";
1193
+ try {
1194
+ let e = ke(t);
1195
+ n = Ie({ price: e.price }), e.allowance?.included !== void 0 && (n += ` · ${e.allowance.included.toLocaleString()} included`);
1196
+ } catch {}
1197
+ return /* @__PURE__ */ I("section", {
1198
+ className: "rounded-lg bg-muted/50 px-3 py-2.5",
1199
+ "aria-live": "polite",
1200
+ children: [/* @__PURE__ */ F("p", {
1201
+ className: "text-xs font-medium text-muted-foreground",
1202
+ children: /* @__PURE__ */ F(e, { id: "Rate preview" })
1203
+ }), /* @__PURE__ */ F("p", {
1204
+ className: "mt-1 text-sm font-medium tabular-nums",
1205
+ children: n
1206
+ })]
1207
+ });
1208
+ }
1209
+ function K({ id: e, label: t, value: n, onChange: r, placeholder: a, inputMode: o }) {
1210
+ let { id: s } = i(), c = Je(e);
1211
+ return /* @__PURE__ */ I("div", {
1212
+ className: "grid gap-1.5",
1213
+ children: [
1214
+ /* @__PURE__ */ F(D, {
1215
+ htmlFor: s(e),
1216
+ children: t
1217
+ }),
1218
+ /* @__PURE__ */ F(y, {
1219
+ id: s(e),
1220
+ value: n,
1221
+ onChange: (e) => r(e.target.value),
1222
+ placeholder: a,
1223
+ inputMode: o,
1224
+ autoComplete: "off",
1225
+ ...Y(e, c ? {
1226
+ fieldId: e,
1227
+ message: c
1228
+ } : null)
1229
+ }),
1230
+ /* @__PURE__ */ F(X, { fieldId: e })
1231
+ ]
1232
+ });
1233
+ }
1234
+ function q(e) {
1235
+ return /* @__PURE__ */ F(K, {
1236
+ ...e,
1237
+ inputMode: "decimal"
1238
+ });
1239
+ }
1240
+ function J({ id: e, label: t, value: n, onChange: r, placeholder: a, inputMode: o }) {
1241
+ let { id: s } = i(), c = Je(e);
1242
+ return /* @__PURE__ */ I("div", {
1243
+ className: "grid gap-1.5",
1244
+ children: [
1245
+ /* @__PURE__ */ F(D, {
1246
+ htmlFor: s(e),
1247
+ className: "text-xs text-muted-foreground sm:sr-only",
1248
+ children: t
1249
+ }),
1250
+ /* @__PURE__ */ F(y, {
1251
+ id: s(e),
1252
+ value: n,
1253
+ onChange: (e) => r(e.target.value),
1254
+ placeholder: a,
1255
+ inputMode: o,
1256
+ autoComplete: "off",
1257
+ ...Y(e, c ? {
1258
+ fieldId: e,
1259
+ message: c
1260
+ } : null)
1261
+ }),
1262
+ /* @__PURE__ */ F(X, { fieldId: e })
1263
+ ]
1264
+ });
1265
+ }
1266
+ function Je(e) {
1267
+ let t = N.useContext(G);
1268
+ return t?.fieldId === e ? t.message : void 0;
1269
+ }
1270
+ function Y(e, t) {
1271
+ let n = t?.fieldId === e;
1272
+ return {
1273
+ "aria-invalid": n || void 0,
1274
+ "aria-describedby": n ? `${e}-error` : void 0
1275
+ };
1276
+ }
1277
+ function X({ fieldId: e }) {
1278
+ let { id: t } = i(), n = Je(e);
1279
+ return n ? /* @__PURE__ */ F("p", {
1280
+ id: t(`${e}-error`),
1281
+ className: "text-xs text-destructive",
1282
+ children: n
1283
+ }) : null;
1284
+ }
1285
+ function Ye({ label: e, onClick: t, disabled: n }) {
1286
+ return /* @__PURE__ */ F(v, {
1287
+ type: "button",
1288
+ variant: "ghost",
1289
+ size: "icon",
1290
+ "aria-label": e,
1291
+ onClick: t,
1292
+ disabled: n,
1293
+ className: "self-end",
1294
+ children: /* @__PURE__ */ F(L, {
1295
+ icon: z,
1296
+ className: "size-4"
1297
+ })
1298
+ });
1299
+ }
1300
+ // src/admin/pages/catalog/metering.tsx
1301
+ var Xe = 200;
1302
+ function Ze() {
1303
+ let { text: n } = i(), { adminQueries: a } = r(), [o, s] = N.useState(""), c = p("", Xe), { data: l, isPending: u, error: d, refetch: f } = pe(a.usageMeters(c.size, c.cursor)), h = T(), g = l?.data ?? [], _ = o.trim().toLowerCase(), b = _ ? g.filter((e) => [
1304
+ e.key,
1305
+ e.event_type,
1306
+ e.aggregation,
1307
+ e.unit,
1308
+ e.rate_card?.product_key
1309
+ ].some((e) => e?.toLowerCase().includes(_))) : g, E = we({
1310
+ pending: u,
1311
+ error: d instanceof t ? d : d ? { status: 500 } : null,
1312
+ count: g.length
1313
+ });
1314
+ return /* @__PURE__ */ I("div", {
1315
+ className: "flex min-w-0 flex-col gap-5",
1316
+ children: [
1317
+ /* @__PURE__ */ I("div", {
1318
+ className: "flex flex-wrap items-start justify-between gap-4",
1319
+ children: [/* @__PURE__ */ I("div", {
1320
+ className: "max-w-2xl",
1321
+ children: [/* @__PURE__ */ F("h1", {
1322
+ className: "text-2xl font-semibold tracking-tight text-balance",
1323
+ children: /* @__PURE__ */ F(e, { id: "Metering" })
1324
+ }), /* @__PURE__ */ F("p", {
1325
+ className: "mt-1 text-sm text-pretty text-muted-foreground",
1326
+ children: /* @__PURE__ */ F(e, { id: "Define usage streams and the default rates charged when usage is recorded. Applications report the events separately." })
1327
+ })]
1328
+ }), h && E !== "permission" && /* @__PURE__ */ F(Re, { writesAllowed: !0 })]
1329
+ }),
1330
+ l && !h && /* @__PURE__ */ F(Q, { children: /* @__PURE__ */ F(e, { id: "Catalog updates are disabled. Meter definitions and rates are visible here; changes require the host operator." }) }),
1331
+ E === "loading" ? /* @__PURE__ */ F(tt, {}) : E === "permission" ? /* @__PURE__ */ F($, {
1332
+ title: n("Metering access is restricted"),
1333
+ description: n("Your role does not have permission to read the merchant catalog.")
1334
+ }) : E === "error" ? /* @__PURE__ */ F($, {
1335
+ title: n("Metering could not be loaded"),
1336
+ description: n("Try again. If the problem continues, check the OpenRails API logs."),
1337
+ action: /* @__PURE__ */ F(v, {
1338
+ variant: "outline",
1339
+ size: "sm",
1340
+ onClick: () => void f(),
1341
+ children: /* @__PURE__ */ F(e, { id: "Try again" })
1342
+ })
1343
+ }) : E === "empty" ? /* @__PURE__ */ F($, {
1344
+ title: n("No usage meters yet"),
1345
+ description: n("Create a meter to describe the events your application will report and bill."),
1346
+ action: h ? /* @__PURE__ */ F(Re, { writesAllowed: !0 }) : void 0
1347
+ }) : /* @__PURE__ */ I(P, { children: [
1348
+ /* @__PURE__ */ I("div", {
1349
+ className: "relative w-full sm:max-w-xs",
1350
+ children: [/* @__PURE__ */ F(L, {
1351
+ icon: xe,
1352
+ className: "absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground"
1353
+ }), /* @__PURE__ */ F(y, {
1354
+ value: o,
1355
+ onChange: (e) => s(e.target.value),
1356
+ className: "pl-8",
1357
+ placeholder: n("Filter this page…"),
1358
+ "aria-label": n("Filter meters on this page")
1359
+ })]
1360
+ }),
1361
+ /* @__PURE__ */ F("div", {
1362
+ className: "max-w-full overflow-x-auto",
1363
+ children: /* @__PURE__ */ I(w, { children: [/* @__PURE__ */ F(te, { children: /* @__PURE__ */ I(C, {
1364
+ className: "hover:bg-transparent",
1365
+ children: [
1366
+ /* @__PURE__ */ F(x, {
1367
+ className: "text-muted-foreground",
1368
+ children: /* @__PURE__ */ F(e, { id: "Meter" })
1369
+ }),
1370
+ /* @__PURE__ */ F(x, {
1371
+ className: "text-muted-foreground",
1372
+ children: /* @__PURE__ */ F(e, { id: "Event" })
1373
+ }),
1374
+ /* @__PURE__ */ F(x, {
1375
+ className: "text-muted-foreground",
1376
+ children: /* @__PURE__ */ F(e, { id: "Aggregation" })
1377
+ }),
1378
+ /* @__PURE__ */ F(x, {
1379
+ className: "text-muted-foreground",
1380
+ children: /* @__PURE__ */ F(e, { id: "Default price" })
1381
+ }),
1382
+ /* @__PURE__ */ F(x, {
1383
+ className: "text-muted-foreground",
1384
+ children: /* @__PURE__ */ F(e, { id: "Product" })
1385
+ }),
1386
+ /* @__PURE__ */ F(x, {
1387
+ className: "text-muted-foreground",
1388
+ children: /* @__PURE__ */ F(e, { id: "Activity" })
1389
+ }),
1390
+ /* @__PURE__ */ F(x, {
1391
+ className: "text-muted-foreground",
1392
+ children: /* @__PURE__ */ F(e, { id: "Last event" })
1393
+ }),
1394
+ /* @__PURE__ */ F(x, { children: /* @__PURE__ */ F("span", {
1395
+ className: "sr-only",
1396
+ children: /* @__PURE__ */ F(e, { id: "Open" })
1397
+ }) })
1398
+ ]
1399
+ }) }), /* @__PURE__ */ I(ee, { children: [b.map((e) => /* @__PURE__ */ F(Qe, { meter: e }, e.key)), b.length === 0 && /* @__PURE__ */ F(C, { children: /* @__PURE__ */ I(S, {
1400
+ colSpan: 9,
1401
+ className: "h-24 text-center text-muted-foreground",
1402
+ children: [
1403
+ /* @__PURE__ */ F(e, { id: "No meters on this page match “" }),
1404
+ o,
1405
+ "”."
1406
+ ]
1407
+ }) })] })] })
1408
+ }),
1409
+ /* @__PURE__ */ F(m, {
1410
+ pages: c,
1411
+ rows: l?.data?.length ?? 0,
1412
+ nextCursor: l?.next_cursor,
1413
+ busy: u,
1414
+ sizes: [
1415
+ 100,
1416
+ 200,
1417
+ 500
1418
+ ]
1419
+ })
1420
+ ] })
1421
+ ]
1422
+ });
1423
+ }
1424
+ function Qe({ meter: e }) {
1425
+ return /* @__PURE__ */ I(g, {
1426
+ to: `/catalog/metering/${encodeURIComponent(e.key)}`,
1427
+ children: [
1428
+ /* @__PURE__ */ I(S, { children: [/* @__PURE__ */ F(f, {
1429
+ className: "font-medium underline-offset-3 hover:underline",
1430
+ to: `/catalog/metering/${encodeURIComponent(e.key)}`,
1431
+ children: e.key
1432
+ }), e.unit && /* @__PURE__ */ F("p", {
1433
+ className: "text-xs text-muted-foreground",
1434
+ children: e.unit
1435
+ })] }),
1436
+ /* @__PURE__ */ F(S, { children: e.event_type }),
1437
+ /* @__PURE__ */ F(S, { children: /* @__PURE__ */ F(_, {
1438
+ variant: "secondary",
1439
+ children: e.aggregation
1440
+ }) }),
1441
+ /* @__PURE__ */ F(S, {
1442
+ className: "font-medium tabular-nums",
1443
+ children: Ie(e.rate_card)
1444
+ }),
1445
+ /* @__PURE__ */ F(S, { children: e.rate_card?.product_key ?? "—" }),
1446
+ /* @__PURE__ */ F(S, { children: /* @__PURE__ */ I("span", {
1447
+ className: "inline-flex items-center gap-1.5 text-sm",
1448
+ children: [/* @__PURE__ */ F("span", { className: `size-1.5 rounded-full ${e.has_activity ? "bg-settled" : "bg-muted-foreground/50"}` }), e.has_activity ? "Active" : "No events"]
1449
+ }) }),
1450
+ /* @__PURE__ */ F(S, {
1451
+ className: "text-muted-foreground tabular-nums",
1452
+ children: o(e.last_event_at)
1453
+ }),
1454
+ /* @__PURE__ */ F(S, {
1455
+ className: "text-right",
1456
+ children: /* @__PURE__ */ F(L, {
1457
+ icon: _e,
1458
+ className: "ml-auto size-4 text-muted-foreground"
1459
+ })
1460
+ })
1461
+ ]
1462
+ });
1463
+ }
1464
+ function $e() {
1465
+ let { text: a } = i(), { adminQueries: o } = r(), { key: c = "" } = s(), l = c, u = n(), d = pe(o.usageMeter(l)), f = T(), p = pe(o.allProducts({ errorAction: "Load products for metering" }));
1466
+ if (d.isPending) return /* @__PURE__ */ F(nt, {});
1467
+ if (d.error) {
1468
+ let e = d.error instanceof t && d.error.status === 404, n = d.error instanceof t && d.error.status === 403;
1469
+ return /* @__PURE__ */ F($, {
1470
+ title: n ? "Metering access is restricted" : e ? "Meter not found" : "Meter could not be loaded",
1471
+ description: n ? "Your role does not have permission to read this meter." : e ? "This meter does not exist in the active merchant catalog." : "Try loading the meter again.",
1472
+ action: n ? void 0 : /* @__PURE__ */ F(v, {
1473
+ variant: "outline",
1474
+ size: "sm",
1475
+ onClick: () => e ? u("/catalog/metering") : void d.refetch(),
1476
+ children: e ? "Back to metering" : "Try again"
1477
+ })
1478
+ });
1479
+ }
1480
+ let m = d.data;
1481
+ if (!m) return null;
1482
+ let h = Le(m, f);
1483
+ return /* @__PURE__ */ I("div", {
1484
+ className: "flex min-w-0 flex-col gap-8",
1485
+ children: [
1486
+ /* @__PURE__ */ I("header", {
1487
+ className: "flex flex-wrap items-start gap-3",
1488
+ children: [
1489
+ /* @__PURE__ */ F(v, {
1490
+ variant: "ghost",
1491
+ size: "icon",
1492
+ onClick: () => u("/catalog/metering"),
1493
+ "aria-label": a("Back to metering"),
1494
+ children: /* @__PURE__ */ F(L, {
1495
+ icon: ge,
1496
+ className: "size-4"
1497
+ })
1498
+ }),
1499
+ /* @__PURE__ */ I("div", {
1500
+ className: "min-w-0 flex-1",
1501
+ children: [/* @__PURE__ */ I("div", {
1502
+ className: "flex flex-wrap items-center gap-2",
1503
+ children: [/* @__PURE__ */ F("h1", {
1504
+ className: "truncate text-xl font-semibold tracking-tight",
1505
+ children: m.key
1506
+ }), !f && /* @__PURE__ */ F(_, {
1507
+ variant: "secondary",
1508
+ children: /* @__PURE__ */ F(e, { id: "read-only" })
1509
+ })]
1510
+ }), /* @__PURE__ */ I("p", {
1511
+ className: "mt-1 text-sm text-muted-foreground",
1512
+ children: [
1513
+ m.event_type,
1514
+ " · ",
1515
+ m.aggregation,
1516
+ m.unit ? ` · ${m.unit}` : ""
1517
+ ]
1518
+ })]
1519
+ }),
1520
+ /* @__PURE__ */ I("div", {
1521
+ className: "flex flex-wrap gap-2",
1522
+ children: [/* @__PURE__ */ F(Re, {
1523
+ meter: m,
1524
+ writesAllowed: f
1525
+ }), /* @__PURE__ */ F(ze, {
1526
+ meter: m,
1527
+ writesAllowed: f,
1528
+ products: p.data?.data ?? [],
1529
+ productsPending: p.isPending,
1530
+ productsError: !!p.error,
1531
+ productsForbidden: p.error instanceof t && p.error.status === 403
1532
+ })]
1533
+ })
1534
+ ]
1535
+ }),
1536
+ !f && /* @__PURE__ */ F(Q, { children: /* @__PURE__ */ F(e, { id: "Catalog updates are disabled. The console is read-only." }) }),
1537
+ /* @__PURE__ */ I("section", {
1538
+ className: "grid gap-4",
1539
+ children: [
1540
+ /* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F("h2", {
1541
+ className: "text-base font-semibold",
1542
+ children: /* @__PURE__ */ F(e, { id: "Event contract" })
1543
+ }), /* @__PURE__ */ I("p", {
1544
+ className: "mt-1 max-w-3xl text-sm text-pretty text-muted-foreground",
1545
+ children: [
1546
+ /* @__PURE__ */ F(e, { id: "Creating this meter does not send events. The host application must report idempotent usage to" }),
1547
+ " ",
1548
+ /* @__PURE__ */ F("code", {
1549
+ className: "text-foreground",
1550
+ children: /* @__PURE__ */ F(e, { id: "/app/leases/sync" })
1551
+ }),
1552
+ /* @__PURE__ */ F(e, { id: " with this shape." })
1553
+ ]
1554
+ })] }),
1555
+ /* @__PURE__ */ I("dl", {
1556
+ className: "grid gap-x-8 gap-y-4 border-y py-4 sm:grid-cols-2 lg:grid-cols-4",
1557
+ children: [
1558
+ /* @__PURE__ */ F(Z, {
1559
+ label: a("Event type"),
1560
+ value: m.event_type
1561
+ }),
1562
+ /* @__PURE__ */ F(Z, {
1563
+ label: a("Aggregation"),
1564
+ value: m.aggregation === "sum" ? `Sum ${m.value_property}` : "Count each event"
1565
+ }),
1566
+ /* @__PURE__ */ F(Z, {
1567
+ label: a("Meter key"),
1568
+ value: m.key
1569
+ }),
1570
+ /* @__PURE__ */ F(Z, {
1571
+ label: a("Billing support"),
1572
+ value: m.billing_supported ? "Supported" : "Read only"
1573
+ }),
1574
+ Object.entries(m.group_by ?? {}).map(([e, t]) => /* @__PURE__ */ F(Z, {
1575
+ label: `Dimension: ${e}`,
1576
+ value: t
1577
+ }, e))
1578
+ ]
1579
+ }),
1580
+ h && f && /* @__PURE__ */ I("p", {
1581
+ className: "flex items-center gap-2 text-xs text-muted-foreground",
1582
+ children: [/* @__PURE__ */ F(L, {
1583
+ icon: he,
1584
+ className: "size-4"
1585
+ }), h]
1586
+ })
1587
+ ]
1588
+ }),
1589
+ /* @__PURE__ */ F(et, {
1590
+ meter: m,
1591
+ writesAllowed: f
1592
+ })
1593
+ ]
1594
+ });
1595
+ }
1596
+ function et({ meter: t, writesAllowed: n }) {
1597
+ let { toast: a, toastApiError: s, adminMutations: c } = r(), { text: l } = i(), u = h(), d = me(), f = fe(c.deleteDefaultUsageRateCard(d)), p = t.rate_card, m = async () => {
1598
+ if (await u({
1599
+ title: "Remove the default rate?",
1600
+ description: "New usage for this meter will stop being rated after removal. Billed usage orders and accrued amounts remain unchanged.",
1601
+ confirmLabel: "Remove default",
1602
+ cancelLabel: "Keep rate",
1603
+ tone: "destructive"
1604
+ })) try {
1605
+ await f.mutateAsync(t), a.success("Default rate removed");
1606
+ } catch (e) {
1607
+ s(e, "Remove default rate");
1608
+ }
1609
+ };
1610
+ return /* @__PURE__ */ I("section", {
1611
+ className: "grid gap-4 border-t pt-7",
1612
+ children: [/* @__PURE__ */ I("div", {
1613
+ className: "flex flex-wrap items-start justify-between gap-4",
1614
+ children: [/* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F("h2", {
1615
+ className: "text-base font-semibold",
1616
+ children: /* @__PURE__ */ F(e, { id: "Default rate" })
1617
+ }), /* @__PURE__ */ F("p", {
1618
+ className: "mt-1 text-sm text-muted-foreground",
1619
+ children: /* @__PURE__ */ F(e, { id: "Used for every customer." })
1620
+ })] }), p && n && /* @__PURE__ */ I(v, {
1621
+ variant: "outline",
1622
+ size: "sm",
1623
+ disabled: f.isPending,
1624
+ onClick: () => void m(),
1625
+ children: [/* @__PURE__ */ F(L, {
1626
+ icon: z,
1627
+ className: "size-4"
1628
+ }), f.isPending ? "Removing…" : "Remove default"]
1629
+ })]
1630
+ }), t.billing_supported ? p ? /* @__PURE__ */ I("dl", {
1631
+ className: "grid gap-x-8 gap-y-4 border-y py-4 sm:grid-cols-2 lg:grid-cols-4",
1632
+ children: [
1633
+ /* @__PURE__ */ F(Z, {
1634
+ label: l("Price"),
1635
+ value: Ie(p)
1636
+ }),
1637
+ /* @__PURE__ */ F(Z, {
1638
+ label: l("Product"),
1639
+ value: p.product_key
1640
+ }),
1641
+ /* @__PURE__ */ F(Z, {
1642
+ label: l("Model"),
1643
+ value: p.price.model.replace("_", " ")
1644
+ }),
1645
+ /* @__PURE__ */ F(Z, {
1646
+ label: l("Filter"),
1647
+ value: Object.keys(p.filter ?? {}).length ? Object.entries(p.filter ?? {}).map(([e, t]) => `${e}: ${t.join(", ")}`).join(" · ") : "All matching events"
1648
+ }),
1649
+ /* @__PURE__ */ F(Z, {
1650
+ label: l("Allowance"),
1651
+ value: p.allowance?.included === void 0 ? "None" : `${p.allowance.included.toLocaleString()} included`
1652
+ }),
1653
+ /* @__PURE__ */ F(Z, {
1654
+ label: l("Updated"),
1655
+ value: o(p.updated_at)
1656
+ })
1657
+ ]
1658
+ }) : /* @__PURE__ */ F("p", {
1659
+ className: "border-y py-6 text-sm text-muted-foreground",
1660
+ children: /* @__PURE__ */ F(e, { id: "No default rate. Usage is recorded but is not billed by this meter." })
1661
+ }) : /* @__PURE__ */ F(Q, { children: /* @__PURE__ */ F(e, { id: "This meter uses an aggregation that the billing engine cannot rate." }) })]
1662
+ });
1663
+ }
1664
+ function Z({ label: e, value: t }) {
1665
+ return /* @__PURE__ */ I("div", {
1666
+ className: "min-w-0",
1667
+ children: [/* @__PURE__ */ F("dt", {
1668
+ className: "text-xs text-muted-foreground",
1669
+ children: e
1670
+ }), /* @__PURE__ */ F("dd", {
1671
+ className: "mt-1 text-sm font-medium break-words tabular-nums",
1672
+ children: t || "—"
1673
+ })]
1674
+ });
1675
+ }
1676
+ function Q({ children: e }) {
1677
+ return /* @__PURE__ */ I("div", {
1678
+ className: "flex items-start gap-2 rounded-lg bg-muted/50 px-3 py-2.5 text-sm text-muted-foreground",
1679
+ children: [/* @__PURE__ */ F(L, {
1680
+ icon: ye,
1681
+ className: "mt-0.5 size-4 shrink-0"
1682
+ }), /* @__PURE__ */ F("p", { children: e })]
1683
+ });
1684
+ }
1685
+ function $({ title: e, description: t, action: n }) {
1686
+ return /* @__PURE__ */ I("div", {
1687
+ className: "flex flex-col items-start gap-3 border-y py-10",
1688
+ children: [/* @__PURE__ */ I("div", { children: [/* @__PURE__ */ F("h2", {
1689
+ className: "text-sm font-medium",
1690
+ children: e
1691
+ }), /* @__PURE__ */ F("p", {
1692
+ className: "mt-1 text-sm text-muted-foreground",
1693
+ children: t
1694
+ })] }), n]
1695
+ });
1696
+ }
1697
+ function tt() {
1698
+ return /* @__PURE__ */ I("div", {
1699
+ className: "grid gap-3",
1700
+ children: [/* @__PURE__ */ F(b, { className: "h-8 w-64" }), Array.from({ length: 5 }).map((e, t) => /* @__PURE__ */ F(b, { className: "h-11 w-full" }, t))]
1701
+ });
1702
+ }
1703
+ function nt() {
1704
+ return /* @__PURE__ */ I("div", {
1705
+ className: "grid gap-6",
1706
+ children: [
1707
+ /* @__PURE__ */ F(b, { className: "h-10 w-72" }),
1708
+ /* @__PURE__ */ F(b, { className: "h-28 w-full" }),
1709
+ /* @__PURE__ */ F(b, { className: "h-36 w-full" }),
1710
+ /* @__PURE__ */ F(b, { className: "h-40 w-full" })
1711
+ ]
1712
+ });
1713
+ }
1714
+ export { Ze as CatalogMeteringPage, $e as MeterDetailPage };
1715
+
1716
+ //# sourceMappingURL=admin-metering-OXGOVQ7e.js.map