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