@solvimon/solvimon-web 0.1.0-alpha.16 → 0.1.0-alpha.17

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 (151) hide show
  1. package/README.md +5 -5
  2. package/dist/{BillingInformation.vue_vue_type_script_setup_true_lang-BYBAO4Au.mjs → BillingInformation.vue_vue_type_script_setup_true_lang-BrPsTuoW.mjs} +2 -2
  3. package/dist/{BillingInformation.vue_vue_type_script_setup_true_lang-BI3Lg7nO.js → BillingInformation.vue_vue_type_script_setup_true_lang-BuQ8bzar.js} +1 -1
  4. package/dist/{CustomerPaymentMethods.vue_vue_type_script_setup_true_lang-C_uHr21N.js → CustomerPaymentMethods.vue_vue_type_script_setup_true_lang-1Op9GjGZ.js} +1 -1
  5. package/dist/{CustomerPaymentMethods.vue_vue_type_script_setup_true_lang-CTnn1gkW.mjs → CustomerPaymentMethods.vue_vue_type_script_setup_true_lang-CuWrBcoK.mjs} +3 -3
  6. package/dist/CustomerWalletBalances.vue_vue_type_script_setup_true_lang-C66beqgf.js +1 -0
  7. package/dist/{useWalletBalanceItems-COQDLfoZ.mjs → CustomerWalletBalances.vue_vue_type_script_setup_true_lang-D2BhuXsh.mjs} +24 -56
  8. package/dist/EmptyStatePlaceholder.vue_vue_type_script_setup_true_lang-BbuEBiY3.js +1 -0
  9. package/dist/EmptyStatePlaceholder.vue_vue_type_script_setup_true_lang-C3cqlbGY.mjs +147 -0
  10. package/dist/{InvoiceDetailsBlock.vue_vue_type_script_setup_true_lang-DU6X3zxr.js → InvoiceDetailsBlock.vue_vue_type_script_setup_true_lang-dwIv_xxf.js} +1 -1
  11. package/dist/{InvoiceDetailsBlock.vue_vue_type_script_setup_true_lang-ryvFEQMV.mjs → InvoiceDetailsBlock.vue_vue_type_script_setup_true_lang-wxP5IaGt.mjs} +1 -1
  12. package/dist/{InvoiceHeader.vue_vue_type_script_setup_true_lang-DdpPrYxi.js → InvoiceHeader.vue_vue_type_script_setup_true_lang-05NKI2A0.js} +1 -1
  13. package/dist/{InvoiceHeader.vue_vue_type_script_setup_true_lang-bAiAbtMi.mjs → InvoiceHeader.vue_vue_type_script_setup_true_lang-17v07F58.mjs} +1 -1
  14. package/dist/{PaymentHistoryBlock-BKMttUyk.mjs → PaymentHistoryBlock-BitwS9Re.mjs} +1 -1
  15. package/dist/{PaymentHistoryBlock-BGbTy4Se.js → PaymentHistoryBlock-ZtmPXXwI.js} +1 -1
  16. package/dist/{PaymentHistoryBlock.vue_vue_type_script_setup_true_lang-tM7f_fQS.mjs → PaymentHistoryBlock.vue_vue_type_script_setup_true_lang-C3ZUDUdw.mjs} +1 -1
  17. package/dist/{PaymentHistoryBlock.vue_vue_type_script_setup_true_lang-CixdxEGm.js → PaymentHistoryBlock.vue_vue_type_script_setup_true_lang-CMGK71zZ.js} +1 -1
  18. package/dist/{PaymentIntegrationForm-CypW6fZY.mjs → PaymentIntegrationForm-BK2aLPCo.mjs} +1 -1
  19. package/dist/{PaymentIntegrationForm-D4QupHWl.js → PaymentIntegrationForm-BZTzCUiu.js} +1 -1
  20. package/dist/{PaymentIntegrationForm.vue_vue_type_script_setup_true_lang-CrGSfZZs.mjs → PaymentIntegrationForm.vue_vue_type_script_setup_true_lang-B_yDNGK8.mjs} +5 -5
  21. package/dist/PaymentIntegrationForm.vue_vue_type_script_setup_true_lang-GN3WAr10.js +1 -0
  22. package/dist/{PaymentMethodForm.vue_vue_type_script_setup_true_lang-B8eNptZp.mjs → PaymentMethodForm.vue_vue_type_script_setup_true_lang-CIQ0vsko.mjs} +25 -14
  23. package/dist/PaymentMethodForm.vue_vue_type_script_setup_true_lang-zRr8iihy.js +1 -0
  24. package/dist/PaymentMethodSelector.vue_vue_type_script_setup_true_lang-BQIN3zuf.mjs +156 -0
  25. package/dist/PaymentMethodSelector.vue_vue_type_script_setup_true_lang-DyL2-vV0.js +1 -0
  26. package/dist/{PaymentMethodsList.vue_vue_type_script_setup_true_lang-BUTqn4Ey.mjs → PaymentMethodsList.vue_vue_type_script_setup_true_lang-DVeB_mqK.mjs} +5 -5
  27. package/dist/{PaymentMethodsList.vue_vue_type_script_setup_true_lang-Be_fF-R_.js → PaymentMethodsList.vue_vue_type_script_setup_true_lang-OvGGejpX.js} +1 -1
  28. package/dist/SecurePaymentsKPI.vue_vue_type_script_setup_true_lang-BxqIfmkK.js +1 -0
  29. package/dist/{SecurePaymentsKPI.vue_vue_type_script_setup_true_lang-Cqk-vonA.mjs → SecurePaymentsKPI.vue_vue_type_script_setup_true_lang-D1TcP9PR.mjs} +115 -68
  30. package/dist/SubscriptionSchedules.vue_vue_type_script_setup_true_lang-BKz2QQn9.js +1 -0
  31. package/dist/SubscriptionSchedules.vue_vue_type_script_setup_true_lang-BMXr26gF.mjs +37 -0
  32. package/dist/{SubscriptionsList.vue_vue_type_script_setup_true_lang-DB1p61kZ.mjs → SubscriptionsList.vue_vue_type_script_setup_true_lang-BDqX6OaE.mjs} +22 -119
  33. package/dist/SubscriptionsList.vue_vue_type_script_setup_true_lang-CyAFjCh7.js +1 -0
  34. package/dist/component-CUJ_G2Nw.mjs +962 -0
  35. package/dist/component-CiKxWtdx.js +1 -0
  36. package/dist/components/BillingInformation/BillingInformation.cjs.js +1 -1
  37. package/dist/components/BillingInformation/BillingInformation.es.js +4 -4
  38. package/dist/components/BillingInformationForm/BillingInformationForm.cjs.js +1 -1
  39. package/dist/components/BillingInformationForm/BillingInformationForm.es.js +3 -3
  40. package/dist/components/CustomerPaymentMethods/CustomerPaymentMethods.cjs.js +1 -1
  41. package/dist/components/CustomerPaymentMethods/CustomerPaymentMethods.es.js +4 -4
  42. package/dist/components/Invoice/Invoice.cjs.js +1 -1
  43. package/dist/components/Invoice/Invoice.es.js +7 -7
  44. package/dist/components/InvoiceDetails/InvoiceDetails.cjs.js +1 -1
  45. package/dist/components/InvoiceDetails/InvoiceDetails.es.js +3 -3
  46. package/dist/components/InvoiceHeader/InvoiceHeader.cjs.js +1 -1
  47. package/dist/components/InvoiceHeader/InvoiceHeader.es.js +4 -4
  48. package/dist/components/InvoicesList/InvoicesList.cjs.js +1 -1
  49. package/dist/components/InvoicesList/InvoicesList.es.js +3 -3
  50. package/dist/components/PaymentHistory/PaymentHistory.cjs.js +1 -1
  51. package/dist/components/PaymentHistory/PaymentHistory.es.js +3 -3
  52. package/dist/components/PaymentMethodForm/PaymentMethodForm.cjs.js +1 -1
  53. package/dist/components/PaymentMethodForm/PaymentMethodForm.es.js +6 -6
  54. package/dist/components/SubscriptionSchedules/SubscriptionSchedules.cjs.js +1 -1
  55. package/dist/components/SubscriptionSchedules/SubscriptionSchedules.es.js +7 -58
  56. package/dist/components/SubscriptionsList/SubscriptionsList.cjs.js +1 -1
  57. package/dist/components/SubscriptionsList/SubscriptionsList.es.js +5 -5
  58. package/dist/components/WalletBalances/WalletBalances.cjs.js +1 -1
  59. package/dist/components/WalletBalances/WalletBalances.es.js +8 -6
  60. package/dist/core/action-request.types.d.ts +3 -3
  61. package/dist/core/index.cjs.js +1 -1
  62. package/dist/core/index.es.js +1 -1
  63. package/dist/core/types.d.ts +4 -2
  64. package/dist/{customer-_W8gIX5m.js → customer-AfRcAZ5P.js} +1 -1
  65. package/dist/{customer-Bv_fqXzO.mjs → customer-DAgdegIW.mjs} +1 -1
  66. package/dist/{en-US-DAgOSlgv.mjs → en-US-DSzSbgL5.mjs} +68 -36
  67. package/dist/en-US-QzQnGXP1.js +1 -0
  68. package/dist/index.cjs.js +1 -1
  69. package/dist/index.d.ts +2 -1
  70. package/dist/index.es.js +7 -4
  71. package/dist/invoices-BHgajZHq.js +1 -0
  72. package/dist/{invoices-BGb0AwVF.mjs → invoices-BXDgW8ch.mjs} +32 -16
  73. package/dist/nl-NL-C4rr-1tr.js +1 -0
  74. package/dist/{nl-NL-DCsmrA8A.mjs → nl-NL-Li7RW89R.mjs} +72 -40
  75. package/dist/{paymentMethods-DIbB759g.js → paymentMethods-BMcc-eTl.js} +1 -1
  76. package/dist/{paymentMethods-DvqlWe96.mjs → paymentMethods-xzFD2L30.mjs} +2 -2
  77. package/dist/{payments-DMDDI3MK.js → payments-DMvmB5vg.js} +1 -1
  78. package/dist/{payments-CpzTVrQM.mjs → payments-DV6csRej.mjs} +1 -1
  79. package/dist/pricing-B1uImUm4.mjs +19 -0
  80. package/dist/pricing-BEjY_5wb.js +1 -0
  81. package/dist/pricingPlanSchedule-B9HFiXy-.js +1 -0
  82. package/dist/pricingPlanSchedule-C_cqUyTk.mjs +144 -0
  83. package/dist/registry-CeMxLjwU.js +1 -0
  84. package/dist/{registry-B-If1W_u.mjs → registry-CyENvS6l.mjs} +7 -4
  85. package/dist/screens/Checkout/Checkout.cjs.js +1 -1
  86. package/dist/screens/Checkout/Checkout.es.js +414 -675
  87. package/dist/screens/CustomerOverview/CustomerOverview.cjs.js +1 -1
  88. package/dist/screens/CustomerOverview/CustomerOverview.es.js +65 -19
  89. package/dist/screens/PayInvoice/PayInvoice.cjs.js +1 -1
  90. package/dist/screens/PayInvoice/PayInvoice.es.js +10 -9
  91. package/dist/screens/PaymentMethodsManagement/PaymentMethodsManagement.cjs.js +1 -1
  92. package/dist/screens/PaymentMethodsManagement/PaymentMethodsManagement.es.js +8 -8
  93. package/dist/screens/SubscriptionDetails/SubscriptionDetails.ce.d.ts +3 -0
  94. package/dist/screens/SubscriptionDetails/SubscriptionDetails.cjs.js +1 -0
  95. package/dist/screens/SubscriptionDetails/SubscriptionDetails.es.js +542 -0
  96. package/dist/screens/SubscriptionManagement/SubscriptionManagement.ce.d.ts +3 -0
  97. package/dist/screens/SubscriptionManagement/SubscriptionManagement.cjs.js +1 -0
  98. package/dist/screens/SubscriptionManagement/SubscriptionManagement.es.js +725 -0
  99. package/dist/solvimon-web.css +1 -1
  100. package/dist/subscription-B4dBAY9C.mjs +89 -0
  101. package/dist/subscription-b0OPx8Du.js +1 -0
  102. package/dist/{subscriptions-BPYyv09M.mjs → subscriptions-CrNDM9qa.mjs} +6 -2
  103. package/dist/{subscriptions-CC61I6Nj.js → subscriptions-DC-mxa17.js} +1 -1
  104. package/dist/{url-1Lbg5Yni.mjs → url-BjZ1Pg0l.mjs} +1 -1
  105. package/dist/url-D8GJi5rF.js +1 -0
  106. package/dist/{useActionDispatchProvider-BHTknMoH.js → useActionDispatchProvider-bqR_FeM4.js} +1 -1
  107. package/dist/{useActionDispatchProvider-Dz8-e4gZ.mjs → useActionDispatchProvider-zB_GKeUR.mjs} +1 -1
  108. package/dist/{useCustomer-VVJi8z2w.mjs → useCustomer-VfeQ6rG2.mjs} +2 -2
  109. package/dist/{useCustomer-Z24KchWC.js → useCustomer-bO4D6e4Z.js} +1 -1
  110. package/dist/{useIncrementalLoading-CuSndpP2.js → useIncrementalLoading-BgWuwoMo.js} +1 -1
  111. package/dist/{useIncrementalLoading-DmOT2MXH.mjs → useIncrementalLoading-C59FXHzp.mjs} +1 -1
  112. package/dist/{useInvoiceData-Bl87gzIS.js → useInvoiceData-CxxkBTGY.js} +1 -1
  113. package/dist/{useInvoiceData-Di5pLPM0.mjs → useInvoiceData-Dhg-hx8C.mjs} +2 -2
  114. package/dist/useInvoicesList-BXZ9uV9i.js +1 -0
  115. package/dist/{useInvoicesList-z19cteaD.mjs → useInvoicesList-DBz7T7sM.mjs} +4 -4
  116. package/dist/{useLoadInitialData-CkpryfjF.mjs → useLoadInitialData-BhpIg7OF.mjs} +1 -1
  117. package/dist/{useLoadInitialData-CTqfiMTN.js → useLoadInitialData-BqiAFNFi.js} +1 -1
  118. package/dist/{usePaymentMethodOptions-BsCZnCQW.js → usePaymentMethodOptions-DszFvgKX.js} +1 -1
  119. package/dist/{usePaymentMethodOptions-BoGHJjng.mjs → usePaymentMethodOptions-PcMjtMSF.mjs} +2 -2
  120. package/dist/{usePaymentMethods-ocHmNoP7.mjs → usePaymentMethods-B5AbGWsn.mjs} +2 -2
  121. package/dist/{usePaymentMethods-AC-4rrR9.js → usePaymentMethods-Bb1Xbads.js} +1 -1
  122. package/dist/{usePayments-D85eB5l4.mjs → usePayments-DgoZoBZh.mjs} +3 -3
  123. package/dist/{usePayments-CgXZeWrU.js → usePayments-is5c66Z6.js} +1 -1
  124. package/dist/{usePortal-DVD7PcWI.js → usePortal-C4qWsJeq.js} +1 -1
  125. package/dist/{usePortal-B1O1zgdV.mjs → usePortal-DWLtNqBB.mjs} +1 -1
  126. package/dist/{useService-DF57xuDd.mjs → useService-BZqFkz7p.mjs} +1 -1
  127. package/dist/{useService-CHrkefKd.js → useService-DKm3QtT4.js} +1 -1
  128. package/dist/useSubscription-CEZJw6wZ.mjs +23 -0
  129. package/dist/useSubscription-DuUNc1_l.js +1 -0
  130. package/dist/useTopUpModal-DNyWrHDv.mjs +1012 -0
  131. package/dist/useTopUpModal-DeF-cfCK.js +1 -0
  132. package/dist/{vendor-ui-B8IlviSs.mjs → vendor-ui-BoGKOJ36.mjs} +8642 -7077
  133. package/dist/vendor-ui-BuRqLx74.js +1 -0
  134. package/package.json +14 -7
  135. package/dist/PaymentIntegrationForm.vue_vue_type_script_setup_true_lang-BBEM-YPz.js +0 -1
  136. package/dist/PaymentMethodForm.vue_vue_type_script_setup_true_lang-eWmC5GOT.js +0 -1
  137. package/dist/SecurePaymentsKPI.vue_vue_type_script_setup_true_lang-BVoS3ZXS.js +0 -1
  138. package/dist/SubscriptionsList.vue_vue_type_script_setup_true_lang-56vu59V4.js +0 -1
  139. package/dist/component-Bg2JVC_O.mjs +0 -933
  140. package/dist/component-Bs8oszfD.js +0 -1
  141. package/dist/en-US-C0gIE4Q1.js +0 -1
  142. package/dist/invoices-D-OKipCg.js +0 -1
  143. package/dist/nl-NL-Br7muSHK.js +0 -1
  144. package/dist/registry-uG2isab0.js +0 -1
  145. package/dist/screens/UpgradeSubscription/UpgradeSubscription.ce.d.ts +0 -3
  146. package/dist/screens/UpgradeSubscription/UpgradeSubscription.cjs.js +0 -1
  147. package/dist/screens/UpgradeSubscription/UpgradeSubscription.es.js +0 -1102
  148. package/dist/url-B6-3PkW2.js +0 -1
  149. package/dist/useInvoicesList-CFk-_oVK.js +0 -1
  150. package/dist/useWalletBalanceItems-BL-R5foK.js +0 -1
  151. package/dist/vendor-ui-C3Tq-qY_.js +0 -1
@@ -0,0 +1,1012 @@
1
+ import { ref, defineComponent, computed, watch, openBlock, createElementBlock, createElementVNode, createBlock, unref, withCtx, createTextVNode, toDisplayString, createCommentVNode, Fragment, renderList, withModifiers, createVNode, onBeforeUnmount, createSlots, normalizeStyle, normalizeClass } from "vue";
2
+ import { a0 as isFlexiblePricing, a1 as hasOneOfPricingTypes, u as useIntl, o as _sfc_main$3, e as _sfc_main$4, a2 as _sfc_main$5, a3 as _sfc_main$6, _ as _sfc_main$8, a4 as _sfc_main$9, a5 as _sfc_main$a, a6 as formatWalletBalanceValue, E as formatAmount, g as getCustomerCountry, M as Modal, c as _sfc_main$e } from "./vendor-ui-BoGKOJ36.mjs";
3
+ import { c as createInvoicesService } from "./invoices-BXDgW8ch.mjs";
4
+ import { u as useWatchDebounced } from "./useWatchDebounced-Zmxd6InB.mjs";
5
+ import { a as useLogger } from "./component-CUJ_G2Nw.mjs";
6
+ import { _ as _sfc_main$7 } from "./Skeleton.vue_vue_type_script_setup_true_lang-DGMxHc20.mjs";
7
+ import { _ as _sfc_main$b } from "./PaymentMethodSelector.vue_vue_type_script_setup_true_lang-BQIN3zuf.mjs";
8
+ import { _ as _sfc_main$c } from "./url-BjZ1Pg0l.mjs";
9
+ import { u as usePaymentMethodOptions } from "./usePaymentMethodOptions-PcMjtMSF.mjs";
10
+ import { _ as _sfc_main$d } from "./PaymentMethodForm.vue_vue_type_script_setup_true_lang-CIQ0vsko.mjs";
11
+ const TOP_UP_MODAL_STEPS = ["TOP_UP", "ADD_PAYMENT_METHOD", "SUCCESS"];
12
+ const isChargeOnDemandPricingItem = (entry) => typeof entry === "object" && entry !== null && "pricing_item" in entry;
13
+ const getTopUpPricingItems = (walletBalanceItem) => ((walletBalanceItem == null ? void 0 : walletBalanceItem.charge_on_demand_pricing_items) ?? []).flatMap((entry) => {
14
+ var _a, _b;
15
+ if (!isChargeOnDemandPricingItem(entry)) {
16
+ return [];
17
+ }
18
+ const pricingItemId = entry.pricing_item_id ?? ((_a = entry.pricing_item) == null ? void 0 : _a.id);
19
+ if (!pricingItemId) {
20
+ return [];
21
+ }
22
+ return (((_b = entry.pricing_item) == null ? void 0 : _b.configs) ?? []).map((config) => {
23
+ const flexiblePricing = getFlexiblePricing(config, walletBalanceItem);
24
+ const fixedPricing = getFixedPricing(config, walletBalanceItem);
25
+ return {
26
+ pricingItemId,
27
+ ...entry.pricing_plan_schedule_id && {
28
+ pricingPlanScheduleId: entry.pricing_plan_schedule_id
29
+ },
30
+ config,
31
+ ...flexiblePricing && { flexiblePricing },
32
+ ...fixedPricing && { fixedPricing }
33
+ };
34
+ });
35
+ });
36
+ function getFixedPricing(config, walletBalanceItem) {
37
+ var _a, _b, _c;
38
+ if (!config.on_demand || !hasOneOfPricingTypes(config, ["FIXED"])) {
39
+ return void 0;
40
+ }
41
+ const amount = (_c = (_b = (_a = config.details) == null ? void 0 : _a.bands) == null ? void 0 : _b[0]) == null ? void 0 : _c.fixed_amount;
42
+ if (!amount) {
43
+ return void 0;
44
+ }
45
+ const walletCredits = getWalletCredits(walletBalanceItem);
46
+ const grantedCredits = walletCredits ? getGrantedCredits(config, walletBalanceItem) : void 0;
47
+ return {
48
+ amount,
49
+ value: grantedCredits && walletCredits ? toCreditsValue(grantedCredits.quantity, walletCredits) : { amount }
50
+ };
51
+ }
52
+ const getWalletCredits = (walletBalanceItem) => {
53
+ var _a;
54
+ return (_a = walletBalanceItem == null ? void 0 : walletBalanceItem.wallet_balance.balance) == null ? void 0 : _a.credits;
55
+ };
56
+ const getWalletGrants = (config, walletBalanceItem) => {
57
+ const walletTypeId = walletBalanceItem == null ? void 0 : walletBalanceItem.wallet_type_id;
58
+ return (config.wallet_grants ?? []).filter(
59
+ ({ wallet_type_id }) => !walletTypeId || wallet_type_id === walletTypeId
60
+ );
61
+ };
62
+ const getCreditsConversion = (config, walletBalanceItem) => {
63
+ var _a, _b;
64
+ return (_b = (_a = getWalletGrants(config, walletBalanceItem).find(({ credits_grant }) => credits_grant == null ? void 0 : credits_grant.conversion)) == null ? void 0 : _a.credits_grant) == null ? void 0 : _b.conversion;
65
+ };
66
+ const getGrantedCredits = (config, walletBalanceItem) => {
67
+ var _a, _b;
68
+ return (_b = (_a = getWalletGrants(config, walletBalanceItem).find(({ credits_grant }) => credits_grant == null ? void 0 : credits_grant.credits)) == null ? void 0 : _a.credits_grant) == null ? void 0 : _b.credits;
69
+ };
70
+ const toCreditsValue = (quantity, walletCredits) => ({ credits: { ...walletCredits, quantity } });
71
+ const toCreditsQuantity = (quantity, rate) => {
72
+ const parsedQuantity = Number(quantity);
73
+ const parsedRate = Number(rate);
74
+ return Number.isFinite(parsedQuantity) && Number.isFinite(parsedRate) ? String(parsedQuantity * parsedRate) : void 0;
75
+ };
76
+ function getFlexiblePricing(config, walletBalanceItem) {
77
+ var _a, _b, _c, _d, _e, _f, _g;
78
+ if (!config.on_demand || !isFlexiblePricing(config)) {
79
+ return void 0;
80
+ }
81
+ const band = (_b = (_a = config.details) == null ? void 0 : _a.bands) == null ? void 0 : _b[0];
82
+ const currency = ((_c = band == null ? void 0 : band.minimum_amount) == null ? void 0 : _c.currency) ?? ((_d = band == null ? void 0 : band.maximum_amount) == null ? void 0 : _d.currency) ?? ((_f = (_e = walletBalanceItem == null ? void 0 : walletBalanceItem.wallet_balance.balance) == null ? void 0 : _e.amount) == null ? void 0 : _f.currency);
83
+ if (!currency) {
84
+ return void 0;
85
+ }
86
+ const credits = getWalletCredits(walletBalanceItem);
87
+ const conversion = credits ? getCreditsConversion(config, walletBalanceItem) : void 0;
88
+ const unitName = (_g = credits == null ? void 0 : credits.credit_type) == null ? void 0 : _g.unit_name;
89
+ const toBound = (amount) => {
90
+ if (!amount) {
91
+ return void 0;
92
+ }
93
+ const quantity = credits && conversion ? toCreditsQuantity(amount.quantity, conversion.rate) : void 0;
94
+ return quantity !== void 0 && credits ? toCreditsValue(quantity, credits) : { amount };
95
+ };
96
+ return {
97
+ config: {
98
+ ...(band == null ? void 0 : band.minimum_amount) && { minimum_amount: band.minimum_amount },
99
+ ...(band == null ? void 0 : band.maximum_amount) && { maximum_amount: band.maximum_amount }
100
+ },
101
+ currency,
102
+ ...conversion && {
103
+ creditsConfiguration: {
104
+ conversionRate: conversion.rate,
105
+ ...(unitName == null ? void 0 : unitName.singular) && { unitNameSingle: unitName.singular },
106
+ ...(unitName == null ? void 0 : unitName.plural) && { unitNamePlural: unitName.plural }
107
+ }
108
+ },
109
+ bounds: {
110
+ ...toBound(band == null ? void 0 : band.minimum_amount) && { minimum: toBound(band == null ? void 0 : band.minimum_amount) },
111
+ ...toBound(band == null ? void 0 : band.maximum_amount) && { maximum: toBound(band == null ? void 0 : band.maximum_amount) }
112
+ }
113
+ };
114
+ }
115
+ const getTopUpValue = (item, amount) => {
116
+ var _a;
117
+ if (item.fixedPricing) {
118
+ return item.fixedPricing.value;
119
+ }
120
+ if (!item.flexiblePricing || !amount) {
121
+ return void 0;
122
+ }
123
+ const { bounds, creditsConfiguration } = item.flexiblePricing;
124
+ const credits = (_a = bounds.minimum ?? bounds.maximum) == null ? void 0 : _a.credits;
125
+ const quantity = creditsConfiguration ? toCreditsQuantity(amount.quantity, creditsConfiguration.conversionRate) : void 0;
126
+ return credits && quantity !== void 0 ? toCreditsValue(quantity, credits) : { amount };
127
+ };
128
+ const PREVIEW_DEBOUNCE_MS = 400;
129
+ function useTopUpInvoicePreview({
130
+ pricingPlanScheduleId,
131
+ pricingItems
132
+ }) {
133
+ const { previewChargeOnDemandPricingItems } = createInvoicesService();
134
+ const logger = useLogger();
135
+ const invoicePreview = ref();
136
+ const isPreviewPending = ref(false);
137
+ let latestRequestId = 0;
138
+ const loadPreview = async () => {
139
+ const scheduleId = pricingPlanScheduleId.value;
140
+ const requestId = ++latestRequestId;
141
+ if (!scheduleId || !pricingItems.value) {
142
+ if (pricingItems.value && !scheduleId) {
143
+ logger.warn(
144
+ "INVOICE_PREVIEW_SKIPPED",
145
+ "Skipped the top-up invoice preview: no schedule to charge it on",
146
+ { missing: ["pricingPlanScheduleId"] }
147
+ );
148
+ }
149
+ invoicePreview.value = void 0;
150
+ isPreviewPending.value = false;
151
+ return;
152
+ }
153
+ isPreviewPending.value = true;
154
+ try {
155
+ const invoice = await previewChargeOnDemandPricingItems({
156
+ pricingPlanScheduleId: scheduleId,
157
+ pricingItems: pricingItems.value
158
+ });
159
+ if (requestId === latestRequestId) {
160
+ invoicePreview.value = invoice;
161
+ }
162
+ } catch (error) {
163
+ if (requestId === latestRequestId) {
164
+ invoicePreview.value = void 0;
165
+ }
166
+ logger.error(
167
+ "INVOICE_PREVIEW_FAILED",
168
+ "Failed to load top-up invoice preview",
169
+ {},
170
+ error
171
+ );
172
+ } finally {
173
+ if (requestId === latestRequestId) {
174
+ isPreviewPending.value = false;
175
+ }
176
+ }
177
+ };
178
+ useWatchDebounced(pricingItems, () => void loadPreview(), {
179
+ debounce: PREVIEW_DEBOUNCE_MS,
180
+ deep: true
181
+ });
182
+ void loadPreview();
183
+ return { invoicePreview, isPreviewPending, loadPreview };
184
+ }
185
+ const _hoisted_1$2 = { class: "sv-top-up-form" };
186
+ const _hoisted_2$2 = { class: "grid grid-cols-1 gap-4" };
187
+ const _hoisted_3$1 = { class: "grid grid-cols-1 gap-1" };
188
+ const _hoisted_4$1 = { class: "sv-top-up-form__option-details" };
189
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
190
+ __name: "TopUpModalForm",
191
+ props: {
192
+ topUpPricingItems: { type: null },
193
+ paymentMethods: { type: Array }
194
+ },
195
+ emits: ["add-payment-method", "success", "failure"],
196
+ setup(__props, { expose: __expose, emit: __emit }) {
197
+ const props = __props;
198
+ const emit = __emit;
199
+ const { $t, formatNumber } = useIntl();
200
+ const model = ref({
201
+ pricing_plan_schedule_id: "",
202
+ pricing_items: [],
203
+ start_at: "",
204
+ finalize_immediately: false,
205
+ payment_method_id: void 0,
206
+ preview: true
207
+ });
208
+ const chargeableItems = computed(
209
+ () => (props.topUpPricingItems ?? []).filter((item) => item.flexiblePricing || item.fixedPricing)
210
+ );
211
+ const findItem = (pricingItemId) => chargeableItems.value.find((item) => item.pricingItemId === pricingItemId);
212
+ const pricingPlanScheduleId = computed(
213
+ () => {
214
+ var _a, _b;
215
+ return (_b = (_a = props.topUpPricingItems) == null ? void 0 : _a.find((item) => item.pricingPlanScheduleId)) == null ? void 0 : _b.pricingPlanScheduleId;
216
+ }
217
+ );
218
+ watch(
219
+ pricingPlanScheduleId,
220
+ (scheduleId) => {
221
+ model.value.pricing_plan_schedule_id = scheduleId ?? "";
222
+ },
223
+ { immediate: true }
224
+ );
225
+ const getInitialAmount = (item) => {
226
+ const { config, currency } = item.flexiblePricing ?? {};
227
+ const minimum = config == null ? void 0 : config.minimum_amount;
228
+ return minimum && currency ? { quantity: minimum.quantity, currency } : void 0;
229
+ };
230
+ const selectedPricingItemId = computed({
231
+ get: () => {
232
+ var _a;
233
+ return (_a = model.value.pricing_items[0]) == null ? void 0 : _a.pricing_item_id;
234
+ },
235
+ set: (value) => {
236
+ const item = findItem(typeof value === "string" ? value : void 0);
237
+ if (!item) {
238
+ model.value.pricing_items = [];
239
+ return;
240
+ }
241
+ const initialAmount = getInitialAmount(item);
242
+ model.value.pricing_items = [
243
+ {
244
+ pricing_item_id: item.pricingItemId,
245
+ ...initialAmount && { flexible_amount: initialAmount }
246
+ }
247
+ ];
248
+ }
249
+ });
250
+ watch(
251
+ chargeableItems,
252
+ (items) => {
253
+ var _a;
254
+ const chosenIsStillOffered = items.some(
255
+ ({ pricingItemId }) => {
256
+ var _a2;
257
+ return pricingItemId === ((_a2 = model.value.pricing_items[0]) == null ? void 0 : _a2.pricing_item_id);
258
+ }
259
+ );
260
+ if (chosenIsStillOffered) {
261
+ return;
262
+ }
263
+ selectedPricingItemId.value = (_a = items.find(
264
+ ({ flexiblePricing }) => flexiblePricing
265
+ )) == null ? void 0 : _a.pricingItemId;
266
+ },
267
+ { immediate: true }
268
+ );
269
+ const flexibleAmount = computed({
270
+ get: () => {
271
+ var _a;
272
+ return (_a = model.value.pricing_items[0]) == null ? void 0 : _a.flexible_amount;
273
+ },
274
+ set: (amount) => {
275
+ var _a;
276
+ const pricingItemId = (_a = model.value.pricing_items[0]) == null ? void 0 : _a.pricing_item_id;
277
+ if (!pricingItemId) {
278
+ return;
279
+ }
280
+ model.value.pricing_items = [
281
+ { pricing_item_id: pricingItemId, ...amount && { flexible_amount: amount } }
282
+ ];
283
+ }
284
+ });
285
+ const formatValue = (value) => formatWalletBalanceValue($t, formatNumber, value);
286
+ const getCostLabel = (optionValue) => {
287
+ var _a;
288
+ const fixedPricing = (_a = findItem(String(optionValue))) == null ? void 0 : _a.fixedPricing;
289
+ return (fixedPricing == null ? void 0 : fixedPricing.value.credits) ? formatAmount(fixedPricing.amount) : void 0;
290
+ };
291
+ const flexiblePricingFor = (optionValue) => {
292
+ var _a;
293
+ const flexiblePricing = (_a = findItem(String(optionValue))) == null ? void 0 : _a.flexiblePricing;
294
+ return flexiblePricing ? [flexiblePricing] : [];
295
+ };
296
+ const isFlexibleOption = (optionValue) => {
297
+ var _a;
298
+ return !!((_a = findItem(String(optionValue))) == null ? void 0 : _a.flexiblePricing);
299
+ };
300
+ const options = computed(
301
+ () => chargeableItems.value.map((item) => {
302
+ var _a;
303
+ return {
304
+ value: item.pricingItemId,
305
+ label: item.fixedPricing ? formatValue(item.fixedPricing.value) : $t({
306
+ defaultMessage: "Choose your own amount",
307
+ description: "Label of the choose-your-amount option in the top-up modal",
308
+ id: "topup_modal.flexible_option.label"
309
+ }),
310
+ ...((_a = item.flexiblePricing) == null ? void 0 : _a.bounds.minimum) && item.flexiblePricing.bounds.maximum && {
311
+ description: $t(
312
+ {
313
+ defaultMessage: "Between {minimum} and {maximum}",
314
+ description: "Bounds of the choose-your-amount option in the top-up modal",
315
+ id: "topup_modal.flexible_option.bounds"
316
+ },
317
+ {
318
+ minimum: formatValue(item.flexiblePricing.bounds.minimum),
319
+ maximum: formatValue(item.flexiblePricing.bounds.maximum)
320
+ }
321
+ )
322
+ }
323
+ };
324
+ })
325
+ );
326
+ const pricingItems = computed(() => {
327
+ const chargeable = model.value.pricing_items.filter(
328
+ (item) => {
329
+ var _a;
330
+ return !((_a = findItem(item.pricing_item_id)) == null ? void 0 : _a.flexiblePricing) || !!item.flexible_amount;
331
+ }
332
+ );
333
+ return chargeable.length > 0 ? chargeable : void 0;
334
+ });
335
+ const { invoicePreview } = useTopUpInvoicePreview({ pricingPlanScheduleId, pricingItems });
336
+ const { chargeOnDemandPricingItems } = createInvoicesService();
337
+ const logger = useLogger();
338
+ const isCharging = ref(false);
339
+ const canSubmit = computed(() => !!model.value.pricing_plan_schedule_id && !!pricingItems.value);
340
+ const chargedValue = computed(() => {
341
+ const [chargedItem] = model.value.pricing_items;
342
+ const item = findItem(chargedItem == null ? void 0 : chargedItem.pricing_item_id);
343
+ return item ? getTopUpValue(item, chargedItem == null ? void 0 : chargedItem.flexible_amount) : void 0;
344
+ });
345
+ async function submit() {
346
+ if (!canSubmit.value || isCharging.value) {
347
+ return;
348
+ }
349
+ isCharging.value = true;
350
+ try {
351
+ const invoice = await chargeOnDemandPricingItems({
352
+ pricing_plan_schedule_id: model.value.pricing_plan_schedule_id,
353
+ pricing_items: pricingItems.value ?? [],
354
+ payment_method_id: model.value.payment_method_id,
355
+ preview: false
356
+ });
357
+ emit("success", invoice);
358
+ } catch (error) {
359
+ logger.error("TOP_UP_FAILED", "Failed to charge the wallet top-up", {}, error);
360
+ emit("failure", error);
361
+ } finally {
362
+ isCharging.value = false;
363
+ }
364
+ }
365
+ __expose({ submit, isCharging, canSubmit, chargedValue });
366
+ const selectedPaymentMethodId = computed({
367
+ get: () => model.value.payment_method_id ?? void 0,
368
+ set: (paymentMethodId) => {
369
+ model.value.payment_method_id = paymentMethodId;
370
+ }
371
+ });
372
+ const toTime = (createdAt) => {
373
+ const parsed = Date.parse(createdAt ?? "");
374
+ return Number.isFinite(parsed) ? parsed : 0;
375
+ };
376
+ const sortedPaymentMethods = computed(
377
+ () => [...props.paymentMethods ?? []].sort((a, b) => toTime(b.created_at) - toTime(a.created_at))
378
+ );
379
+ watch(
380
+ () => props.paymentMethods,
381
+ (paymentMethods, previousPaymentMethods) => {
382
+ var _a;
383
+ const addedPaymentMethod = paymentMethods == null ? void 0 : paymentMethods.find(
384
+ ({ id }) => !(previousPaymentMethods == null ? void 0 : previousPaymentMethods.some((previous) => previous.id === id))
385
+ );
386
+ if (addedPaymentMethod && (previousPaymentMethods == null ? void 0 : previousPaymentMethods.length)) {
387
+ selectedPaymentMethodId.value = addedPaymentMethod.id;
388
+ return;
389
+ }
390
+ const chosenStillExists = paymentMethods == null ? void 0 : paymentMethods.some(
391
+ ({ id }) => id === model.value.payment_method_id
392
+ );
393
+ if (chosenStillExists) {
394
+ return;
395
+ }
396
+ selectedPaymentMethodId.value = (_a = (paymentMethods == null ? void 0 : paymentMethods.find(({ is_default }) => is_default)) ?? sortedPaymentMethods.value[0]) == null ? void 0 : _a.id;
397
+ },
398
+ { immediate: true }
399
+ );
400
+ return (_ctx, _cache) => {
401
+ return openBlock(), createElementBlock("form", _hoisted_1$2, [
402
+ createElementVNode("div", _hoisted_2$2, [
403
+ createElementVNode("div", _hoisted_3$1, [
404
+ options.value.length > 0 ? (openBlock(), createBlock(unref(_sfc_main$3), {
405
+ key: 0,
406
+ modelValue: selectedPricingItemId.value,
407
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => selectedPricingItemId.value = $event),
408
+ class: "sv-top-up-form__options",
409
+ name: "top-up-pricing-item",
410
+ direction: "column",
411
+ required: "",
412
+ disabled: isCharging.value,
413
+ options: options.value,
414
+ "show-radio": false,
415
+ label: unref($t)({
416
+ defaultMessage: "Top up amount",
417
+ description: "Label above the list of ways to top up the wallet in the top-up modal",
418
+ id: "topup_modal.pricing_items.label"
419
+ })
420
+ }, {
421
+ label: withCtx(({ option, optionValue }) => [
422
+ createElementVNode("span", null, toDisplayString(option.label), 1),
423
+ getCostLabel(optionValue) ? (openBlock(), createBlock(unref(_sfc_main$4), {
424
+ key: 0,
425
+ tag: "span",
426
+ variant: "body-sm",
427
+ shade: "lighter",
428
+ weight: "normal",
429
+ "no-spacing": "",
430
+ class: "sv-top-up-form__option-cost"
431
+ }, {
432
+ default: withCtx(() => [
433
+ createTextVNode(toDisplayString(getCostLabel(optionValue)), 1)
434
+ ]),
435
+ _: 2
436
+ }, 1024)) : createCommentVNode("", true)
437
+ ]),
438
+ description: withCtx(({ option, optionValue }) => [
439
+ createElementVNode("div", _hoisted_4$1, [
440
+ option.description && !isFlexibleOption(optionValue) ? (openBlock(), createBlock(unref(_sfc_main$4), {
441
+ key: 0,
442
+ tag: "span",
443
+ variant: "body-xs",
444
+ shade: "lighter",
445
+ "no-spacing": ""
446
+ }, {
447
+ default: withCtx(() => [
448
+ createTextVNode(toDisplayString(option.description), 1)
449
+ ]),
450
+ _: 2
451
+ }, 1024)) : createCommentVNode("", true),
452
+ flexiblePricingFor(optionValue).length > 0 ? (openBlock(), createBlock(unref(_sfc_main$5), {
453
+ key: 1,
454
+ "is-open": String(optionValue) === selectedPricingItemId.value,
455
+ lazy: ""
456
+ }, {
457
+ default: withCtx(() => [
458
+ (openBlock(true), createElementBlock(Fragment, null, renderList(flexiblePricingFor(optionValue), (flexiblePricing) => {
459
+ return openBlock(), createElementBlock("div", {
460
+ key: flexiblePricing.currency,
461
+ class: "sv-top-up-form__amount grid grid-cols-1 gap-3",
462
+ onClick: _cache[1] || (_cache[1] = withModifiers(() => {
463
+ }, ["stop"])),
464
+ onKeydown: _cache[2] || (_cache[2] = withModifiers(() => {
465
+ }, ["stop"]))
466
+ }, [
467
+ option.description ? (openBlock(), createBlock(unref(_sfc_main$4), {
468
+ key: 0,
469
+ tag: "span",
470
+ variant: "body-xs",
471
+ shade: "lighter",
472
+ "no-spacing": ""
473
+ }, {
474
+ default: withCtx(() => [
475
+ createTextVNode(toDisplayString(option.description), 1)
476
+ ]),
477
+ _: 2
478
+ }, 1024)) : createCommentVNode("", true),
479
+ createVNode(unref(_sfc_main$6), {
480
+ modelValue: flexibleAmount.value,
481
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => flexibleAmount.value = $event),
482
+ config: flexiblePricing.config,
483
+ currency: flexiblePricing.currency,
484
+ "credits-configuration": flexiblePricing.creditsConfiguration,
485
+ required: "",
486
+ disabled: isCharging.value,
487
+ "show-range-hint": false
488
+ }, null, 8, ["modelValue", "config", "currency", "credits-configuration", "disabled"])
489
+ ], 32);
490
+ }), 128))
491
+ ]),
492
+ _: 2
493
+ }, 1032, ["is-open"])) : createCommentVNode("", true)
494
+ ])
495
+ ]),
496
+ _: 1
497
+ }, 8, ["modelValue", "disabled", "options", "label"])) : createCommentVNode("", true),
498
+ pricingItems.value ? (openBlock(), createBlock(_sfc_main$7, {
499
+ key: 1,
500
+ class: "h-[152px]",
501
+ "data-testid": "top-up-invoice-preview-skeleton"
502
+ }, {
503
+ default: withCtx(() => [
504
+ unref(invoicePreview) ? (openBlock(), createBlock(unref(_sfc_main$8), {
505
+ key: 0,
506
+ "content-background": "none"
507
+ }, {
508
+ default: withCtx(() => [
509
+ createVNode(unref(_sfc_main$9), {
510
+ invoice: unref(invoicePreview),
511
+ "is-customer-facing": ""
512
+ }, null, 8, ["invoice"])
513
+ ]),
514
+ _: 1
515
+ })) : createCommentVNode("", true)
516
+ ]),
517
+ _: 1
518
+ })) : createCommentVNode("", true)
519
+ ]),
520
+ createElementVNode("div", null, [
521
+ createVNode(unref(_sfc_main$a), { spacing: "xs" })
522
+ ]),
523
+ createElementVNode("div", null, [
524
+ createVNode(_sfc_main$b, {
525
+ modelValue: selectedPaymentMethodId.value,
526
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => selectedPaymentMethodId.value = $event),
527
+ class: "sv-top-up-form__payment-methods",
528
+ "payment-methods": sortedPaymentMethods.value,
529
+ required: "",
530
+ disabled: isCharging.value,
531
+ label: unref($t)({
532
+ defaultMessage: "Payment method",
533
+ description: "Label above the payment method that pays for the top-up, in the top-up modal",
534
+ id: "topup_modal.payment_method_selector.label"
535
+ }),
536
+ onAddPaymentMethod: _cache[5] || (_cache[5] = ($event) => emit("add-payment-method"))
537
+ }, null, 8, ["modelValue", "payment-methods", "disabled", "label"])
538
+ ])
539
+ ])
540
+ ]);
541
+ };
542
+ }
543
+ });
544
+ const _hoisted_1$1 = { class: "sv-top-up-success grid grid-cols-1 gap-4" };
545
+ const _hoisted_2$1 = {
546
+ key: 0,
547
+ class: "sv-top-up-success__added"
548
+ };
549
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
550
+ __name: "TopUpModalSuccess",
551
+ props: {
552
+ addedValue: { type: Object },
553
+ invoice: { type: Object }
554
+ },
555
+ setup(__props) {
556
+ const props = __props;
557
+ const { $t, formatNumber } = useIntl();
558
+ const title = computed(
559
+ () => $t({
560
+ defaultMessage: "Top-up successful",
561
+ description: "Title of the top-up modal once the top-up has been charged",
562
+ id: "topup_modal.success.title"
563
+ })
564
+ );
565
+ const addedLabel = computed(
566
+ () => props.addedValue ? $t(
567
+ {
568
+ // Phrased around the value rather than agreeing with it: "1,000 coins was added"
569
+ // would be wrong, and the value arrives already formatted, so it cannot pluralise.
570
+ defaultMessage: "Your balance was topped up with {value}. Please be aware that it can take some time to reflect this change in your wallet.",
571
+ description: "Confirmation of what a completed top-up added to the wallet balance",
572
+ id: "topup_modal.success.added"
573
+ },
574
+ { value: formatWalletBalanceValue($t, formatNumber, props.addedValue) }
575
+ ) : void 0
576
+ );
577
+ return (_ctx, _cache) => {
578
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
579
+ createVNode(_sfc_main$c, {
580
+ status: "success",
581
+ title: title.value
582
+ }, {
583
+ default: withCtx(() => [
584
+ addedLabel.value ? (openBlock(), createElementBlock("span", _hoisted_2$1, toDisplayString(addedLabel.value), 1)) : createCommentVNode("", true)
585
+ ]),
586
+ _: 1
587
+ }, 8, ["title"]),
588
+ __props.invoice ? (openBlock(), createBlock(unref(_sfc_main$8), {
589
+ key: 0,
590
+ "content-background": "none"
591
+ }, {
592
+ default: withCtx(() => [
593
+ createVNode(unref(_sfc_main$4), {
594
+ tag: "span",
595
+ variant: "body-sm",
596
+ weight: "semibold",
597
+ class: "mb-2 block"
598
+ }, {
599
+ default: withCtx(() => [
600
+ createTextVNode(toDisplayString(unref($t)({
601
+ defaultMessage: "Receipt",
602
+ description: "Heading above the invoice a completed top-up produced",
603
+ id: "topup_modal.success.receipt.heading"
604
+ })), 1)
605
+ ]),
606
+ _: 1
607
+ }),
608
+ createVNode(unref(_sfc_main$9), {
609
+ invoice: __props.invoice,
610
+ "is-customer-facing": ""
611
+ }, null, 8, ["invoice"])
612
+ ]),
613
+ _: 1
614
+ })) : createCommentVNode("", true)
615
+ ]);
616
+ };
617
+ }
618
+ });
619
+ function useTopUpModalLabels({
620
+ step,
621
+ currentBalance,
622
+ topUpValue
623
+ }) {
624
+ const { $t, formatNumber } = useIntl();
625
+ const title = computed(() => {
626
+ if (step.value === "ADD_PAYMENT_METHOD") {
627
+ return $t({
628
+ defaultMessage: "Add payment method",
629
+ description: "Title of the top-up modal while the customer is adding a payment method",
630
+ id: "topup_modal.add_payment_method.title"
631
+ });
632
+ }
633
+ if (step.value === "SUCCESS") {
634
+ return $t({
635
+ defaultMessage: "Top-up complete",
636
+ description: "Title of the top-up modal once the top-up has been charged",
637
+ id: "topup_modal.success.modal_title"
638
+ });
639
+ }
640
+ return $t({
641
+ defaultMessage: "Top up balance",
642
+ description: "Title of the wallet top-up modal",
643
+ id: "topup_modal.title"
644
+ });
645
+ });
646
+ const subTitle = computed(() => {
647
+ if (step.value === "ADD_PAYMENT_METHOD") {
648
+ return $t({
649
+ defaultMessage: "Add a new payment method for topping up your balance.",
650
+ description: "Subtitle of the top-up modal while the customer is adding a payment method",
651
+ id: "topup_modal.add_payment_method.subtitle"
652
+ });
653
+ }
654
+ if (step.value === "SUCCESS") {
655
+ return $t({
656
+ defaultMessage: "Your payment went through.",
657
+ description: "Subtitle of the top-up modal once the top-up has been charged",
658
+ id: "topup_modal.success.modal_subtitle"
659
+ });
660
+ }
661
+ return $t(
662
+ {
663
+ defaultMessage: "Your current balance is {balance}.",
664
+ description: "Subtitle of the top-up modal showing the current wallet balance",
665
+ id: "topup_modal.subtitle"
666
+ },
667
+ { balance: currentBalance.value }
668
+ );
669
+ });
670
+ const cancelButtonText = computed(
671
+ () => step.value === "ADD_PAYMENT_METHOD" ? $t({
672
+ defaultMessage: "Back",
673
+ description: "Label of the button that leaves the add payment method step in the top-up modal",
674
+ id: "topup_modal.back_button.label"
675
+ }) : $t({
676
+ defaultMessage: "Cancel",
677
+ description: "Label of the button that closes the top-up modal",
678
+ id: "topup_modal.cancel_button.label"
679
+ })
680
+ );
681
+ const confirmButtonText = computed(() => {
682
+ if (step.value === "ADD_PAYMENT_METHOD") {
683
+ return $t({
684
+ defaultMessage: "Save payment method",
685
+ description: "Label of the confirm button in the top-up modal while adding a payment method",
686
+ id: "topup_modal.save_payment_method.label"
687
+ });
688
+ }
689
+ if (step.value === "SUCCESS") {
690
+ return $t({
691
+ defaultMessage: "Done",
692
+ description: "Label of the button that dismisses the top-up modal once the top-up has been charged",
693
+ id: "topup_modal.done_button.label"
694
+ });
695
+ }
696
+ if (!topUpValue.value) {
697
+ return $t({
698
+ defaultMessage: "Top up balance",
699
+ description: "Label of the confirm button in the top-up modal while no amount is entered",
700
+ id: "topup_modal.confirm_button.empty.label"
701
+ });
702
+ }
703
+ return $t(
704
+ {
705
+ defaultMessage: "Top up balance with {value}",
706
+ description: "Label of the confirm button in the top-up modal once an amount is entered",
707
+ id: "topup_modal.confirm_button.label"
708
+ },
709
+ { value: formatWalletBalanceValue($t, formatNumber, topUpValue.value) }
710
+ );
711
+ });
712
+ return { title, subTitle, cancelButtonText, confirmButtonText };
713
+ }
714
+ function useElementHeight(target) {
715
+ const height = ref(0);
716
+ const measure = (element) => {
717
+ height.value = (element == null ? void 0 : element.offsetHeight) ?? 0;
718
+ };
719
+ const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver((entries) => {
720
+ var _a;
721
+ const element = (_a = entries[0]) == null ? void 0 : _a.target;
722
+ measure(element instanceof HTMLElement ? element : void 0);
723
+ });
724
+ watch(
725
+ target,
726
+ (element, previousElement) => {
727
+ if (previousElement) {
728
+ observer == null ? void 0 : observer.unobserve(previousElement);
729
+ }
730
+ measure(element);
731
+ if (element) {
732
+ observer == null ? void 0 : observer.observe(element);
733
+ }
734
+ },
735
+ // `post` so the callback runs after the render that assigns the template ref, not before.
736
+ { immediate: true, flush: "post" }
737
+ );
738
+ onBeforeUnmount(() => {
739
+ observer == null ? void 0 : observer.disconnect();
740
+ });
741
+ return height;
742
+ }
743
+ const _hoisted_1 = { class: "grid grid-cols-1 gap-4 pb-4" };
744
+ const _hoisted_2 = ["inert"];
745
+ const _hoisted_3 = ["inert"];
746
+ const _hoisted_4 = ["inert"];
747
+ const _hoisted_5 = { class: "flex flex-col gap-2" };
748
+ const PANE_TRANSITION_MS = 300;
749
+ const PANE_GAP = "1rem";
750
+ const _sfc_main = /* @__PURE__ */ defineComponent({
751
+ __name: "TopUpModal",
752
+ props: {
753
+ showModal: { type: Boolean },
754
+ selectedBalanceItem: { type: Object },
755
+ paymentMethods: { type: Array },
756
+ customer: { type: Object }
757
+ },
758
+ emits: ["confirm", "close", "payment-success", "payment-failed"],
759
+ setup(__props, { emit: __emit }) {
760
+ const props = __props;
761
+ const emit = __emit;
762
+ const { $t, formatNumber } = useIntl();
763
+ const currentBalance = computed(
764
+ () => {
765
+ var _a;
766
+ return formatWalletBalanceValue(
767
+ $t,
768
+ formatNumber,
769
+ (_a = props.selectedBalanceItem) == null ? void 0 : _a.wallet_balance.open_balance
770
+ );
771
+ }
772
+ );
773
+ const topUpPricingItems = computed(() => getTopUpPricingItems(props.selectedBalanceItem));
774
+ const {
775
+ paymentMethodOptions,
776
+ get: loadPaymentMethodOptions,
777
+ isPending: isPaymentMethodOptionsPending
778
+ } = usePaymentMethodOptions();
779
+ watch(
780
+ () => [props.showModal, props.customer],
781
+ ([showModal, customer]) => {
782
+ if (!showModal || !customer) {
783
+ return;
784
+ }
785
+ void loadPaymentMethodOptions({
786
+ customerId: customer.id,
787
+ country: getCustomerCountry(customer)
788
+ });
789
+ },
790
+ { immediate: true }
791
+ );
792
+ const step = ref("TOP_UP");
793
+ const chargedInvoice = ref();
794
+ const chargedValue = ref();
795
+ const handlePaymentSuccess = () => {
796
+ step.value = "TOP_UP";
797
+ emit("payment-success");
798
+ };
799
+ const paymentMethodFormConfiguration = computed(() => ({
800
+ variant: "TOKENIZE"
801
+ }));
802
+ const hasEverShownForm = ref(false);
803
+ const isSwitchingPanes = ref(false);
804
+ let switchTimeout;
805
+ watch(step, (currentStep) => {
806
+ hasEverShownForm.value = hasEverShownForm.value || currentStep === "ADD_PAYMENT_METHOD";
807
+ isSwitchingPanes.value = true;
808
+ clearTimeout(switchTimeout);
809
+ switchTimeout = setTimeout(() => {
810
+ isSwitchingPanes.value = false;
811
+ }, PANE_TRANSITION_MS);
812
+ });
813
+ onBeforeUnmount(() => {
814
+ clearTimeout(switchTimeout);
815
+ });
816
+ const topUpPaneRef = ref();
817
+ const addPaneRef = ref();
818
+ const successPaneRef = ref();
819
+ const paneHeights = {
820
+ TOP_UP: useElementHeight(topUpPaneRef),
821
+ ADD_PAYMENT_METHOD: useElementHeight(addPaneRef),
822
+ SUCCESS: useElementHeight(successPaneRef)
823
+ };
824
+ const paneHeight = computed(() => paneHeights[step.value].value);
825
+ const trackOffset = computed(() => {
826
+ const index = TOP_UP_MODAL_STEPS.indexOf(step.value);
827
+ return index === 0 ? "translateX(0px)" : `translateX(calc(${-index} * (100% + ${PANE_GAP})))`;
828
+ });
829
+ const paymentMethodFormRef = ref();
830
+ const isSavingPaymentMethod = computed(
831
+ () => {
832
+ var _a;
833
+ return step.value === "ADD_PAYMENT_METHOD" && !!((_a = paymentMethodFormRef.value) == null ? void 0 : _a.isPaymentPending);
834
+ }
835
+ );
836
+ const topUpFormRef = ref();
837
+ const topUpValue = computed(() => {
838
+ var _a;
839
+ return (_a = topUpFormRef.value) == null ? void 0 : _a.chargedValue;
840
+ });
841
+ const isPending = computed(() => {
842
+ var _a;
843
+ return isSavingPaymentMethod.value || !!((_a = topUpFormRef.value) == null ? void 0 : _a.isCharging);
844
+ });
845
+ const { title, subTitle, cancelButtonText, confirmButtonText } = useTopUpModalLabels({
846
+ step,
847
+ currentBalance,
848
+ topUpValue
849
+ });
850
+ const handleConfirm = () => {
851
+ var _a, _b;
852
+ if (step.value === "ADD_PAYMENT_METHOD") {
853
+ (_a = paymentMethodFormRef.value) == null ? void 0 : _a.submit();
854
+ return;
855
+ }
856
+ void ((_b = topUpFormRef.value) == null ? void 0 : _b.submit());
857
+ };
858
+ const handleTopUpSuccess = (invoice) => {
859
+ var _a;
860
+ chargedInvoice.value = invoice;
861
+ chargedValue.value = (_a = topUpFormRef.value) == null ? void 0 : _a.chargedValue;
862
+ step.value = "SUCCESS";
863
+ };
864
+ const handleDone = () => {
865
+ emit("confirm");
866
+ emit("close");
867
+ };
868
+ const handleCancel = () => {
869
+ if (isPending.value) {
870
+ return;
871
+ }
872
+ if (step.value === "ADD_PAYMENT_METHOD") {
873
+ step.value = "TOP_UP";
874
+ return;
875
+ }
876
+ if (step.value === "SUCCESS") {
877
+ handleDone();
878
+ return;
879
+ }
880
+ emit("close");
881
+ };
882
+ const topUpFormKey = ref(0);
883
+ watch(
884
+ () => props.showModal,
885
+ (showModal) => {
886
+ if (!showModal) {
887
+ return;
888
+ }
889
+ step.value = "TOP_UP";
890
+ chargedInvoice.value = void 0;
891
+ chargedValue.value = void 0;
892
+ topUpFormKey.value += 1;
893
+ }
894
+ );
895
+ return (_ctx, _cache) => {
896
+ return openBlock(), createBlock(unref(Modal), {
897
+ "no-click-away": "",
898
+ "show-modal": __props.showModal,
899
+ size: "lg",
900
+ title: unref(title),
901
+ "sub-title": unref(subTitle),
902
+ "cancel-button-text": unref(cancelButtonText),
903
+ "confirm-button-text": unref(confirmButtonText),
904
+ "is-loading": isPending.value,
905
+ onConfirm: handleConfirm,
906
+ onClose: handleCancel
907
+ }, createSlots({
908
+ body: withCtx(() => [
909
+ createElementVNode("div", _hoisted_1, [
910
+ createElementVNode("div", {
911
+ class: normalizeClass([
912
+ "sv-topup-modal__viewport relative -mx-2 overflow-hidden px-2",
913
+ isSwitchingPanes.value ? "transition-[height] duration-300 ease-in-out motion-reduce:transition-none" : ""
914
+ ]),
915
+ style: normalizeStyle(paneHeight.value ? { height: `${paneHeight.value}px` } : void 0)
916
+ }, [
917
+ createElementVNode("div", {
918
+ class: "sv-topup-modal__track flex items-start gap-4 transition-transform duration-300 ease-in-out motion-reduce:transition-none",
919
+ style: normalizeStyle({ transform: trackOffset.value })
920
+ }, [
921
+ createElementVNode("div", {
922
+ class: "sv-topup-modal__pane w-full shrink-0",
923
+ inert: step.value !== "TOP_UP" || void 0
924
+ }, [
925
+ createElementVNode("div", {
926
+ ref_key: "topUpPaneRef",
927
+ ref: topUpPaneRef
928
+ }, [
929
+ (openBlock(), createBlock(_sfc_main$2, {
930
+ key: topUpFormKey.value,
931
+ ref_key: "topUpFormRef",
932
+ ref: topUpFormRef,
933
+ "top-up-pricing-items": topUpPricingItems.value,
934
+ "payment-methods": __props.paymentMethods,
935
+ onAddPaymentMethod: _cache[0] || (_cache[0] = ($event) => step.value = "ADD_PAYMENT_METHOD"),
936
+ onSuccess: handleTopUpSuccess
937
+ }, null, 8, ["top-up-pricing-items", "payment-methods"]))
938
+ ], 512)
939
+ ], 8, _hoisted_2),
940
+ createElementVNode("div", {
941
+ class: "sv-topup-modal__pane w-full shrink-0",
942
+ inert: step.value !== "ADD_PAYMENT_METHOD" || void 0
943
+ }, [
944
+ createElementVNode("div", {
945
+ ref_key: "addPaneRef",
946
+ ref: addPaneRef
947
+ }, [
948
+ __props.customer && hasEverShownForm.value ? (openBlock(), createBlock(_sfc_main$d, {
949
+ key: 0,
950
+ ref_key: "paymentMethodFormRef",
951
+ ref: paymentMethodFormRef,
952
+ "hide-submit-button": "",
953
+ customer: __props.customer,
954
+ "payment-method-options": unref(paymentMethodOptions),
955
+ "is-loading": unref(isPaymentMethodOptionsPending),
956
+ configuration: paymentMethodFormConfiguration.value,
957
+ onSuccess: handlePaymentSuccess,
958
+ onFailure: _cache[1] || (_cache[1] = (error) => _ctx.$emit("payment-failed", error))
959
+ }, null, 8, ["customer", "payment-method-options", "is-loading", "configuration"])) : createCommentVNode("", true)
960
+ ], 512)
961
+ ], 8, _hoisted_3),
962
+ createElementVNode("div", {
963
+ class: "sv-topup-modal__pane w-full shrink-0",
964
+ inert: step.value !== "SUCCESS" || void 0
965
+ }, [
966
+ createElementVNode("div", {
967
+ ref_key: "successPaneRef",
968
+ ref: successPaneRef
969
+ }, [
970
+ chargedInvoice.value ? (openBlock(), createBlock(_sfc_main$1, {
971
+ key: 0,
972
+ "added-value": chargedValue.value,
973
+ invoice: chargedInvoice.value
974
+ }, null, 8, ["added-value", "invoice"])) : createCommentVNode("", true)
975
+ ], 512)
976
+ ], 8, _hoisted_4)
977
+ ], 4)
978
+ ], 6)
979
+ ])
980
+ ]),
981
+ _: 2
982
+ }, [
983
+ step.value === "SUCCESS" ? {
984
+ name: "footer",
985
+ fn: withCtx(() => [
986
+ createElementVNode("div", _hoisted_5, [
987
+ createVNode(unref(_sfc_main$e), {
988
+ size: "lg",
989
+ "data-testid": "done",
990
+ onClick: handleDone
991
+ }, {
992
+ default: withCtx(() => [
993
+ createTextVNode(toDisplayString(unref(confirmButtonText)), 1)
994
+ ]),
995
+ _: 1
996
+ })
997
+ ])
998
+ ]),
999
+ key: "0"
1000
+ } : void 0
1001
+ ]), 1032, ["show-modal", "title", "sub-title", "cancel-button-text", "confirm-button-text", "is-loading"]);
1002
+ };
1003
+ }
1004
+ });
1005
+ function useTopUpModal(selectedBalance) {
1006
+ const showModal = computed(() => !!selectedBalance.value);
1007
+ return { showModal };
1008
+ }
1009
+ export {
1010
+ _sfc_main as _,
1011
+ useTopUpModal as u
1012
+ };