@arcblock/payment-service 1.29.8 → 1.29.10

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 (184) hide show
  1. package/dist/cf.d.ts +31 -0
  2. package/dist/cf.js +79 -60
  3. package/dist/index.js +358 -87
  4. package/package.json +4 -4
  5. package/web/assets/{account-DETfFe4_.js → account-DrsnH5wP.js} +1 -1
  6. package/web/assets/{action-B_DQJlip.js → action-C2c0yWuW.js} +1 -1
  7. package/web/assets/{actions-Bt_jST94.js → actions--FNKSNIs.js} +1 -1
  8. package/web/assets/{actions-jxGAdGfb.js → actions-BEUwbsq1.js} +1 -1
  9. package/web/assets/{actions-D9MHLBFH.js → actions-C9AfME83.js} +1 -1
  10. package/web/assets/{actions-QPa-8lfB.js → actions-D2-s31n3.js} +1 -1
  11. package/web/assets/{actions-DJyfN5OU.js → actions-DXMceTgd.js} +1 -1
  12. package/web/assets/{actions-BtaoyTWt.js → actions-DeCPtfTK.js} +1 -1
  13. package/web/assets/{actions-BaDh4xWX.js → actions-DtNZGZWf.js} +1 -1
  14. package/web/assets/{actions-EPYeS5p4.js → actions-JHsqbHpB.js} +1 -1
  15. package/web/assets/{actions-BknL4OyZ.js → actions-izdZ2Mn4.js} +1 -1
  16. package/web/assets/{add-price-CD-utowo.js → add-price-TdXAR3NW.js} +1 -1
  17. package/web/assets/{admin-_nEB-lHn.js → admin-BpFv3eF5.js} +1 -1
  18. package/web/assets/{assign-CkV5Q2LP.js → assign-DKRfmN7W.js} +1 -1
  19. package/web/assets/{attempts-DySeqBYU.js → attempts-BfbYfiJa.js} +1 -1
  20. package/web/assets/browser-DF2vfpBa.js +1 -0
  21. package/web/assets/{change-payment-CPUCUEER.js → change-payment-j5UC8_h0.js} +1 -1
  22. package/web/assets/{change-plan-CxE-XfWc.js → change-plan-CtXvsIDw.js} +1 -1
  23. package/web/assets/{click-boundary-y8dVA_tr.js → click-boundary-Bi28Y0Fq.js} +1 -1
  24. package/web/assets/{connect-CC_l_f6Q.js → connect-CXek4LAE.js} +1 -1
  25. package/web/assets/{copyable-DpX04wZz.js → copyable-CprMHdhV.js} +1 -1
  26. package/web/assets/{create-Bs65p5Ne.js → create-B-Ubepl_.js} +1 -1
  27. package/web/assets/{create-tYebjhr9.js → create-BVt_sQ_7.js} +1 -1
  28. package/web/assets/{create-3SsWCAOC.js → create-BWviSWbC.js} +1 -1
  29. package/web/assets/{create-BkQAaSvD.js → create-C6jihslA.js} +1 -1
  30. package/web/assets/{create-BmcRybZ5.js → create-IaalYGmm.js} +1 -1
  31. package/web/assets/{create-kG09X9gl.js → create-jzl1m8ZK.js} +1 -1
  32. package/web/assets/{credit-grant-item-list-Bk27jIc7.js → credit-grant-item-list-DQcvdSRs.js} +1 -1
  33. package/web/assets/{credit-overview-DmMSEs14.js → credit-overview-CPId2vzk.js} +2 -2
  34. package/web/assets/{currency-restrictions-DYLv4YyW.js → currency-restrictions-Dsupz2ce.js} +1 -1
  35. package/web/assets/{currency-select-DGS-62-L.js → currency-select-C8j7QQMP.js} +1 -1
  36. package/web/assets/{dayjs-B9tvQIKg.js → dayjs-DUNWtvju.js} +1 -1
  37. package/web/assets/{description-Ym17DL48.js → description-BHxdy5I3.js} +1 -1
  38. package/web/assets/{detail-DPCTQLOx.js → detail-B17BN6kU.js} +1 -1
  39. package/web/assets/detail-BJ-hl5PK.js +10 -0
  40. package/web/assets/detail-BJEqTXDS.js +1 -0
  41. package/web/assets/{detail-DG4l2CqN.js → detail-BdC9VIc6.js} +1 -1
  42. package/web/assets/detail-BkRkrKyw.js +1 -0
  43. package/web/assets/{detail-DuWdZIyp.js → detail-BvcI9cB_.js} +1 -1
  44. package/web/assets/detail-C--ATvwm.js +24 -0
  45. package/web/assets/{detail-Cb9HBSMw.js → detail-CHJqYZ0W.js} +1 -1
  46. package/web/assets/detail-CfvKZ7IV.js +1 -0
  47. package/web/assets/{detail-K9EVY3r2.js → detail-CmIweOLE.js} +1 -1
  48. package/web/assets/{detail-CxYQYu_l.js → detail-D729Bgs6.js} +1 -1
  49. package/web/assets/detail-DD1YBtex.js +1 -0
  50. package/web/assets/detail-DOcm4Kqg.js +15 -0
  51. package/web/assets/{detail-Do9QO5L2.js → detail-DQj1mbhA.js} +1 -1
  52. package/web/assets/detail-DTXDMIR9.js +15 -0
  53. package/web/assets/{detail-DB56SG-k.js → detail-DUAJzKsu.js} +1 -1
  54. package/web/assets/detail-De8PyTyx.js +1 -0
  55. package/web/assets/{detail-CT9Unyrf.js → detail-DqfxOHky.js} +1 -1
  56. package/web/assets/{detail-cwHZbY62.js → detail-Dzt5tfyZ.js} +1 -1
  57. package/web/assets/{detail-D5KRrQDx.js → detail-H0dkKVyS.js} +1 -1
  58. package/web/assets/{detail-DuO_Jn5X.js → detail-MgdgGj5J.js} +1 -1
  59. package/web/assets/{detail-BJTcK7mx.js → detail-WAmPM6yq.js} +1 -1
  60. package/web/assets/{detail-Cr2wG4Th.js → detail-g6el9Fxj.js} +1 -1
  61. package/web/assets/did-Bqcz-NjH.js +1 -0
  62. package/web/assets/{drawer-form-Cl0T1Yyt.js → drawer-form-CQjNFFWk.js} +1 -1
  63. package/web/assets/{edit-3HUAnaXW.js → edit-DAU8AWzT.js} +1 -1
  64. package/web/assets/{editor-BF5I0siU.js → editor-vZvxDUTl.js} +1 -1
  65. package/web/assets/{embed-CsNqeCd0.js → embed-ClYNqZbf.js} +1 -1
  66. package/web/assets/{filter-toolbar-BydfQ-79.js → filter-toolbar-VvmMATj0.js} +1 -1
  67. package/web/assets/form-4_MzglPj.js +9 -0
  68. package/web/assets/{form-P4luyUpY.js → form-AFzUvoFE.js} +1 -1
  69. package/web/assets/{form-DSzMo9UD.js → form-Bro99BjK.js} +1 -1
  70. package/web/assets/{form-BGm5NPDn.js → form-CnrBCyTJ.js} +1 -1
  71. package/web/assets/form-Cuvruf4H.js +16 -0
  72. package/web/assets/{gas-Qf0SSUfS.js → gas-kw2KMH1u.js} +1 -1
  73. package/web/assets/{generateCategoricalChart-BaWwaXky.js → generateCategoricalChart-BCpuUeC_.js} +1 -1
  74. package/web/assets/{home-HbrLyxJL.js → home-ZNJREzbw.js} +1 -1
  75. package/web/assets/{index-BIoSdRvX.js → index-ASk8vU2H.js} +3 -3
  76. package/web/assets/{index-B1pTTyGZ.js → index-B4n6PvPu.js} +1 -1
  77. package/web/assets/{index-DgSc1Qy8.js → index-B4yaPb7B.js} +17 -17
  78. package/web/assets/{index-CI_EY4YS.js → index-BHwID_s4.js} +1 -1
  79. package/web/assets/index-BMcnd_jZ.js +1 -0
  80. package/web/assets/{index-9xBRL_33.js → index-BRmN8ViQ.js} +1 -1
  81. package/web/assets/index-BdbLl6St.js +1 -0
  82. package/web/assets/{index-Cw0ugaQL.js → index-BjKRyxNQ.js} +1 -1
  83. package/web/assets/index-BjLJQRKY.js +1 -0
  84. package/web/assets/index-BkNCPnTn.js +1 -0
  85. package/web/assets/index-BlAwTTmu.js +1 -0
  86. package/web/assets/{index-C0JaS08f.js → index-BtWfmATr.js} +1 -1
  87. package/web/assets/{index-DE2KzqXl.js → index-C-5n472s.js} +1 -1
  88. package/web/assets/{index-Br7_mvEw.js → index-C3AP4jq0.js} +1 -1
  89. package/web/assets/{index-2l22EYw9.js → index-C3Rh1SaB.js} +1 -1
  90. package/web/assets/index-CDyxbCzc.js +1 -0
  91. package/web/assets/{index-Dc954mDP.js → index-CH_k9MVv.js} +1 -1
  92. package/web/assets/{index-1y9kjPIr.js → index-CKPfOW6M.js} +1 -1
  93. package/web/assets/{index-Dr_MwbKt.js → index-CPFlZhA2.js} +1 -1
  94. package/web/assets/index-CPyGjEd3.js +49 -0
  95. package/web/assets/index-ChC-jsE2.js +1 -0
  96. package/web/assets/index-CiWvs3j9.js +1 -0
  97. package/web/assets/{index-BP53rZV9.js → index-D6gv9jHh.js} +1 -1
  98. package/web/assets/{index-CdkYrABk.js → index-D7pWd60Z.js} +1 -1
  99. package/web/assets/{index-fswPX_qe.js → index-DAen2-cr.js} +1 -1
  100. package/web/assets/{index-DPodCQ9c.js → index-DNobX-Tr.js} +1 -1
  101. package/web/assets/{index-Drav4oDH.js → index-DY-g0BPU.js} +2 -2
  102. package/web/assets/index-DZkpxY-C.js +1 -0
  103. package/web/assets/{index-BFML4-2u.js → index-Dh9agU9O.js} +1 -1
  104. package/web/assets/index-Dju8k6mq.js +1 -0
  105. package/web/assets/{index-fByZjxLy.js → index-DwDNPqjF.js} +1 -1
  106. package/web/assets/index-Dze0CpfQ.js +14 -0
  107. package/web/assets/{index-BMKZToMM.js → index-eDERHpkr.js} +2 -2
  108. package/web/assets/{index-SYTpMMMH.js → index-mgPU1lyd.js} +1 -1
  109. package/web/assets/{index-DZpJPE1Z.js → index-olGOY5KB.js} +1 -1
  110. package/web/assets/{index-Clbt8nRm.js → index-oy7LrXGT.js} +1 -1
  111. package/web/assets/index-x7sBb6oM.js +1 -0
  112. package/web/assets/{index.es-BWnfUzLb.js → index.es-C2Q6Owow.js} +1 -1
  113. package/web/assets/{info-card-C1yxhxJG.js → info-card-C9dRgztS.js} +1 -1
  114. package/web/assets/{info-metric-CNse3r66.js → info-metric-ukWq8INi.js} +1 -1
  115. package/web/assets/{info-row-DOK2whMn.js → info-row-CaPaNF4L.js} +1 -1
  116. package/web/assets/{info-row-group-BeUhWnnY.js → info-row-group-Cxo-4Gk5.js} +1 -1
  117. package/web/assets/{libphonenumber-CyphiuxQ.js → libphonenumber-CTvobi0D.js} +1 -1
  118. package/web/assets/{link-3eeclTeS.js → link-DsltSF2Q.js} +1 -1
  119. package/web/assets/{list-C521zE_7.js → list-B2b-s8wM.js} +1 -1
  120. package/web/assets/{list-CO0X4L3-.js → list-BzgF4i3i.js} +1 -1
  121. package/web/assets/{list-DnePqZ2K.js → list-Cd1O-aDi.js} +1 -1
  122. package/web/assets/{list-D1aevUOI.js → list-CvM46TsP.js} +2 -2
  123. package/web/assets/{list-jHj_5yy3.js → list-DtEjqlED.js} +1 -1
  124. package/web/assets/{list-D-I0msRW.js → list-O_uCSLFq.js} +2 -2
  125. package/web/assets/{list-1OG83xc4.js → list-YNWVqjwW.js} +1 -1
  126. package/web/assets/{list-CNmzJKIQ.js → list-ZaBapEXW.js} +1 -1
  127. package/web/assets/metadata-_hV0ZaVh.js +55 -0
  128. package/web/assets/{meter-event-lmNMgmIu.js → meter-event-CPVBpekF.js} +1 -1
  129. package/web/assets/{metrics-C7U41HWk.js → metrics-DVPdwpyf.js} +1 -1
  130. package/web/assets/{overview-Cs3-8n4e.js → overview-CGdVIJrJ.js} +1 -1
  131. package/web/assets/{overview-CH1HnSP-.js → overview-CN59I5Sc.js} +1 -1
  132. package/web/assets/{past-due-CGGRZmXY.js → past-due-C3PtU8uo.js} +1 -1
  133. package/web/assets/pay-XVdSNq__.js +4 -0
  134. package/web/assets/{payment-method-info-BsOBbA3m.js → payment-method-info-D_qR04xC.js} +2 -2
  135. package/web/assets/{preview-CjYh9dTg.js → preview-Bdtbh-xk.js} +1 -1
  136. package/web/assets/{preview-DjYRpRA8.js → preview-F3lma170.js} +1 -1
  137. package/web/assets/{pricing-table-edE6TJGX.js → pricing-table-Bt2WljzE.js} +1 -1
  138. package/web/assets/{pricing-table-C3Lkhq46.js → pricing-table-D9FGYBVa.js} +2 -2
  139. package/web/assets/{product-select-0ScZE2e8.js → product-select-_72p-5lF.js} +1 -1
  140. package/web/assets/{recharge-DcPtT8vt.js → recharge-CSlKshbU.js} +1 -1
  141. package/web/assets/{related-credit-grants-BygNGPfb.js → related-credit-grants-DnKdAit6.js} +22 -22
  142. package/web/assets/{safe-did-address-B0fFbUph.js → safe-did-address-CRTPYo34.js} +1 -1
  143. package/web/assets/{source-data-viewer-By_Utay-.js → source-data-viewer-D1GShrs5.js} +1 -1
  144. package/web/assets/{status-l6pD08fw.js → status-3Swm2gK5.js} +1 -1
  145. package/web/assets/subscription-BX00k6FU.js +1 -0
  146. package/web/assets/{subscription-Dq22e3D1.js → subscription-Bzeblscr.js} +1 -1
  147. package/web/assets/table-BN3WBnr3.js +1 -0
  148. package/web/assets/{tax-code-select-CWhIIiXi.js → tax-code-select-j2arPbaE.js} +1 -1
  149. package/web/assets/{tax-utils-DqNX34-r.js → tax-utils-B8J0Kfnz.js} +1 -1
  150. package/web/assets/{uploader-DRXDz_r0.js → uploader-BLdAbLR6.js} +1 -1
  151. package/web/assets/{usage-records-jjJMZ6DI.js → usage-records-BAwNs1y8.js} +1 -1
  152. package/web/assets/{util-mDHAL0lx.js → util-B8B3fsMa.js} +1 -1
  153. package/web/assets/{vendor-arcblock-ChFCRdyx.js → vendor-arcblock-D1drrE7q.js} +1 -1
  154. package/web/assets/{vendor-blocklet-D_i_QeSo.js → vendor-blocklet-B67R14so.js} +43 -43
  155. package/web/index.html +1 -1
  156. package/web/assets/browser-DSLTxXlL.js +0 -1
  157. package/web/assets/detail-15zxCbV9.js +0 -10
  158. package/web/assets/detail-ASPdMJoW.js +0 -1
  159. package/web/assets/detail-CIx9vkir.js +0 -1
  160. package/web/assets/detail-D5NbV29V.js +0 -1
  161. package/web/assets/detail-DE3OOC5M.js +0 -15
  162. package/web/assets/detail-DVVzYhdV.js +0 -1
  163. package/web/assets/detail-Dqc0OfCQ.js +0 -1
  164. package/web/assets/detail-OZeeKI69.js +0 -24
  165. package/web/assets/detail-uhlID8jD.js +0 -15
  166. package/web/assets/form-BXAuSawq.js +0 -9
  167. package/web/assets/form-CKfKLGXP.js +0 -16
  168. package/web/assets/index-0HK7CYm4.js +0 -1
  169. package/web/assets/index-BJ_E6bEO.js +0 -1
  170. package/web/assets/index-Bnyh4rlV.js +0 -1
  171. package/web/assets/index-BoQ7wf3O.js +0 -1
  172. package/web/assets/index-C68x-aau.js +0 -1
  173. package/web/assets/index-C8s2QKoe.js +0 -1
  174. package/web/assets/index-Cn7O-OP7.js +0 -49
  175. package/web/assets/index-DU39aG5u.js +0 -1
  176. package/web/assets/index-DtbqgSK4.js +0 -1
  177. package/web/assets/index-DuRu9NWB.js +0 -14
  178. package/web/assets/index-WMKOiUez.js +0 -1
  179. package/web/assets/index-dmHgoplS.js +0 -1
  180. package/web/assets/index-txVTkoDD.js +0 -1
  181. package/web/assets/metadata-CMSHcSXi.js +0 -55
  182. package/web/assets/pay-CSpHBUh_.js +0 -4
  183. package/web/assets/subscription-DcwhSOpa.js +0 -1
  184. package/web/assets/table-BRU4Enia.js +0 -1
@@ -1,5 +1,5 @@
1
- import{r as m,j as e,bg as ce,a3 as u,q as f,a2 as le,B as P,A as Se,aX as Te,aZ as ee,aT as Ae,ad as Re,N as Pe,x as G,w as de,b_ as Ie,bU as qe,bL as ke,bH as ue,aN as ze,aM as X,b$ as Me,c0 as $e}from"./vendor-mui-BXZut9Pz.js";import{V as Q,X as Ne,O as H,$ as Fe,Y as q,a6 as Le,E as me,ap as te,F as ne}from"./vendor-blocklet-D_i_QeSo.js";import{f as ae,aR as Ee,aS as Be,aT as We,ay as De,a8 as Oe,aU as Ue,M as Ge,aV as re,a as Ve,W as He,h as Qe,F as Xe,S as Ze,aW as se,C as ie,a3 as pe,aX as oe,a0 as Je,e as N,k as U,i as he,a1 as Ye,l as xe,aY as Ke,aZ as et,a_ as tt,A as nt}from"./index-DgSc1Qy8.js";import{a as at,b as rt}from"./vendor-react-BPknnnEA.js";import{I as st}from"./collapse-CSrlJ0eG.js";function it({product:t,price:r,currency:i,quantity:c,onQuantityChange:o,maxQuantity:b=99,minQuantity:s=1,creditCurrency:j,exchangeRate:d=null,isDynamicPricing:A=!1,exchangeRateData:v=null,slippageConfig:w=null,slippagePercent:k=.5,onSlippageChange:z=void 0,disabled:R=!1}){const{t:S,locale:I}=Q(),[p,x]=m.useState(c),a=Number(p)||0,{paymentAmount:l,usdReferenceDisplay:y}=m.useMemo(()=>{if(!A||!d||!r?.base_amount)return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const T=Number(r.base_amount)*a,C=Number(d);if(C<=0||!Number.isFinite(T))return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const D=T/C,M=Ee(D,!0,6),$=Be(T.toString(),I);return{paymentAmount:`${M} ${i.symbol}`,usdReferenceDisplay:$?`≈ $${$}`:null}},[A,d,r,i,t?.unit_label,p,a,I]),_=T=>{if(!T){x(void 0);return}T>=s&&T<=b&&(x(T),o(T))},F=T=>{const C=parseInt(T.target.value||"0",10);Number.isNaN(C)||_(C)},L=Number(r.metadata?.credit_config?.credit_amount||0);return e.jsxs(ce,{variant:"outlined",sx:{p:2},children:[e.jsxs(u,{direction:"row",spacing:2,sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(u,{direction:"row",spacing:2,sx:{alignItems:"center",flex:1},children:e.jsx(We,{name:t?.name||"",description:S("payment.autoTopup.creditsIncluded",{num:De(Oe(L*a),j?.symbol||"",I)}),logo:t?.images?.[0],size:40})}),e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center",alignSelf:{xs:"flex-end",sm:"center"}},children:[e.jsxs(f,{variant:"body2",sx:{color:"text.secondary",minWidth:"fit-content"},children:[S("common.quantity"),":"]}),e.jsx(le,{size:"small",value:p,onChange:F,type:"number",sx:{"& .MuiInputBase-root":{height:32}},slotProps:{htmlInput:{min:0,max:b,style:{textAlign:"center",padding:"4px 8px"}}}})]})]}),e.jsxs(u,{direction:"row",sx:{justifyContent:"space-between",alignItems:"flex-start",mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:S("payment.autoTopup.rechargeAmount")}),e.jsxs(u,{sx:{alignItems:"flex-end"},children:[e.jsx(f,{variant:"h6",sx:{fontWeight:600,color:"text.primary"},children:l}),y&&e.jsx(f,{sx:{fontSize:"0.7875rem",color:"text.lighter"},children:y}),A&&v?.rate&&e.jsx(Ue,{rateLine:S("payment.checkout.quote.rateLine",{symbol:i.symbol,rate:`$${re(v.rate)||v.rate}`}),rows:[{label:S("payment.checkout.quote.detailProvider"),value:v?.provider_display||v?.provider_name||"—"},{label:S("payment.checkout.quote.detailUpdatedAt"),value:v?.timestamp_ms?Ge(v.timestamp_ms,I):"—"},{label:S("payment.checkout.quote.detailSlippage"),value:w?.mode==="rate"&&w.min_acceptable_rate?`$${re(w.min_acceptable_rate)||w.min_acceptable_rate}`:`${w?.percent??k}%`,isSlippage:!0}],isSubscription:!0,slippageValue:w?.percent??k,slippageConfig:w||void 0,onSlippageChange:z,exchangeRate:v?.rate,baseCurrency:"USD",disabled:R})]})]})]})}const ot=async(t,r)=>{const{data:i}=await N.get(`/api/auto-recharge-configs/customer/${t}`,{params:{currency_id:r}});return i},ct=async(t,r)=>{const{data:i}=await N.get("/api/customers/payer-token",{params:{currencyId:t,payerAddress:r}});return i},B={enabled:!1,threshold:"100",quantity:1,payment_method_id:"",recharge_currency_id:"",price_id:"",daily_max_amount:0,daily_max_attempts:0},lt=async t=>{const{data:r}=await N.post("/api/exchange-rates/validate",{currency:t});return r},dt=async t=>{let r;return await Ye(async()=>{const{data:i}=await N.get(`/api/auto-recharge-configs/retrieve/${t}`);return r=i,!!r.payment_settings?.payment_method_options?.[r.paymentMethod.type]?.payer},{interval:2e3,timeout:180*1e3}),r};function ut({config:t,onChangePaymentMethod:r,paymentMethod:i,currency:c}){const{t:o}=Q(),[b,s]=m.useState(!1),j=at(),d=t?.payment_settings?.payment_method_options?.[i.type||""],{data:A,loading:v}=H(async()=>i.type==="stripe"?null:await ct(c.id,d?.payer),{refreshDeps:[c.id,d?.payer],ready:!!c.id&&!!d?.payer}),w=()=>{const R=!b;s(R),r(R)};if(!d)return null;const k=R=>{const S=me(xe(),`/customer/recharge/${c.id}?rechargeAddress=${d?.payer}`),I=Ke(S,!0);et(R,I,j)},z=()=>i.type==="stripe"?e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(qe,{fontSize:"small",color:"primary"}),e.jsxs(f,{variant:"body2",children:["**** **** **** ",d?.card_last4||"****"]}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary",textTransform:"uppercase"},children:d?.card_brand||"CARD"}),d?.exp_time&&e.jsx(f,{variant:"body2",sx:{color:"text.secondary",borderLeft:"1px solid",borderColor:"divider",pl:1},children:d?.exp_time})]}):e.jsxs(u,{spacing:1,sx:{borderRadius:1,backgroundColor:R=>R.palette.mode==="dark"?"grey.100":"grey.50",p:2},children:[e.jsx(Le,{did:d?.payer,responsive:!1,compact:!0,copyable:!1}),(A||v)&&e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[v?e.jsx(de,{size:14,sx:{mr:.5}}):e.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(ke,{fontSize:"small",sx:{color:"text.lighter"}}),e.jsxs(f,{variant:"body2",sx:{color:"text.primary"},children:[e.jsxs("strong",{children:[he(A?.token||"0",c?.decimal)," "]}),c?.symbol||""]})]}),e.jsxs(G,{size:"small",variant:"text",onClick:k,sx:{fontSize:"smaller",color:"primary.main"},children:[e.jsx(ue,{fontSize:"small"}),o("payment.autoTopup.addFunds")]})]})]});return e.jsx(P,{sx:{p:2,border:"1px solid",borderColor:b?"primary.main":"divider",borderRadius:1,bgcolor:b?"primary.50":"background.paper"},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(f,{variant:"subtitle2",sx:{display:"flex",alignItems:"center",gap:1,whiteSpace:"nowrap"},children:o("payment.autoTopup.currentPaymentMethod")}),e.jsx(G,{size:"small",startIcon:e.jsx(Ie,{}),onClick:w,variant:"text",sx:{color:"primary.main",whiteSpace:"nowrap",alignSelf:{xs:"flex-end",sm:"center"}},children:o(b?"payment.autoTopup.keepCurrent":"payment.autoTopup.changePaymentMethod")})]}),b?e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:o("payment.autoTopup.changePaymentMethodTip")}):z()]})})}function mt({open:t,onClose:r,currencyId:i,onSuccess:c=()=>{},onError:o=()=>{},defaultEnabled:b=void 0}){const{t:s,locale:j}=Q(),{session:d,connect:A,settings:v}=Ve(),[w,k]=m.useState(!1),[z,R]=m.useState(.5),[S,I]=m.useState(null),[p,x]=Ne({loading:!1,submitting:!1,authorizationRequired:!1,stripeContext:{client_secret:"",intent_type:"",status:"",public_key:"",customer:{}}}),a=He(v.paymentMethods),l=Qe({defaultValues:{enabled:b||B.enabled,threshold:B.threshold,quantity:B.quantity,payment_method_id:B.payment_method_id,recharge_currency_id:B.recharge_currency_id,price_id:B.price_id,daily_limits:{max_attempts:B.daily_max_attempts,max_amount:B.daily_max_amount}}}),{handleSubmit:y,setValue:_,watch:F}=l,L=F("enabled"),T=F("quantity"),C=F("recharge_currency_id"),D=v.paymentMethods.find(n=>n.payment_currencies.find(h=>h.id===C)),M=D?.type==="stripe",$=()=>{x({loading:!1,submitting:!1,authorizationRequired:!1}),r()},{data:g}=H(()=>ot(d?.user?.did,i),{refreshDeps:[d?.user?.did,i],ready:!!d?.user?.did&&!!i,onError:n=>{q.error(U(n))},onSuccess:n=>{_("enabled",b||n.enabled),_("threshold",n.threshold),_("quantity",n.quantity),_("payment_method_id",n.payment_method_id),_("recharge_currency_id",n.recharge_currency_id||n.price?.currency_id),_("price_id",n.price_id),_("daily_limits",{max_amount:n.daily_limits?.max_amount||0,max_attempts:n.daily_limits?.max_attempts||0}),n.slippage_config&&(I(n.slippage_config),R(n.slippage_config.percent??.5))}}),W=g?.price?.pricing_type==="dynamic",{data:V}=H(()=>lt(C),{refreshDeps:[C],ready:!!C&&W&&L&&!M,pollingInterval:3e4,pollingWhenHidden:!1,onError:n=>{console.warn("Failed to fetch exchange rate:",n.message)}}),E=m.useMemo(()=>a.filter(n=>g?.price?.currency_options?.find(h=>h.currency_id===n.id)),[a,g]),J=async()=>{try{await dt(g?.id)&&(x({submitting:!1,authorizationRequired:!1}),c?.(g),$(),q.success(s("payment.autoTopup.saveSuccess")))}catch(n){q.error(U(n))}finally{x({submitting:!1,authorizationRequired:!1})}},ge=async()=>{try{const n={...g,enabled:!1};if(!g?.enabled)return;const{data:h}=await N.post("/api/auto-recharge-configs/submit",n);c?.(h),q.success(s("payment.autoTopup.disableSuccess"))}catch(n){q.error(U(n)),o?.(n)}},fe=async n=>{_("enabled",n),n||await ge()},be=n=>{x({authorizationRequired:!0}),n.stripeContext?x({stripeContext:{client_secret:n.stripeContext.client_secret,intent_type:n.stripeContext.intent_type,status:n.stripeContext.status,public_key:n.paymentMethod.settings.stripe.publishable_key,customer:n.customer}}):n.delegation&&_e()},_e=()=>{try{x({submitting:!0}),A.open({containerEl:void 0,saveConnect:!1,locale:j,action:"auto-recharge-auth",prefix:me(xe(),"/api/did"),extraParams:{autoRechargeConfigId:g?.id},messages:{scan:s("payment.autoTopup.authTip"),title:s("payment.autoTopup.authTitle"),confirm:s("common.connect.confirm")},onSuccess:async()=>{A.close(),await J()},onClose:()=>{A.close(),x({submitting:!1,authorizationRequired:!1})},onError:n=>{x({submitting:!1,authorizationRequired:!1}),q.error(U(n))}})}catch(n){x({submitting:!1,authorizationRequired:!1}),q.error(U(n))}},je=async n=>{x({submitting:!0});try{const h={customer_id:d?.user?.did,enabled:n.enabled,threshold:n.threshold,currency_id:i,recharge_currency_id:n.recharge_currency_id,price_id:n.price_id,quantity:n.quantity,daily_limits:{max_attempts:n.daily_limits.max_attempts||0,max_amount:n.daily_limits.max_amount||"0"},change_payment_method:w};W&&S&&(h.slippage_config={...S,updated_at_ms:Date.now()});const{data:O}=await N.post("/api/auto-recharge-configs/submit",h);if(O.balanceResult&&!O.balanceResult.sufficient){await be({...O.balanceResult,paymentMethod:O.paymentMethod,customer:O.customer});return}x({submitting:!1,authorizationRequired:!1}),c?.(O),$(),q.success(s("payment.autoTopup.saveSuccess"))}catch(h){x({submitting:!1,authorizationRequired:!1}),q.error(U(h)),o?.(h)}},Y=n=>{je(n)},K=E.find(n=>n.id===C),ve=p.authorizationRequired&&M,Ce=async()=>{await J()},we=()=>{x({submitting:!1,authorizationRequired:!1})};return e.jsx(Fe,{open:t,onClose:$,maxWidth:"sm",fullWidth:!0,className:"base-dialog",title:s("payment.autoTopup.title"),actions:L?e.jsxs(u,{direction:"row",spacing:2,children:[e.jsx(G,{variant:"outlined",onClick:$,disabled:p.submitting,children:s("common.cancel")}),e.jsxs(G,{variant:"contained",onClick:()=>y(Y)(),disabled:p.loading||p.authorizationRequired||p.submitting,children:[p.submitting&&e.jsx(de,{size:20,sx:{mr:1}}),s("payment.autoTopup.saveConfiguration")]})]}):null,children:e.jsx(Xe,{...l,children:e.jsx(P,{component:"form",onSubmit:y(Y),children:e.jsxs(u,{sx:{gap:2},children:[e.jsx(Se,{severity:"info",children:s("payment.autoTopup.tip")}),e.jsxs(u,{spacing:2,direction:"row",sx:{alignItems:"center"},children:[e.jsx(f,{variant:"subtitle1",children:s("payment.autoTopup.enableLabel")}),e.jsx(Te,{control:e.jsx(Ze,{checked:L,onChange:n=>fe(n.target.checked)}),label:""})]}),L&&e.jsxs(e.Fragment,{children:[e.jsx(P,{sx:{pt:1},children:e.jsxs(u,{spacing:2.5,children:[e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"},".MuiTextField-root":{width:{xs:"100%",sm:"auto"}}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.triggerThreshold")}),e.jsx(ie,{name:"threshold",control:l.control,rules:{required:s("payment.checkout.required"),min:{value:0,message:s("payment.autoTopup.thresholdMinError")}},render:({field:n})=>e.jsx(le,{...n,type:"number",placeholder:s("payment.autoTopup.thresholdPlaceholder"),sx:{input:{minWidth:80}},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:pe("",g?.currency?.symbol)})},htmlInput:{min:0,step:.01}}})})]}),e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.purchaseBelow")}),e.jsx(ie,{name:"recharge_currency_id",control:l.control,render:({field:n})=>e.jsx(Ae,{...n,value:n.value,onChange:h=>n.onChange(h.target.value),size:"small",children:E.map(h=>e.jsx(Re,{value:h?.id,children:e.jsxs(u,{direction:"row",sx:{alignItems:"center",gap:1},children:[e.jsx(Pe,{src:h?.logo,sx:{width:20,height:20},alt:h?.symbol}),e.jsxs(f,{sx:{color:"text.secondary"},children:[h?.symbol," (",h?.method?.name,")"]})]})},h?.id))})})]}),g?.price?.product&&e.jsx(it,{product:g.price.product,price:g.price,creditCurrency:g.currency,currency:E.find(n=>n.id===C)||E[0],quantity:T,onQuantityChange:n=>_("quantity",n),maxQuantity:9999,minQuantity:1,exchangeRate:V?.rate,isDynamicPricing:W&&!M,exchangeRateData:V,slippageConfig:S,slippagePercent:z,onSlippageChange:n=>{I(n),n.percent!==void 0&&R(n.percent)},disabled:p.submitting}),g&&K&&e.jsx(ut,{config:g,onChangePaymentMethod:k,currency:K,paymentMethod:D}),e.jsx(st,{trigger:s("payment.autoTopup.advanced"),children:e.jsxs(u,{sx:{gap:2,pl:2,pr:1},children:[e.jsx(oe,{name:"daily_limits.max_amount",label:s("payment.autoTopup.dailyLimits.maxAmount"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAmountPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAmountDescription"),inputProps:{min:0,step:.01},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:E.find(n=>n.id===C)?.symbol||""})}},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"}),e.jsx(oe,{name:"daily_limits.max_attempts",label:s("payment.autoTopup.dailyLimits.maxAttempts"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAttemptsPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAttemptsDescription"),inputProps:{min:0,step:1},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"})]})})]})}),e.jsx(u,{spacing:2,children:ve&&e.jsx(P,{sx:{mt:2},children:p.stripeContext&&e.jsx(P,{sx:{mt:2},children:e.jsx(Je,{clientSecret:p.stripeContext.client_secret,intentType:p.stripeContext.intent_type,publicKey:p.stripeContext.public_key,customer:p.stripeContext.customer,mode:"setup",onConfirm:Ce,onCancel:we})})})})]})]})})})})}function pt(t){if(!t)return"Unknown error";if(t?.name==="ZodError")return Array.isArray(t.errors)?t.errors.map(r=>r.message).join(`
1
+ import{r as m,j as e,bg as ce,a3 as u,q as f,a2 as le,B as P,A as Se,aX as Te,aZ as ee,aT as Ae,ad as Re,N as Pe,x as G,w as de,b_ as Ie,bU as qe,bL as ke,bH as ue,aN as ze,aM as Z,b$ as Me,c0 as $e}from"./vendor-mui-BXZut9Pz.js";import{V as Q,Y as Ne,P as H,$ as Fe,Z as q,a7 as Le,F as me,aq as te,G as ne}from"./vendor-blocklet-B67R14so.js";import{f as ae,aR as Ee,aS as Be,aT as We,ay as De,a8 as Ue,aU as Oe,M as Ge,aV as re,a as Ve,W as He,h as Qe,F as Ze,S as Je,aW as se,C as ie,a3 as pe,aX as oe,a0 as Xe,e as N,k as O,i as he,a1 as Ye,l as xe,aY as Ke,aZ as et,a_ as tt,A as nt}from"./index-B4yaPb7B.js";import{a as at,b as rt}from"./vendor-react-BPknnnEA.js";import{I as st}from"./collapse-CSrlJ0eG.js";function it({product:t,price:r,currency:i,quantity:c,onQuantityChange:o,maxQuantity:b=99,minQuantity:s=1,creditCurrency:j,exchangeRate:d=null,isDynamicPricing:A=!1,exchangeRateData:v=null,slippageConfig:w=null,slippagePercent:k=.5,onSlippageChange:z=void 0,disabled:R=!1}){const{t:S,locale:I}=Q(),[p,x]=m.useState(c),a=Number(p)||0,{paymentAmount:l,usdReferenceDisplay:y}=m.useMemo(()=>{if(!A||!d||!r?.base_amount)return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const T=Number(r.base_amount)*a,C=Number(d);if(C<=0||!Number.isFinite(T))return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const D=T/C,M=Ee(D,!0,6),$=Be(T.toString(),I);return{paymentAmount:`${M} ${i.symbol}`,usdReferenceDisplay:$?`≈ $${$}`:null}},[A,d,r,i,t?.unit_label,p,a,I]),_=T=>{if(!T){x(void 0);return}T>=s&&T<=b&&(x(T),o(T))},F=T=>{const C=parseInt(T.target.value||"0",10);Number.isNaN(C)||_(C)},L=Number(r.metadata?.credit_config?.credit_amount||0);return e.jsxs(ce,{variant:"outlined",sx:{p:2},children:[e.jsxs(u,{direction:"row",spacing:2,sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(u,{direction:"row",spacing:2,sx:{alignItems:"center",flex:1},children:e.jsx(We,{name:t?.name||"",description:S("payment.autoTopup.creditsIncluded",{num:De(Ue(L*a),j?.symbol||"",I)}),logo:t?.images?.[0],size:40})}),e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center",alignSelf:{xs:"flex-end",sm:"center"}},children:[e.jsxs(f,{variant:"body2",sx:{color:"text.secondary",minWidth:"fit-content"},children:[S("common.quantity"),":"]}),e.jsx(le,{size:"small",value:p,onChange:F,type:"number",sx:{"& .MuiInputBase-root":{height:32}},slotProps:{htmlInput:{min:0,max:b,style:{textAlign:"center",padding:"4px 8px"}}}})]})]}),e.jsxs(u,{direction:"row",sx:{justifyContent:"space-between",alignItems:"flex-start",mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:S("payment.autoTopup.rechargeAmount")}),e.jsxs(u,{sx:{alignItems:"flex-end"},children:[e.jsx(f,{variant:"h6",sx:{fontWeight:600,color:"text.primary"},children:l}),y&&e.jsx(f,{sx:{fontSize:"0.7875rem",color:"text.lighter"},children:y}),A&&v?.rate&&e.jsx(Oe,{rateLine:S("payment.checkout.quote.rateLine",{symbol:i.symbol,rate:`$${re(v.rate)||v.rate}`}),rows:[{label:S("payment.checkout.quote.detailProvider"),value:v?.provider_display||v?.provider_name||"—"},{label:S("payment.checkout.quote.detailUpdatedAt"),value:v?.timestamp_ms?Ge(v.timestamp_ms,I):"—"},{label:S("payment.checkout.quote.detailSlippage"),value:w?.mode==="rate"&&w.min_acceptable_rate?`$${re(w.min_acceptable_rate)||w.min_acceptable_rate}`:`${w?.percent??k}%`,isSlippage:!0}],isSubscription:!0,slippageValue:w?.percent??k,slippageConfig:w||void 0,onSlippageChange:z,exchangeRate:v?.rate,baseCurrency:"USD",disabled:R})]})]})]})}const ot=async(t,r)=>{const{data:i}=await N.get(`/api/auto-recharge-configs/customer/${t}`,{params:{currency_id:r}});return i},ct=async(t,r)=>{const{data:i}=await N.get("/api/customers/payer-token",{params:{currencyId:t,payerAddress:r}});return i},B={enabled:!1,threshold:"100",quantity:1,payment_method_id:"",recharge_currency_id:"",price_id:"",daily_max_amount:0,daily_max_attempts:0},lt=async t=>{const{data:r}=await N.post("/api/exchange-rates/validate",{currency:t});return r},dt=async t=>{let r;return await Ye(async()=>{const{data:i}=await N.get(`/api/auto-recharge-configs/retrieve/${t}`);return r=i,!!r.payment_settings?.payment_method_options?.[r.paymentMethod.type]?.payer},{interval:2e3,timeout:180*1e3}),r};function ut({config:t,onChangePaymentMethod:r,paymentMethod:i,currency:c}){const{t:o}=Q(),[b,s]=m.useState(!1),j=at(),d=t?.payment_settings?.payment_method_options?.[i.type||""],{data:A,loading:v}=H(async()=>i.type==="stripe"?null:await ct(c.id,d?.payer),{refreshDeps:[c.id,d?.payer],ready:!!c.id&&!!d?.payer}),w=()=>{const R=!b;s(R),r(R)};if(!d)return null;const k=R=>{const S=me(xe(),`/customer/recharge/${c.id}?rechargeAddress=${d?.payer}`),I=Ke(S,!0);et(R,I,j)},z=()=>i.type==="stripe"?e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(qe,{fontSize:"small",color:"primary"}),e.jsxs(f,{variant:"body2",children:["**** **** **** ",d?.card_last4||"****"]}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary",textTransform:"uppercase"},children:d?.card_brand||"CARD"}),d?.exp_time&&e.jsx(f,{variant:"body2",sx:{color:"text.secondary",borderLeft:"1px solid",borderColor:"divider",pl:1},children:d?.exp_time})]}):e.jsxs(u,{spacing:1,sx:{borderRadius:1,backgroundColor:R=>R.palette.mode==="dark"?"grey.100":"grey.50",p:2},children:[e.jsx(Le,{did:d?.payer,responsive:!1,compact:!0,copyable:!1}),(A||v)&&e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[v?e.jsx(de,{size:14,sx:{mr:.5}}):e.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(ke,{fontSize:"small",sx:{color:"text.lighter"}}),e.jsxs(f,{variant:"body2",sx:{color:"text.primary"},children:[e.jsxs("strong",{children:[he(A?.token||"0",c?.decimal)," "]}),c?.symbol||""]})]}),e.jsxs(G,{size:"small",variant:"text",onClick:k,sx:{fontSize:"smaller",color:"primary.main"},children:[e.jsx(ue,{fontSize:"small"}),o("payment.autoTopup.addFunds")]})]})]});return e.jsx(P,{sx:{p:2,border:"1px solid",borderColor:b?"primary.main":"divider",borderRadius:1,bgcolor:b?"primary.50":"background.paper"},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(f,{variant:"subtitle2",sx:{display:"flex",alignItems:"center",gap:1,whiteSpace:"nowrap"},children:o("payment.autoTopup.currentPaymentMethod")}),e.jsx(G,{size:"small",startIcon:e.jsx(Ie,{}),onClick:w,variant:"text",sx:{color:"primary.main",whiteSpace:"nowrap",alignSelf:{xs:"flex-end",sm:"center"}},children:o(b?"payment.autoTopup.keepCurrent":"payment.autoTopup.changePaymentMethod")})]}),b?e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:o("payment.autoTopup.changePaymentMethodTip")}):z()]})})}function mt({open:t,onClose:r,currencyId:i,onSuccess:c=()=>{},onError:o=()=>{},defaultEnabled:b=void 0}){const{t:s,locale:j}=Q(),{session:d,connect:A,settings:v}=Ve(),[w,k]=m.useState(!1),[z,R]=m.useState(.5),[S,I]=m.useState(null),[p,x]=Ne({loading:!1,submitting:!1,authorizationRequired:!1,stripeContext:{client_secret:"",intent_type:"",status:"",public_key:"",customer:{}}}),a=He(v.paymentMethods),l=Qe({defaultValues:{enabled:b||B.enabled,threshold:B.threshold,quantity:B.quantity,payment_method_id:B.payment_method_id,recharge_currency_id:B.recharge_currency_id,price_id:B.price_id,daily_limits:{max_attempts:B.daily_max_attempts,max_amount:B.daily_max_amount}}}),{handleSubmit:y,setValue:_,watch:F}=l,L=F("enabled"),T=F("quantity"),C=F("recharge_currency_id"),D=v.paymentMethods.find(n=>n.payment_currencies.find(h=>h.id===C)),M=D?.type==="stripe",$=()=>{x({loading:!1,submitting:!1,authorizationRequired:!1}),r()},{data:g}=H(()=>ot(d?.user?.did,i),{refreshDeps:[d?.user?.did,i],ready:!!d?.user?.did&&!!i,onError:n=>{q.error(O(n))},onSuccess:n=>{_("enabled",b||n.enabled),_("threshold",n.threshold),_("quantity",n.quantity),_("payment_method_id",n.payment_method_id),_("recharge_currency_id",n.recharge_currency_id||n.price?.currency_id),_("price_id",n.price_id),_("daily_limits",{max_amount:n.daily_limits?.max_amount||0,max_attempts:n.daily_limits?.max_attempts||0}),n.slippage_config&&(I(n.slippage_config),R(n.slippage_config.percent??.5))}}),W=g?.price?.pricing_type==="dynamic",{data:V}=H(()=>lt(C),{refreshDeps:[C],ready:!!C&&W&&L&&!M,pollingInterval:3e4,pollingWhenHidden:!1,onError:n=>{console.warn("Failed to fetch exchange rate:",n.message)}}),E=m.useMemo(()=>a.filter(n=>g?.price?.currency_options?.find(h=>h.currency_id===n.id)),[a,g]),X=async()=>{try{await dt(g?.id)&&(x({submitting:!1,authorizationRequired:!1}),c?.(g),$(),q.success(s("payment.autoTopup.saveSuccess")))}catch(n){q.error(O(n))}finally{x({submitting:!1,authorizationRequired:!1})}},ge=async()=>{try{const n={...g,enabled:!1};if(!g?.enabled)return;const{data:h}=await N.post("/api/auto-recharge-configs/submit",n);c?.(h),q.success(s("payment.autoTopup.disableSuccess"))}catch(n){q.error(O(n)),o?.(n)}},fe=async n=>{_("enabled",n),n||await ge()},be=n=>{x({authorizationRequired:!0}),n.stripeContext?x({stripeContext:{client_secret:n.stripeContext.client_secret,intent_type:n.stripeContext.intent_type,status:n.stripeContext.status,public_key:n.paymentMethod.settings.stripe.publishable_key,customer:n.customer}}):n.delegation&&_e()},_e=()=>{try{x({submitting:!0}),A.open({containerEl:void 0,saveConnect:!1,locale:j,action:"auto-recharge-auth",prefix:me(xe(),"/api/did"),extraParams:{autoRechargeConfigId:g?.id},messages:{scan:s("payment.autoTopup.authTip"),title:s("payment.autoTopup.authTitle"),confirm:s("common.connect.confirm")},onSuccess:async()=>{A.close(),await X()},onClose:()=>{A.close(),x({submitting:!1,authorizationRequired:!1})},onError:n=>{x({submitting:!1,authorizationRequired:!1}),q.error(O(n))}})}catch(n){x({submitting:!1,authorizationRequired:!1}),q.error(O(n))}},je=async n=>{x({submitting:!0});try{const h={customer_id:d?.user?.did,enabled:n.enabled,threshold:n.threshold,currency_id:i,recharge_currency_id:n.recharge_currency_id,price_id:n.price_id,quantity:n.quantity,daily_limits:{max_attempts:n.daily_limits.max_attempts||0,max_amount:n.daily_limits.max_amount||"0"},change_payment_method:w};W&&S&&(h.slippage_config={...S,updated_at_ms:Date.now()});const{data:U}=await N.post("/api/auto-recharge-configs/submit",h);if(U.balanceResult&&!U.balanceResult.sufficient){await be({...U.balanceResult,paymentMethod:U.paymentMethod,customer:U.customer});return}x({submitting:!1,authorizationRequired:!1}),c?.(U),$(),q.success(s("payment.autoTopup.saveSuccess"))}catch(h){x({submitting:!1,authorizationRequired:!1}),q.error(O(h)),o?.(h)}},Y=n=>{je(n)},K=E.find(n=>n.id===C),ve=p.authorizationRequired&&M,Ce=async()=>{await X()},we=()=>{x({submitting:!1,authorizationRequired:!1})};return e.jsx(Fe,{open:t,onClose:$,maxWidth:"sm",fullWidth:!0,className:"base-dialog",title:s("payment.autoTopup.title"),actions:L?e.jsxs(u,{direction:"row",spacing:2,children:[e.jsx(G,{variant:"outlined",onClick:$,disabled:p.submitting,children:s("common.cancel")}),e.jsxs(G,{variant:"contained",onClick:()=>y(Y)(),disabled:p.loading||p.authorizationRequired||p.submitting,children:[p.submitting&&e.jsx(de,{size:20,sx:{mr:1}}),s("payment.autoTopup.saveConfiguration")]})]}):null,children:e.jsx(Ze,{...l,children:e.jsx(P,{component:"form",onSubmit:y(Y),children:e.jsxs(u,{sx:{gap:2},children:[e.jsx(Se,{severity:"info",children:s("payment.autoTopup.tip")}),e.jsxs(u,{spacing:2,direction:"row",sx:{alignItems:"center"},children:[e.jsx(f,{variant:"subtitle1",children:s("payment.autoTopup.enableLabel")}),e.jsx(Te,{control:e.jsx(Je,{checked:L,onChange:n=>fe(n.target.checked)}),label:""})]}),L&&e.jsxs(e.Fragment,{children:[e.jsx(P,{sx:{pt:1},children:e.jsxs(u,{spacing:2.5,children:[e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"},".MuiTextField-root":{width:{xs:"100%",sm:"auto"}}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.triggerThreshold")}),e.jsx(ie,{name:"threshold",control:l.control,rules:{required:s("payment.checkout.required"),min:{value:0,message:s("payment.autoTopup.thresholdMinError")}},render:({field:n})=>e.jsx(le,{...n,type:"number",placeholder:s("payment.autoTopup.thresholdPlaceholder"),sx:{input:{minWidth:80}},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:pe("",g?.currency?.symbol)})},htmlInput:{min:0,step:.01}}})})]}),e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.purchaseBelow")}),e.jsx(ie,{name:"recharge_currency_id",control:l.control,render:({field:n})=>e.jsx(Ae,{...n,value:n.value,onChange:h=>n.onChange(h.target.value),size:"small",children:E.map(h=>e.jsx(Re,{value:h?.id,children:e.jsxs(u,{direction:"row",sx:{alignItems:"center",gap:1},children:[e.jsx(Pe,{src:h?.logo,sx:{width:20,height:20},alt:h?.symbol}),e.jsxs(f,{sx:{color:"text.secondary"},children:[h?.symbol," (",h?.method?.name,")"]})]})},h?.id))})})]}),g?.price?.product&&e.jsx(it,{product:g.price.product,price:g.price,creditCurrency:g.currency,currency:E.find(n=>n.id===C)||E[0],quantity:T,onQuantityChange:n=>_("quantity",n),maxQuantity:9999,minQuantity:1,exchangeRate:V?.rate,isDynamicPricing:W&&!M,exchangeRateData:V,slippageConfig:S,slippagePercent:z,onSlippageChange:n=>{I(n),n.percent!==void 0&&R(n.percent)},disabled:p.submitting}),g&&K&&e.jsx(ut,{config:g,onChangePaymentMethod:k,currency:K,paymentMethod:D}),e.jsx(st,{trigger:s("payment.autoTopup.advanced"),children:e.jsxs(u,{sx:{gap:2,pl:2,pr:1},children:[e.jsx(oe,{name:"daily_limits.max_amount",label:s("payment.autoTopup.dailyLimits.maxAmount"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAmountPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAmountDescription"),inputProps:{min:0,step:.01},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:E.find(n=>n.id===C)?.symbol||""})}},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"}),e.jsx(oe,{name:"daily_limits.max_attempts",label:s("payment.autoTopup.dailyLimits.maxAttempts"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAttemptsPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAttemptsDescription"),inputProps:{min:0,step:1},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"})]})})]})}),e.jsx(u,{spacing:2,children:ve&&e.jsx(P,{sx:{mt:2},children:p.stripeContext&&e.jsx(P,{sx:{mt:2},children:e.jsx(Xe,{clientSecret:p.stripeContext.client_secret,intentType:p.stripeContext.intent_type,publicKey:p.stripeContext.public_key,customer:p.stripeContext.customer,mode:"setup",onConfirm:Ce,onCancel:we})})})})]})]})})})})}function pt(t){if(!t)return"Unknown error";if(t?.name==="ZodError")return Array.isArray(t.errors)?t.errors.map(r=>r.message).join(`
2
2
  `):"Validation failed";if(Array.isArray(t?.details))return`Validate failed: ${t.details.map(i=>{const c=i.message.replace(/["]/g,"'");return`${i.path.join(".")}: ${c}`}).join(";")}`;if(Array.isArray(t?.errors))return t.errors.map(r=>r.msg||r.message).join(`
3
3
  `);if(Array.isArray(t?.constraints))return Object.values(t.constraints).join(`
4
4
  `);if(t?.keyword==="validation")return t.message||"Validation error";if(Array.isArray(t?.errors))return t.errors.map(r=>r.message).join(`
5
- `);if(t instanceof TypeError&&t.message.includes("fetch"))return"Network error: Failed to fetch";if(t?.name==="FetchError")return t.message||"Fetch error occurred";if(t?.isAxiosError){if(t.response?.data){if(t.response.data.message)return t.response.data.message;if(t.response.data.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||"Request failed"}if(t?.response){if(t.response.error)return t.response.error;if(t.response.data?.message)return t.response.data.message;if(t.response.data?.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||String(t)}const ye=m.createContext(null),ht=()=>m.useContext(ye);function jt({skeleton:t,children:r,skeletonComponent:i=null,onStateChange:c=()=>{}}){const[o,b]=m.useState("hidden"),s=m.useRef(null);m.useEffect(()=>{c(o)},[o]);const j=m.useCallback((A=!0)=>{s.current&&(clearTimeout(s.current),s.current=null),b(A?"none":"visible")},[]),d=m.useMemo(()=>({hideRender:j}),[j]);return m.useEffect(()=>(t||(s.current=setTimeout(()=>{b("visible"),s.current=null},3e3)),()=>{s.current&&(clearTimeout(s.current),s.current=null)}),[t]),t?i:o==="none"?null:e.jsx(ye.Provider,{value:d,children:e.jsx(P,{sx:{position:o==="hidden"?"absolute":"static",left:o==="hidden"?"-9999px":"auto",top:o==="hidden"?"-9999px":"auto",visibility:o==="hidden"?"hidden":"visible",width:o==="hidden"?"0":"auto",height:o==="hidden"?"0":"auto",overflow:"hidden"},children:r})})}var Z=(t=>(t.OVERVIEW="overview",t.GRANTS="grants",t.TRANSACTIONS="transactions",t))(Z||{});const xt=async t=>{try{const[r,i]=await Promise.all([N.get(`/api/credit-grants/summary?customer_id=${t}`),N.get(`/api/meter-events/pending-amount?customer_id=${t}`)]);return{grants:r.data,pendingAmount:i.data}}catch(r){return console.error("Failed to fetch credit summary:",r),{grants:null,transactions:null,pendingAmount:null}}};function vt({customerId:t,settings:r,mode:i="portal"}){const{t:c}=Q(),[o,b]=rt(),s=()=>{const a=o.get("creditTab");return a&&Object.values(Z).includes(a)?a:"overview"},[j,d]=m.useState(s),A=ht(),[v,w]=m.useState({currencyId:"",open:!1});m.useEffect(()=>{const a=o.get("creditTab");a&&Object.values(Z).includes(a)&&d(a)},[o]),m.useEffect(()=>{const a=o.get("action"),l=o.get("currencyId");if(a==="auto-recharge"&&l){w({currencyId:l,open:!0});const y=new URLSearchParams(o);y.delete("action"),y.delete("currencyId"),b(y,{replace:!0})}},[o,b]);const k=m.useMemo(()=>r?.paymentMethods?.filter(a=>a.type==="arcblock")?.flatMap(a=>a.payment_currencies)?.filter(a=>a.type==="credit")||[],[r]),{data:z}=H(xt,{defaultParams:[t],refreshDeps:[j==="overview"],onSuccess:a=>{const l=k.filter(y=>a.grants?.[y.id]);A?.hideRender(l.length===0)}}),R=async a=>{try{const l=await N.get(`/api/payment-currencies/${a.id}/recharge-config`).then(y=>y.data);if(l.recharge_config&&l.recharge_config.payment_url){const y=new URL(l.recharge_config.payment_url);y.searchParams.set("redirect",window.location.href),window.open(y.toString(),"_self")}else q.error(c("customer.recharge.unsupported"))}catch(l){console.error("Failed to fetch recharge config:",l),q.error(pt(l))}},S=a=>{w({currencyId:a.id,open:!0})},I=a=>{d(a);const l=new URLSearchParams(o);a==="overview"?l.delete("creditTab"):l.set("creditTab",a),b(l)},p=a=>{if(r?.paymentMethods?.find(M=>M.id===a.payment_method_id)?.type!=="arcblock")return null;const y=a.id,_=z?.grants?.[y],F=z?.pendingAmount?.[y]||"0";if(!_||_.meter?.status==="inactive")return null;const L=_.paymentCurrency.recharge_config?.base_price_id&&i==="portal",T=_.totalAmount||"0",C=_.remainingAmount||"0",D=_.meter?.name||a.name;return e.jsx(ce,{sx:{height:"100%",display:"flex",flexDirection:"column",border:"1px solid",borderColor:"divider",boxShadow:1,borderRadius:1,backgroundColor:"background.default"},children:e.jsx(Me,{sx:{flexGrow:1},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{direction:"row",spacing:.5,sx:{alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider",pb:2},children:[e.jsx(f,{variant:"h6",component:"div",children:D}),L&&e.jsx(te,{variant:"outlined",size:"small",color:"primary",menu:[e.jsxs(te.Item,{onClick:()=>S(a),sx:{color:"primary.main"},children:[e.jsx($e,{fontSize:"small",sx:{mr:.5}}),e.jsx(f,{variant:"body2",className:"recharge-title",children:c("customer.credit.autoRecharge")})]},"autoRecharge")],children:e.jsxs(G,{variant:"text",color:"primary",size:"small",onClick:()=>R(a),children:[e.jsx(ue,{fontSize:"small"}),e.jsx(f,{variant:"body2",className:"recharge-title",children:c("customer.credit.recharge")})]})})]}),(()=>{const M=new ne(C),$=new ne(F),g=M.sub($),W=g.isNeg(),V=W?g.abs().toString():g.toString(),E=T==="0"&&C==="0"&&F==="0"?"0":pe(he(V,a.decimal),a.symbol,!1);return e.jsxs(P,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(f,{variant:"body2",gutterBottom:!0,sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.creditBalance")}),e.jsx(f,{variant:"h5",component:"div",sx:{fontWeight:"normal",color:W?"error.main":"text.primary"},children:W?`-${E}`:E})]})})()]})})},a.id)},x=m.useMemo(()=>k.filter(a=>!!z?.grants?.[a.id]),[k,z?.grants]);return e.jsxs(u,{sx:{width:"100%"},children:[e.jsxs(ze,{value:j,onChange:(a,l)=>I(l),sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(X,{label:c("admin.creditGrants.overview"),value:"overview"}),e.jsx(X,{label:c("admin.creditGrants.tab"),value:"grants"}),e.jsx(X,{label:c("admin.creditTransactions.tab"),value:"transactions"})]}),e.jsxs(P,{className:"section-body",children:[j==="overview"&&e.jsxs(P,{sx:{width:"100%",mt:1},children:[e.jsx(P,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",md:"repeat(2, 1fr)"},gap:2,"@container (max-width: 600px)":{gridTemplateColumns:"repeat(1, 1fr)"}},children:x.map(p)}),x.length===0&&e.jsxs(P,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,textAlign:"center"},children:[e.jsx(f,{variant:"h6",gutterBottom:!0,sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.noGrants")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.noGrantsDescription")})]})]},j),j==="grants"&&e.jsx(tt,{customer_id:t,mode:i},j),j==="transactions"&&e.jsx(nt,{customer_id:t,mode:i,includeGrants:!0},j)]}),v.open&&e.jsx(mt,{open:!0,onClose:()=>w({currencyId:"",open:!1}),currencyId:v.currencyId})]})}export{jt as C,vt as a,ht as u};
5
+ `);if(t instanceof TypeError&&t.message.includes("fetch"))return"Network error: Failed to fetch";if(t?.name==="FetchError")return t.message||"Fetch error occurred";if(t?.isAxiosError){if(t.response?.data){if(t.response.data.message)return t.response.data.message;if(t.response.data.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||"Request failed"}if(t?.response){if(t.response.error)return t.response.error;if(t.response.data?.message)return t.response.data.message;if(t.response.data?.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||String(t)}const ye=m.createContext(null),ht=()=>m.useContext(ye);function jt({skeleton:t,children:r,skeletonComponent:i=null,onStateChange:c=()=>{}}){const[o,b]=m.useState("hidden"),s=m.useRef(null);m.useEffect(()=>{c(o)},[o]);const j=m.useCallback((A=!0)=>{s.current&&(clearTimeout(s.current),s.current=null),b(A?"none":"visible")},[]),d=m.useMemo(()=>({hideRender:j}),[j]);return m.useEffect(()=>(t||(s.current=setTimeout(()=>{b("visible"),s.current=null},3e3)),()=>{s.current&&(clearTimeout(s.current),s.current=null)}),[t]),t?i:o==="none"?null:e.jsx(ye.Provider,{value:d,children:e.jsx(P,{sx:{position:o==="hidden"?"absolute":"static",left:o==="hidden"?"-9999px":"auto",top:o==="hidden"?"-9999px":"auto",visibility:o==="hidden"?"hidden":"visible",width:o==="hidden"?"0":"auto",height:o==="hidden"?"0":"auto",overflow:"hidden"},children:r})})}var J=(t=>(t.OVERVIEW="overview",t.GRANTS="grants",t.TRANSACTIONS="transactions",t))(J||{});const xt=async t=>{try{const[r,i]=await Promise.all([N.get(`/api/credit-grants/summary?customer_id=${t}`),N.get(`/api/meter-events/pending-amount?customer_id=${t}`)]);return{grants:r.data,pendingAmount:i.data}}catch(r){return console.error("Failed to fetch credit summary:",r),{grants:null,transactions:null,pendingAmount:null}}};function vt({customerId:t,settings:r,mode:i="portal"}){const{t:c}=Q(),[o,b]=rt(),s=()=>{const a=o.get("creditTab");return a&&Object.values(J).includes(a)?a:"overview"},[j,d]=m.useState(s),A=ht(),[v,w]=m.useState({currencyId:"",open:!1});m.useEffect(()=>{const a=o.get("creditTab");a&&Object.values(J).includes(a)&&d(a)},[o]),m.useEffect(()=>{const a=o.get("action"),l=o.get("currencyId");if(a==="auto-recharge"&&l){w({currencyId:l,open:!0});const y=new URLSearchParams(o);y.delete("action"),y.delete("currencyId"),b(y,{replace:!0})}},[o,b]);const k=m.useMemo(()=>r?.paymentMethods?.filter(a=>a.type==="arcblock")?.flatMap(a=>a.payment_currencies)?.filter(a=>a.type==="credit")||[],[r]),{data:z}=H(xt,{defaultParams:[t],refreshDeps:[j==="overview"],onSuccess:a=>{const l=k.filter(y=>a.grants?.[y.id]);A?.hideRender(l.length===0)}}),R=async a=>{try{const l=await N.get(`/api/payment-currencies/${a.id}/recharge-config`).then(y=>y.data);if(l.recharge_config&&l.recharge_config.payment_url){const y=new URL(l.recharge_config.payment_url);y.searchParams.set("redirect",window.location.href),window.open(y.toString(),"_self")}else q.error(c("customer.recharge.unsupported"))}catch(l){console.error("Failed to fetch recharge config:",l),q.error(pt(l))}},S=a=>{w({currencyId:a.id,open:!0})},I=a=>{d(a);const l=new URLSearchParams(o);a==="overview"?l.delete("creditTab"):l.set("creditTab",a),b(l)},p=a=>{if(r?.paymentMethods?.find(M=>M.id===a.payment_method_id)?.type!=="arcblock")return null;const y=a.id,_=z?.grants?.[y],F=z?.pendingAmount?.[y]||"0";if(!_||_.meter?.status==="inactive")return null;const L=_.paymentCurrency.recharge_config?.base_price_id&&i==="portal",T=_.totalAmount||"0",C=_.remainingAmount||"0",D=_.meter?.name||a.name;return e.jsx(ce,{sx:{height:"100%",display:"flex",flexDirection:"column",border:"1px solid",borderColor:"divider",boxShadow:1,borderRadius:1,backgroundColor:"background.default"},children:e.jsx(Me,{sx:{flexGrow:1},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{direction:"row",spacing:.5,sx:{alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider",pb:2},children:[e.jsx(f,{variant:"h6",component:"div",children:D}),L&&e.jsx(te,{variant:"outlined",size:"small",color:"primary",menu:[e.jsxs(te.Item,{onClick:()=>S(a),sx:{color:"primary.main"},children:[e.jsx($e,{fontSize:"small",sx:{mr:.5}}),e.jsx(f,{variant:"body2",className:"recharge-title",children:c("customer.credit.autoRecharge")})]},"autoRecharge")],children:e.jsxs(G,{variant:"text",color:"primary",size:"small",onClick:()=>R(a),children:[e.jsx(ue,{fontSize:"small"}),e.jsx(f,{variant:"body2",className:"recharge-title",children:c("customer.credit.recharge")})]})})]}),(()=>{const M=new ne(C),$=new ne(F),g=M.sub($),W=g.isNeg(),V=W?g.abs().toString():g.toString(),E=T==="0"&&C==="0"&&F==="0"?"0":pe(he(V,a.decimal),a.symbol,!1);return e.jsxs(P,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(f,{variant:"body2",gutterBottom:!0,sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.creditBalance")}),e.jsx(f,{variant:"h5",component:"div",sx:{fontWeight:"normal",color:W?"error.main":"text.primary"},children:W?`-${E}`:E})]})})()]})})},a.id)},x=m.useMemo(()=>k.filter(a=>!!z?.grants?.[a.id]),[k,z?.grants]);return e.jsxs(u,{sx:{width:"100%"},children:[e.jsxs(ze,{value:j,onChange:(a,l)=>I(l),sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(Z,{label:c("admin.creditGrants.overview"),value:"overview"}),e.jsx(Z,{label:c("admin.creditGrants.tab"),value:"grants"}),e.jsx(Z,{label:c("admin.creditTransactions.tab"),value:"transactions"})]}),e.jsxs(P,{className:"section-body",children:[j==="overview"&&e.jsxs(P,{sx:{width:"100%",mt:1},children:[e.jsx(P,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",md:"repeat(2, 1fr)"},gap:2,"@container (max-width: 600px)":{gridTemplateColumns:"repeat(1, 1fr)"}},children:x.map(p)}),x.length===0&&e.jsxs(P,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,textAlign:"center"},children:[e.jsx(f,{variant:"h6",gutterBottom:!0,sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.noGrants")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.noGrantsDescription")})]})]},j),j==="grants"&&e.jsx(tt,{customer_id:t,mode:i},j),j==="transactions"&&e.jsx(nt,{customer_id:t,mode:i,includeGrants:!0},j)]}),v.open&&e.jsx(mt,{open:!0,onClose:()=>w({currencyId:"",open:!1}),currencyId:v.currencyId})]})}export{jt as C,vt as a,ht as u};
@@ -1 +1 @@
1
- import{r as F,j as e,B as v,q as f,a3 as q,x as Y,w as ne,aN as ie,aM as G,a7 as K,bf as O}from"./vendor-mui-BXZut9Pz.js";import{V as I,G as $,$ as re,Y as B,X as ce,O as ae}from"./vendor-blocklet-D_i_QeSo.js";import{a as se,h as ue,Y as N,F as me,e as k,b8 as W,k as V,I as X,T as J,v as Q,j as A}from"./index-DgSc1Qy8.js";import{D as Z,P as de}from"./index-Clbt8nRm.js";import{A as le}from"./actions-jxGAdGfb.js";import{L as ee}from"./link-DMWJcQvZ.js";import{C as oe}from"./link-3eeclTeS.js";import{S as pe}from"./description-Ym17DL48.js";import{S as fe}from"./status-l6pD08fw.js";import{a as _e}from"./vendor-react-BPknnnEA.js";function Ae({open:o,onClose:h,onSubmit:S=()=>{},couponId:t,promotionCode:s=null,isEditing:a=!1,availableCurrencies:p=[]}){const{t:m}=I(),{settings:c}=se(),w=ue({mode:"onChange",defaultValues:Z}),{handleSubmit:L,reset:C,formState:{isSubmitting:P}}=w;F.useEffect(()=>{if(o)if(a&&s){const n={},_=s.restrictions?.minimum_amount_currency?N(c.paymentMethods,s.restrictions.minimum_amount_currency):null,x=s.restrictions?.minimum_amount?parseFloat($(s.restrictions.minimum_amount,_?.decimal||0)):void 0;let M=!1;if(s.restrictions?.currency_options){const H=Object.entries(s.restrictions.currency_options);M=H.length>0,H.forEach(([U,T])=>{const E=N(c.paymentMethods,U);let g=0;if(T&&typeof T=="object"&&"minimum_amount"in T){const u=T.minimum_amount;E&&u?g=parseFloat($(u||"0",E.decimal)):g=u||0}n[U]={minimum_amount:g}})}C({code:s.code||"",active:s.active??!0,max_redemptions:s.max_redemptions||void 0,description:s.description||"",expires_at:s.expires_at?new Date(s.expires_at*1e3).toISOString().slice(0,16):"",verification_type:s.verification_type||"code",limit_number_redemptions:!!s.max_redemptions,add_expiration_date:!!s.expires_at,restrictions:{first_time_transaction:s.restrictions?.first_time_transaction||!1,require_minimum_amount:M,minimum_amount:x,minimum_amount_currency:_?.id,currency_options:n},customer_dids:s.customer_dids||[],nft_addresses:s.nft_config?.addresses||[],nft_tags:s.nft_config?.tags||[],trusted_issuers:s.nft_config?.trusted_issuers||[],trusted_parents:s.nft_config?.trusted_parents||[],min_balance:s.nft_config?.min_balance||1,vc_roles:s.vc_config?.roles||[],vc_trusted_issuers:s.vc_config?.trusted_issuers||[]})}else C(Z)},[o,a,s,C,c.paymentMethods]);const b=async n=>{try{const _={active:n.active,verification_type:n.verification_type,restrictions:n.restrictions,description:n.description,metadata:{}};a||(_.coupon_id=t),n.code&&n.code.trim()&&(_.code=n.code),n.limit_number_redemptions&&n.max_redemptions&&(_.max_redemptions=n.max_redemptions),n.expires_at&&(_.expires_at=Math.floor(new Date(n.expires_at).getTime()/1e3)),n.verification_type==="nft"?_.nft_config={addresses:n.nft_addresses?.filter(x=>x.trim())||[],tags:n.nft_tags?.filter(x=>x.trim())||[],trusted_issuers:n.trusted_issuers?.filter(x=>x.trim())||[],trusted_parents:n.trusted_parents?.filter(x=>x.trim())||[],min_balance:n.min_balance||1}:n.verification_type==="vc"?_.vc_config={roles:n.vc_roles?.filter(x=>x.trim())||[],trusted_issuers:n.vc_trusted_issuers?.filter(x=>x.trim())||[]}:n.verification_type==="user_restricted"&&(_.customer_dids=n.customer_dids?.filter(x=>x.trim())||[]),a&&s?(await k.put(`/api/promotion-codes/${s.id}`,_),B.success(m("common.saved")),W("promotion-code.updated")):(await k.post("/api/promotion-codes",_),B.success(m("admin.coupon.saved")),W("promotion-code.created")),S&&S(),h()}catch(_){console.error(_),B.error(V(_))}},D=()=>{C(),h()},d=m(a?"admin.promotionCode.edit":"admin.coupon.createPromotionCode");return e.jsx(re,{open:o,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:D,showCloseButton:!1,title:d,actions:e.jsxs(q,{direction:"row",children:[e.jsx(Y,{size:"small",sx:{mr:2},onClick:D,disabled:P,children:m("common.cancel")}),e.jsxs(Y,{variant:"contained",color:"primary",size:"small",disabled:P,onClick:L(b),children:[P&&e.jsx(ne,{size:16,sx:{mr:1}}),m(a?"common.save":"admin.coupon.createPromotionCode")]})]}),children:e.jsx(me,{...w,children:e.jsxs(v,{sx:{display:"flex",flexDirection:"column",gap:3},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:m("admin.coupon.promotionCodeDescription")}),e.jsx(de,{showCodeInput:!0,showExpandedOptions:!0,availableCurrencies:p})]})})})}function $e({data:o,onChange:h,variant:S="compact"}){const{t}=I(),s=!o.locked&&o.active,a=!o.locked,p=o.active,[m,c]=ce({action:"",loading:!1}),w=async()=>{try{c({loading:!0}),await k.put(`/api/promotion-codes/${o.id}/archive`).then(b=>b.data),B.success(t("common.saved")),W("promotion-code.updated"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},L=async()=>{try{c({loading:!0}),await k.delete(`/api/promotion-codes/${o.id}`).then(b=>b.data),B.success(t("common.removed")),W("promotion-code.deleted"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},C=()=>{c({action:"edit"}),h("edit",o)},P=[{label:t("admin.promotionCode.edit"),handler:C,color:s?"text.primary":"text.disabled",disabled:!s},{label:t("admin.promotionCode.archive"),handler:()=>c({action:"archive"}),color:p?"text.primary":"text.disabled",disabled:!p},{label:t("admin.promotionCode.delete"),handler:()=>c({action:"delete"}),color:a?"error.main":"text.disabled",disabled:!a}];return e.jsxs(e.Fragment,{children:[e.jsx(le,{variant:S,actions:P}),m.action==="archive"&&e.jsx(X,{onConfirm:w,onCancel:()=>c({action:""}),title:t("admin.promotionCode.archive"),message:t("admin.promotionCode.archiveTip")}),m.action==="delete"&&e.jsx(X,{onConfirm:L,onCancel:()=>c({action:""}),title:t("admin.promotionCode.delete"),message:t("admin.promotionCode.deleteTip")})]})}function xe(o){if((!o.couponId||o.couponId==="")&&(!o.promotionCodeId||o.promotionCodeId===""))throw new Error("Either couponId or promotionCodeId must be provided")}const be=(o,h,S,t="coupon")=>{const s=new URLSearchParams({page:h.page.toString(),pageSize:h.pageSize.toString()});s.append("type",S);const a=t==="coupon"?`/api/coupons/${o}/redemptions`:`/api/promotion-codes/${o}/redemptions`;return k.get(`${a}?${s}`).then(p=>p.data)};function ke({couponId:o="",promotionCodeId:h=""}){xe({couponId:o,promotionCodeId:h});const{t}=I(),s=_e(),[a,p]=F.useState(0),[m,c]=F.useState({page:0,pageSize:10}),[w,L]=F.useState({page:0,pageSize:10}),C=o&&o!==""?o:h,P=o&&o!==""?"coupon":"promotion-code",b=a===0?m:w,D=a===0?"customer":"subscription",{data:d={customers:[],subscriptions:[],count:0},loading:n}=ae(()=>be(C,{page:b.page+1,pageSize:b.pageSize},D,P),{refreshDeps:[C,b.page,b.pageSize,a]}),_=(g,u)=>{p(u),u===0?c({page:0,pageSize:10}):L({page:0,pageSize:10})},x=({page:g,rowsPerPage:u})=>{c({page:g,pageSize:u})},M=({page:g,rowsPerPage:u})=>{L({page:g,pageSize:u})},U=(()=>{const g=[{label:t("common.name"),name:"name",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r];return e.jsx(oe,{customer:l,size:"small"})}}},{label:t("common.email"),name:"email",options:{customBodyRenderLite:(u,r)=>d.customers?.[r]?.email||"—"}},{label:t("admin.coupon.usageStats"),name:"usage_stats",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsx(f,{variant:"body2",children:i.total_discount_records}):"—"}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_codes",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r],i=l?.coupon_usage_stats?.promotion_codes_used||[],z=l?.discount_records||[];if(i.length===0)return"—";const R=new Map;return z.forEach(y=>{if(y.promotion_code){const j=y.promotion_code.id||y.promotion_code.code;R.set(j,(R.get(j)||0)+1)}}),e.jsx(v,{sx:{display:"flex",flexWrap:"wrap",gap:.5,maxWidth:"200px"},children:i.map(y=>{const j=R.get(y.id||y.code)||0;return e.jsx(K,{label:`${y.code} (${j})`,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${y.id}`),sx:{cursor:"pointer","&:hover":{backgroundColor:"action.hover"}}},`${y.id||y.code}`)})})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{display:"inline-flex"},children:[y>0&&"、",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.usagePeriod"),name:"usage_period",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.firstUsed"),": ",A(i.first_used)]}),i.first_used!==i.last_used&&e.jsxs(f,{variant:"body2",sx:{color:"text.secondary"},children:[t("admin.coupon.lastUsed"),": ",A(i.last_used)]})]}):"—"}}}),g})(),E=(()=>{const g=[{label:t("admin.subscription.product"),name:"id",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(pe,{subscription:l})})}}},{label:t("common.status"),name:"status",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(fe,{subscription:l})})}}},{label:t("common.customer"),name:"customer_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.customer;return e.jsx(oe,{customer:i,size:"small"})}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_code_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.promotion_code;return i?e.jsx(v,{children:e.jsx(K,{label:i.code,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${i.id}`),sx:{cursor:"pointer",mb:.5,"&:hover":{backgroundColor:"action.hover"}}})}):e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.directCouponUsage")})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",sx:{color:"text.lighter"},children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{lineHeight:1.2},children:[y>0&&", ",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.discountInfo"),name:"discount_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info;if(!i)return e.jsx(f,{variant:"body2",children:"—"});const z=i.coupon_info;return e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.discountPeriod"),": ",A(i.discount_start*1e3),i.discount_end&&` - ${A(i.discount_end*1e3)}`]}),e.jsxs(f,{variant:"caption",sx:{color:"text.secondary"},children:[t("admin.coupon.duration"),":"," ",t(`admin.coupon.couponTermsDuration.${z.duration}`,{months:z.duration_in_months})]})]})}}},{label:t("common.created"),name:"created_at",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return A(l?.created_at)}}}),g})();return e.jsxs(v,{children:[e.jsxs(ie,{value:a,onChange:_,sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(G,{label:t("admin.coupon.customers")}),e.jsx(G,{label:t("admin.coupon.subscriptions")})]}),a===0&&e.jsx(v,{sx:{mt:2},children:d.customers?.length>0?e.jsx(J,{data:d.customers,columns:U,loading:n,toolbar:!1,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:m.page,rowsPerPage:m.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:x}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersRedeem")})]})}),a===1&&e.jsx(v,{children:d.subscriptions?.length>0?e.jsx(J,{data:d.subscriptions,columns:E,loading:n,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:w.page,rowsPerPage:w.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:M}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsRedeem")})]})})]})}const ge=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1.5,2),backgroundColor:o.palette.grey[50],borderRadius:o.shape.borderRadius,marginBottom:o.spacing(1),"&:last-child":{marginBottom:0}})),he=O(f)(({theme:o})=>({fontWeight:500,color:o.palette.text.primary,textTransform:"uppercase",fontSize:"0.875rem"})),ye=O(f)(({theme:o})=>({color:o.palette.text.secondary,fontSize:"0.875rem",fontFamily:"monospace"})),ve=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1,2),marginBottom:o.spacing(1),borderBottom:`1px solid ${o.palette.divider}`})),te=O(f)(({theme:o})=>({fontWeight:600,color:o.palette.text.primary,fontSize:"0.75rem",letterSpacing:"0.5px"}));function Oe({currencyOptions:o,type:h="coupon"}){const{t:S}=I(),{settings:t}=se();if(!o||Object.keys(o).length===0)return null;const s=Object.entries(o);return e.jsxs(v,{children:[e.jsxs(ve,{children:[e.jsx(te,{children:S("admin.coupon.currency")}),e.jsx(te,{children:S(h==="coupon"?"admin.coupon.discountAmount":"admin.coupon.minimumAmount")})]}),e.jsx(q,{children:s.map(([a,p])=>{const m=N(t.paymentMethods,a)||{symbol:a.toUpperCase(),name:a.toUpperCase(),decimal:18};let c;return typeof p=="string"?c=$(p,m.decimal):typeof p=="number"?c=p.toLocaleString():typeof p=="object"&&p!==null?"minimum_amount"in p?c=$(p.minimum_amount,m.decimal):"amount_off"in p?c=$(p.amount_off,m.decimal):c="0":c="0",e.jsxs(ge,{children:[e.jsx(he,{children:m.symbol}),e.jsx(ye,{children:c})]},a)})})]})}export{ke as A,Oe as C,$e as P,Ae as a};
1
+ import{r as F,j as e,B as v,q as f,a3 as q,x as Y,w as ne,aN as ie,aM as K,a7 as Z,bf as O}from"./vendor-mui-BXZut9Pz.js";import{V as H,H as $,$ as re,Z as B,Y as ce,P as ae}from"./vendor-blocklet-B67R14so.js";import{a as se,h as ue,Y as N,F as me,e as k,b8 as W,k as V,I as G,T as J,v as Q,j as A}from"./index-B4yaPb7B.js";import{D as X,P as de}from"./index-oy7LrXGT.js";import{A as le}from"./actions-BEUwbsq1.js";import{L as ee}from"./link-DMWJcQvZ.js";import{C as oe}from"./link-DsltSF2Q.js";import{S as pe}from"./description-BHxdy5I3.js";import{S as fe}from"./status-3Swm2gK5.js";import{a as _e}from"./vendor-react-BPknnnEA.js";function Ae({open:o,onClose:h,onSubmit:S=()=>{},couponId:t,promotionCode:s=null,isEditing:a=!1,availableCurrencies:p=[]}){const{t:m}=H(),{settings:c}=se(),w=ue({mode:"onChange",defaultValues:X}),{handleSubmit:L,reset:C,formState:{isSubmitting:P}}=w;F.useEffect(()=>{if(o)if(a&&s){const n={},_=s.restrictions?.minimum_amount_currency?N(c.paymentMethods,s.restrictions.minimum_amount_currency):null,x=s.restrictions?.minimum_amount?parseFloat($(s.restrictions.minimum_amount,_?.decimal||0)):void 0;let M=!1;if(s.restrictions?.currency_options){const I=Object.entries(s.restrictions.currency_options);M=I.length>0,I.forEach(([U,T])=>{const E=N(c.paymentMethods,U);let g=0;if(T&&typeof T=="object"&&"minimum_amount"in T){const u=T.minimum_amount;E&&u?g=parseFloat($(u||"0",E.decimal)):g=u||0}n[U]={minimum_amount:g}})}C({code:s.code||"",active:s.active??!0,max_redemptions:s.max_redemptions||void 0,description:s.description||"",expires_at:s.expires_at?new Date(s.expires_at*1e3).toISOString().slice(0,16):"",verification_type:s.verification_type||"code",limit_number_redemptions:!!s.max_redemptions,add_expiration_date:!!s.expires_at,restrictions:{first_time_transaction:s.restrictions?.first_time_transaction||!1,require_minimum_amount:M,minimum_amount:x,minimum_amount_currency:_?.id,currency_options:n},customer_dids:s.customer_dids||[],nft_addresses:s.nft_config?.addresses||[],nft_tags:s.nft_config?.tags||[],trusted_issuers:s.nft_config?.trusted_issuers||[],trusted_parents:s.nft_config?.trusted_parents||[],min_balance:s.nft_config?.min_balance||1,vc_roles:s.vc_config?.roles||[],vc_trusted_issuers:s.vc_config?.trusted_issuers||[]})}else C(X)},[o,a,s,C,c.paymentMethods]);const b=async n=>{try{const _={active:n.active,verification_type:n.verification_type,restrictions:n.restrictions,description:n.description,metadata:{}};a||(_.coupon_id=t),n.code&&n.code.trim()&&(_.code=n.code),n.limit_number_redemptions&&n.max_redemptions&&(_.max_redemptions=n.max_redemptions),n.expires_at&&(_.expires_at=Math.floor(new Date(n.expires_at).getTime()/1e3)),n.verification_type==="nft"?_.nft_config={addresses:n.nft_addresses?.filter(x=>x.trim())||[],tags:n.nft_tags?.filter(x=>x.trim())||[],trusted_issuers:n.trusted_issuers?.filter(x=>x.trim())||[],trusted_parents:n.trusted_parents?.filter(x=>x.trim())||[],min_balance:n.min_balance||1}:n.verification_type==="vc"?_.vc_config={roles:n.vc_roles?.filter(x=>x.trim())||[],trusted_issuers:n.vc_trusted_issuers?.filter(x=>x.trim())||[]}:n.verification_type==="user_restricted"&&(_.customer_dids=n.customer_dids?.filter(x=>x.trim())||[]),a&&s?(await k.put(`/api/promotion-codes/${s.id}`,_),B.success(m("common.saved")),W("promotion-code.updated")):(await k.post("/api/promotion-codes",_),B.success(m("admin.coupon.saved")),W("promotion-code.created")),S&&S(),h()}catch(_){console.error(_),B.error(V(_))}},D=()=>{C(),h()},d=m(a?"admin.promotionCode.edit":"admin.coupon.createPromotionCode");return e.jsx(re,{open:o,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:D,showCloseButton:!1,title:d,actions:e.jsxs(q,{direction:"row",children:[e.jsx(Y,{size:"small",sx:{mr:2},onClick:D,disabled:P,children:m("common.cancel")}),e.jsxs(Y,{variant:"contained",color:"primary",size:"small",disabled:P,onClick:L(b),children:[P&&e.jsx(ne,{size:16,sx:{mr:1}}),m(a?"common.save":"admin.coupon.createPromotionCode")]})]}),children:e.jsx(me,{...w,children:e.jsxs(v,{sx:{display:"flex",flexDirection:"column",gap:3},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:m("admin.coupon.promotionCodeDescription")}),e.jsx(de,{showCodeInput:!0,showExpandedOptions:!0,availableCurrencies:p})]})})})}function $e({data:o,onChange:h,variant:S="compact"}){const{t}=H(),s=!o.locked&&o.active,a=!o.locked,p=o.active,[m,c]=ce({action:"",loading:!1}),w=async()=>{try{c({loading:!0}),await k.put(`/api/promotion-codes/${o.id}/archive`).then(b=>b.data),B.success(t("common.saved")),W("promotion-code.updated"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},L=async()=>{try{c({loading:!0}),await k.delete(`/api/promotion-codes/${o.id}`).then(b=>b.data),B.success(t("common.removed")),W("promotion-code.deleted"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},C=()=>{c({action:"edit"}),h("edit",o)},P=[{label:t("admin.promotionCode.edit"),handler:C,color:s?"text.primary":"text.disabled",disabled:!s},{label:t("admin.promotionCode.archive"),handler:()=>c({action:"archive"}),color:p?"text.primary":"text.disabled",disabled:!p},{label:t("admin.promotionCode.delete"),handler:()=>c({action:"delete"}),color:a?"error.main":"text.disabled",disabled:!a}];return e.jsxs(e.Fragment,{children:[e.jsx(le,{variant:S,actions:P}),m.action==="archive"&&e.jsx(G,{onConfirm:w,onCancel:()=>c({action:""}),title:t("admin.promotionCode.archive"),message:t("admin.promotionCode.archiveTip")}),m.action==="delete"&&e.jsx(G,{onConfirm:L,onCancel:()=>c({action:""}),title:t("admin.promotionCode.delete"),message:t("admin.promotionCode.deleteTip")})]})}function xe(o){if((!o.couponId||o.couponId==="")&&(!o.promotionCodeId||o.promotionCodeId===""))throw new Error("Either couponId or promotionCodeId must be provided")}const be=(o,h,S,t="coupon")=>{const s=new URLSearchParams({page:h.page.toString(),pageSize:h.pageSize.toString()});s.append("type",S);const a=t==="coupon"?`/api/coupons/${o}/redemptions`:`/api/promotion-codes/${o}/redemptions`;return k.get(`${a}?${s}`).then(p=>p.data)};function ke({couponId:o="",promotionCodeId:h=""}){xe({couponId:o,promotionCodeId:h});const{t}=H(),s=_e(),[a,p]=F.useState(0),[m,c]=F.useState({page:0,pageSize:10}),[w,L]=F.useState({page:0,pageSize:10}),C=o&&o!==""?o:h,P=o&&o!==""?"coupon":"promotion-code",b=a===0?m:w,D=a===0?"customer":"subscription",{data:d={customers:[],subscriptions:[],count:0},loading:n}=ae(()=>be(C,{page:b.page+1,pageSize:b.pageSize},D,P),{refreshDeps:[C,b.page,b.pageSize,a]}),_=(g,u)=>{p(u),u===0?c({page:0,pageSize:10}):L({page:0,pageSize:10})},x=({page:g,rowsPerPage:u})=>{c({page:g,pageSize:u})},M=({page:g,rowsPerPage:u})=>{L({page:g,pageSize:u})},U=(()=>{const g=[{label:t("common.name"),name:"name",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r];return e.jsx(oe,{customer:l,size:"small"})}}},{label:t("common.email"),name:"email",options:{customBodyRenderLite:(u,r)=>d.customers?.[r]?.email||"—"}},{label:t("admin.coupon.usageStats"),name:"usage_stats",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsx(f,{variant:"body2",children:i.total_discount_records}):"—"}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_codes",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r],i=l?.coupon_usage_stats?.promotion_codes_used||[],z=l?.discount_records||[];if(i.length===0)return"—";const R=new Map;return z.forEach(y=>{if(y.promotion_code){const j=y.promotion_code.id||y.promotion_code.code;R.set(j,(R.get(j)||0)+1)}}),e.jsx(v,{sx:{display:"flex",flexWrap:"wrap",gap:.5,maxWidth:"200px"},children:i.map(y=>{const j=R.get(y.id||y.code)||0;return e.jsx(Z,{label:`${y.code} (${j})`,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${y.id}`),sx:{cursor:"pointer","&:hover":{backgroundColor:"action.hover"}}},`${y.id||y.code}`)})})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{display:"inline-flex"},children:[y>0&&"、",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.usagePeriod"),name:"usage_period",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.firstUsed"),": ",A(i.first_used)]}),i.first_used!==i.last_used&&e.jsxs(f,{variant:"body2",sx:{color:"text.secondary"},children:[t("admin.coupon.lastUsed"),": ",A(i.last_used)]})]}):"—"}}}),g})(),E=(()=>{const g=[{label:t("admin.subscription.product"),name:"id",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(pe,{subscription:l})})}}},{label:t("common.status"),name:"status",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(fe,{subscription:l})})}}},{label:t("common.customer"),name:"customer_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.customer;return e.jsx(oe,{customer:i,size:"small"})}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_code_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.promotion_code;return i?e.jsx(v,{children:e.jsx(Z,{label:i.code,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${i.id}`),sx:{cursor:"pointer",mb:.5,"&:hover":{backgroundColor:"action.hover"}}})}):e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.directCouponUsage")})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",sx:{color:"text.lighter"},children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{lineHeight:1.2},children:[y>0&&", ",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.discountInfo"),name:"discount_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info;if(!i)return e.jsx(f,{variant:"body2",children:"—"});const z=i.coupon_info;return e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.discountPeriod"),": ",A(i.discount_start*1e3),i.discount_end&&` - ${A(i.discount_end*1e3)}`]}),e.jsxs(f,{variant:"caption",sx:{color:"text.secondary"},children:[t("admin.coupon.duration"),":"," ",t(`admin.coupon.couponTermsDuration.${z.duration}`,{months:z.duration_in_months})]})]})}}},{label:t("common.created"),name:"created_at",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return A(l?.created_at)}}}),g})();return e.jsxs(v,{children:[e.jsxs(ie,{value:a,onChange:_,sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(K,{label:t("admin.coupon.customers")}),e.jsx(K,{label:t("admin.coupon.subscriptions")})]}),a===0&&e.jsx(v,{sx:{mt:2},children:d.customers?.length>0?e.jsx(J,{data:d.customers,columns:U,loading:n,toolbar:!1,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:m.page,rowsPerPage:m.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:x}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersRedeem")})]})}),a===1&&e.jsx(v,{children:d.subscriptions?.length>0?e.jsx(J,{data:d.subscriptions,columns:E,loading:n,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:w.page,rowsPerPage:w.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:M}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsRedeem")})]})})]})}const ge=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1.5,2),backgroundColor:o.palette.grey[50],borderRadius:o.shape.borderRadius,marginBottom:o.spacing(1),"&:last-child":{marginBottom:0}})),he=O(f)(({theme:o})=>({fontWeight:500,color:o.palette.text.primary,textTransform:"uppercase",fontSize:"0.875rem"})),ye=O(f)(({theme:o})=>({color:o.palette.text.secondary,fontSize:"0.875rem",fontFamily:"monospace"})),ve=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1,2),marginBottom:o.spacing(1),borderBottom:`1px solid ${o.palette.divider}`})),te=O(f)(({theme:o})=>({fontWeight:600,color:o.palette.text.primary,fontSize:"0.75rem",letterSpacing:"0.5px"}));function Oe({currencyOptions:o,type:h="coupon"}){const{t:S}=H(),{settings:t}=se();if(!o||Object.keys(o).length===0)return null;const s=Object.entries(o);return e.jsxs(v,{children:[e.jsxs(ve,{children:[e.jsx(te,{children:S("admin.coupon.currency")}),e.jsx(te,{children:S(h==="coupon"?"admin.coupon.discountAmount":"admin.coupon.minimumAmount")})]}),e.jsx(q,{children:s.map(([a,p])=>{const m=N(t.paymentMethods,a)||{symbol:a.toUpperCase(),name:a.toUpperCase(),decimal:18};let c;return typeof p=="string"?c=$(p,m.decimal):typeof p=="number"?c=p.toLocaleString():typeof p=="object"&&p!==null?"minimum_amount"in p?c=$(p.minimum_amount,m.decimal):"amount_off"in p?c=$(p.amount_off,m.decimal):c="0":c="0",e.jsxs(ge,{children:[e.jsx(he,{children:m.symbol}),e.jsx(ye,{children:c})]},a)})})]})}export{ke as A,Oe as C,$e as P,Ae as a};
@@ -1 +1 @@
1
- import{r as x,j as n,q as l,ch as D,aT as G,ad as T,bN as H,a3 as $,bH as I}from"./vendor-mui-BXZut9Pz.js";import{V as L}from"./vendor-blocklet-D_i_QeSo.js";import{a as P}from"./index-DgSc1Qy8.js";import{C as V}from"./currency-GstdXsJf.js";function _({mode:i,hasSelected:d,onSelect:b,value:r,width:z="100%",disabled:h=!1,selectSX:k={},currencyFilter:v=()=>!0,hideMethod:t=!1,includeAllOption:j=!1,allOption:o={value:"all",label:"All"},selectedSx:A={}}){const{t:E}=L(),{settings:g}=P(),[C,u]=x.useState(i),c=x.useMemo(()=>(g.paymentMethods||[]).map(e=>({method:e,currencies:(e.payment_currencies||[]).map(s=>({...s,method:e}))})),[g.paymentMethods]),f=x.useMemo(()=>c.flatMap(e=>e.currencies),[c]);x.useEffect(()=>{if(r&&i==="selected"&&f.length>0){const e=f.find(s=>s.id===r);if(e&&!d(e)){const s=setTimeout(()=>{b(r)},0);return()=>clearTimeout(s)}}},[r,i,f,d]);const W=e=>{h||(u(i),b(e.target.value))},p=f.find(e=>e.id===r),a=c.find(e=>e.currencies.some(s=>s.id===r))?.method,S=x.useMemo(()=>c.map(e=>({method:e.method,currencies:e.currencies.filter(s=>v(s)&&!d(s))})).filter(e=>e.currencies.length>0),[c,d]),y=S.length>0&&!h;if(C==="selected"){const e=j&&r===o.value;let s="";return e?s=o.label:p?.symbol?s=t?p.symbol:`${p.symbol} (${a?.name||""})`:!t&&a?.name&&(s=`(${a.name})`),n.jsxs(l,{onClick:()=>{y&&u("selecting")},sx:{cursor:y?"pointer":"default",display:"inline-flex",minWidth:"120px",justifyContent:"flex-end",textAlign:"right",width:"100%",...A},children:[s,y&&n.jsx(D,{sx:{color:"text.secondary",fontSize:21}})]})}return y?C==="selecting"?n.jsxs(G,{size:"small",value:r,renderValue:()=>{if(j&&r===o.value)return n.jsx(l,{variant:"body1",sx:{display:"inline-flex",fontSize:"12px",color:"text.secondary"},children:o.label});const e=p?.symbol||"",s=!t&&a?.name?` (${a.name})`:"";return n.jsx(l,{variant:"body1",sx:{display:"inline-flex",fontSize:"12px",color:"text.secondary"},children:`${e}${s}`.trim()})},onChange:W,open:!0,sx:{width:z,...k},disabled:h,onClose:()=>u(i),children:[j?n.jsx(T,{value:o.value,children:n.jsx(l,{sx:{fontWeight:"bold"},children:o.label})}):null,S.flatMap(e=>{const s=t?null:n.jsx(H,{sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:"2.1875rem"},children:e.method.name},e.method.id),w=e.currencies.map(m=>n.jsx(T,{sx:{pl:3},value:m.id,children:n.jsxs($,{direction:"row",sx:{width:"100%",justifyContent:"space-between",gap:2},children:[t?null:n.jsx(V,{logo:m.logo,name:m.name}),n.jsx(l,{sx:{fontWeight:t?"normal":"bold"},children:m.symbol})]})},m.id));return s?[s,...w]:w})]}):n.jsx("span",{children:n.jsxs($,{direction:"row",onClick:()=>u("selecting"),sx:{alignItems:"center",cursor:"pointer",display:"inline-flex"},children:[n.jsx(I,{color:"primary"}),n.jsx(l,{color:"primary",children:E("admin.price.currency.add")})]})}):null}export{_ as C};
1
+ import{r as x,j as n,q as l,ch as D,aT as G,ad as T,bN as H,a3 as $,bH as I}from"./vendor-mui-BXZut9Pz.js";import{V as L}from"./vendor-blocklet-B67R14so.js";import{a as P}from"./index-B4yaPb7B.js";import{C as V}from"./currency-GstdXsJf.js";function _({mode:i,hasSelected:d,onSelect:b,value:r,width:z="100%",disabled:h=!1,selectSX:k={},currencyFilter:v=()=>!0,hideMethod:t=!1,includeAllOption:j=!1,allOption:o={value:"all",label:"All"},selectedSx:A={}}){const{t:E}=L(),{settings:g}=P(),[C,u]=x.useState(i),c=x.useMemo(()=>(g.paymentMethods||[]).map(e=>({method:e,currencies:(e.payment_currencies||[]).map(s=>({...s,method:e}))})),[g.paymentMethods]),f=x.useMemo(()=>c.flatMap(e=>e.currencies),[c]);x.useEffect(()=>{if(r&&i==="selected"&&f.length>0){const e=f.find(s=>s.id===r);if(e&&!d(e)){const s=setTimeout(()=>{b(r)},0);return()=>clearTimeout(s)}}},[r,i,f,d]);const W=e=>{h||(u(i),b(e.target.value))},p=f.find(e=>e.id===r),a=c.find(e=>e.currencies.some(s=>s.id===r))?.method,S=x.useMemo(()=>c.map(e=>({method:e.method,currencies:e.currencies.filter(s=>v(s)&&!d(s))})).filter(e=>e.currencies.length>0),[c,d]),y=S.length>0&&!h;if(C==="selected"){const e=j&&r===o.value;let s="";return e?s=o.label:p?.symbol?s=t?p.symbol:`${p.symbol} (${a?.name||""})`:!t&&a?.name&&(s=`(${a.name})`),n.jsxs(l,{onClick:()=>{y&&u("selecting")},sx:{cursor:y?"pointer":"default",display:"inline-flex",minWidth:"120px",justifyContent:"flex-end",textAlign:"right",width:"100%",...A},children:[s,y&&n.jsx(D,{sx:{color:"text.secondary",fontSize:21}})]})}return y?C==="selecting"?n.jsxs(G,{size:"small",value:r,renderValue:()=>{if(j&&r===o.value)return n.jsx(l,{variant:"body1",sx:{display:"inline-flex",fontSize:"12px",color:"text.secondary"},children:o.label});const e=p?.symbol||"",s=!t&&a?.name?` (${a.name})`:"";return n.jsx(l,{variant:"body1",sx:{display:"inline-flex",fontSize:"12px",color:"text.secondary"},children:`${e}${s}`.trim()})},onChange:W,open:!0,sx:{width:z,...k},disabled:h,onClose:()=>u(i),children:[j?n.jsx(T,{value:o.value,children:n.jsx(l,{sx:{fontWeight:"bold"},children:o.label})}):null,S.flatMap(e=>{const s=t?null:n.jsx(H,{sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:"2.1875rem"},children:e.method.name},e.method.id),w=e.currencies.map(m=>n.jsx(T,{sx:{pl:3},value:m.id,children:n.jsxs($,{direction:"row",sx:{width:"100%",justifyContent:"space-between",gap:2},children:[t?null:n.jsx(V,{logo:m.logo,name:m.name}),n.jsx(l,{sx:{fontWeight:t?"normal":"bold"},children:m.symbol})]})},m.id));return s?[s,...w]:w})]}):n.jsx("span",{children:n.jsxs($,{direction:"row",onClick:()=>u("selecting"),sx:{alignItems:"center",cursor:"pointer",display:"inline-flex"},children:[n.jsx(I,{color:"primary"}),n.jsx(l,{color:"primary",children:E("admin.price.currency.add")})]})}):null}export{_ as C};
@@ -1 +1 @@
1
- import"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-D_i_QeSo.js";import"./index-DgSc1Qy8.js";const d=(i,f,{t:m,separator:c=" "})=>{const h=(r,o)=>`${r||0} ${m(`common.${o}${r>1?"s":""}`).toLowerCase()}`,s=(r,o)=>{switch(o){case"hour":{if(r<24)return[["hour",r]];if(r<48)return[["day",Math.floor(r/24)],["hour",r%24]];const t=Math.floor(r/24);return s(t,"day")}case"day":{if(r<7)return[["day",r]];if(r<14)return[["week",Math.floor(r/7)],["day",r%7]];if(r<30)return r%7===0?[["week",r/7]]:[["day",r]];const t=Math.floor(r/365),e=r%365,n=Math.floor(e/30);return t>0?n>0?[["year",t],["month",n]]:[["year",t]]:n>0?[["month",n],["week",Math.floor(e%30/7)]]:[["week",Math.floor(r/7)]]}case"week":{if(r<4)return[["week",r]];if(r<8)return[["month",Math.floor(r/4)],["week",r%4]];const t=Math.floor(r/4);return s(t,"month")}case"month":{const t=Math.floor(r/12),e=r%12;return t>0?e>0?[["year",t],["month",e]]:[["year",t]]:[["month",r]]}case"year":return[["year",r]];default:return[[o,r]]}},u=s(i,f).filter(([,r])=>r>0);return u.length===0?h(0,f):u.map(([r,o])=>h(o,r)).join(c)};export{d as f};
1
+ import"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-B67R14so.js";import"./index-B4yaPb7B.js";const d=(i,f,{t:m,separator:c=" "})=>{const h=(r,o)=>`${r||0} ${m(`common.${o}${r>1?"s":""}`).toLowerCase()}`,s=(r,o)=>{switch(o){case"hour":{if(r<24)return[["hour",r]];if(r<48)return[["day",Math.floor(r/24)],["hour",r%24]];const t=Math.floor(r/24);return s(t,"day")}case"day":{if(r<7)return[["day",r]];if(r<14)return[["week",Math.floor(r/7)],["day",r%7]];if(r<30)return r%7===0?[["week",r/7]]:[["day",r]];const t=Math.floor(r/365),e=r%365,n=Math.floor(e/30);return t>0?n>0?[["year",t],["month",n]]:[["year",t]]:n>0?[["month",n],["week",Math.floor(e%30/7)]]:[["week",Math.floor(r/7)]]}case"week":{if(r<4)return[["week",r]];if(r<8)return[["month",Math.floor(r/4)],["week",r%4]];const t=Math.floor(r/4);return s(t,"month")}case"month":{const t=Math.floor(r/12),e=r%12;return t>0?e>0?[["year",t],["month",e]]:[["year",t]]:[["month",r]]}case"year":return[["year",r]];default:return[[o,r]]}},u=s(i,f).filter(([,r])=>r>0);return u.length===0?h(0,f):u.map(([r,o])=>h(o,r)).join(c)};export{d as f};
@@ -1 +1 @@
1
- import{j as s,a3 as d,q as r,O as l,be as x}from"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-D_i_QeSo.js";import{d as p,aM as o,J as n}from"./index-DgSc1Qy8.js";function f({subscription:t,variant:e="body1",hideSubscription:a=!1,maxLength:i=80}){const{isMobile:c}=p();return t.description?s.jsxs(d,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[s.jsx(r,{variant:e,className:"subscription-description",children:s.jsx(o,{text:t.description,maxLength:i,useWidth:!0})}),!a&&!c&&s.jsx(l,{title:n(t.items),children:s.jsx(x,{sx:{color:"text.secondary"},fontSize:"small"})})]}):s.jsx(r,{variant:e,children:s.jsx(o,{text:n(t.items),maxLength:i,useWidth:!0})})}export{f as S};
1
+ import{j as s,a3 as d,q as r,O as l,be as x}from"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-B67R14so.js";import{d as p,aM as o,J as n}from"./index-B4yaPb7B.js";function f({subscription:t,variant:e="body1",hideSubscription:a=!1,maxLength:i=80}){const{isMobile:c}=p();return t.description?s.jsxs(d,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[s.jsx(r,{variant:e,className:"subscription-description",children:s.jsx(o,{text:t.description,maxLength:i,useWidth:!0})}),!a&&!c&&s.jsx(l,{title:n(t.items),children:s.jsx(x,{sx:{color:"text.secondary"},fontSize:"small"})})]}):s.jsx(r,{variant:e,children:s.jsx(o,{text:n(t.items),maxLength:i,useWidth:!0})})}export{f as S};
@@ -1 +1 @@
1
- import{j as e,w as z,A as N,B as o,a3 as m,bv as P,q as x,Y as v,x as b,O as q,cA as H,bf as J}from"./vendor-mui-BXZut9Pz.js";import{V as U,X as V,O as Y,Y as f}from"./vendor-blocklet-D_i_QeSo.js";import{d as G,h as X,ac as D,j as M,F as K,e as w,b8 as S,k as A}from"./index-DgSc1Qy8.js";import{C as Q}from"./copyable-DpX04wZz.js";import{I as g}from"./info-metric-CNse3r66.js";import{I as d}from"./info-row-DOK2whMn.js";import{I as Z}from"./info-row-group-BeUhWnnY.js";import{I as ee}from"./list-CNmzJKIQ.js";import{M as te}from"./editor-BF5I0siU.js";import{M as ae}from"./list-C521zE_7.js";import{S as R}from"./header-ivXuPt06.js";import{g as se,a as ie,T as ne}from"./tax-utils-DqNX34-r.js";import{T as oe}from"./index-Br7_mvEw.js";import{D as re}from"./drawer-form-Cl0T1Yyt.js";import{g as le}from"./util-mDHAL0lx.js";import{a as de}from"./vendor-react-BPknnnEA.js";import"./table-BRU4Enia.js";import"./cache-state-lld4zuDg.js";import"./link-3eeclTeS.js";import"./filter-toolbar-BydfQ-79.js";import"./lodash-B4Ozcv0x.js";import"./product-select-0ScZE2e8.js";import"./info-card-C1yxhxJG.js";import"./action-B_DQJlip.js";import"./actions-jxGAdGfb.js";import"./click-boundary-y8dVA_tr.js";import"./form-BGm5NPDn.js";import"./tax-code-select-CWhIIiXi.js";import"./collapse-BvbJGg1V.js";import"./collapse-CSrlJ0eG.js";const ce=r=>w.get(`/api/tax-rates/${r}`).then(t=>t.data),xe=(r={})=>Object.entries(r).map(([t,n])=>({key:t,value:typeof n=="object"?JSON.stringify(n,null,2):String(n)})),me=r=>r.reduce((t,n)=>{if(!n.key||!n.value)return t;try{t[n.key]=JSON.parse(n.value)}catch{t[n.key]=n.value}return t},{});function He({id:r}){const{t,locale:n}=U(),{isMobile:O}=G(),W=de(),[c,l]=V({editing:{metadata:!1,taxRate:!1},loading:{metadata:!1,taxRate:!1}}),j=X({defaultValues:{display_name:"",description:"",country:"",state:"",postal_code:"",tax_code:"",percentage:0,metadata:[{key:"",value:""}]}}),{data:a,loading:$,error:C,runAsync:h}=Y(()=>ce(r));if($&&!a)return e.jsx(z,{});if(C)return e.jsx(N,{severity:"error",children:C.message});if(!a)return null;const F=s=>{s==="delete"?W("/admin/tax/rates"):h()},I=()=>{l(s=>({editing:{...s.editing,metadata:!0}}))},B=()=>{j.reset({display_name:a.display_name,description:a.description||"",country:(a.country||"").toLowerCase(),state:a.state||"",postal_code:a.postal_code||"",tax_code:a.tax_code||"",percentage:a.percentage,metadata:xe(a.metadata||{})}),l(s=>({editing:{...s.editing,taxRate:!0}}))},E=async s=>{try{l(i=>({loading:{...i.loading,metadata:!0}})),await w.put(`/api/tax-rates/${r}`,s),f.success(t("common.saved")),S("tax-rate.updated"),h()}catch(i){console.error(i),f.error(A(i))}finally{l(i=>({loading:{...i.loading,metadata:!1}}))}},L=async s=>{try{l(y=>({loading:{...y.loading,taxRate:!0}}));const{metadata:i,...T}=s;await w.put(`/api/tax-rates/${r}`,{...T,percentage:Number(T.percentage),metadata:me(i||[])}),f.success(t("admin.taxRate.updated")),S("tax-rate.updated"),l(y=>({editing:{...y.editing,taxRate:!1}})),h()}catch(i){console.error(i),f.error(A(i))}finally{l(i=>({loading:{...i.loading,taxRate:!1}}))}},p=a.country?se(a.country):null,_=[a.state,a.postal_code].filter(Boolean),k=p?`${p.name}${_.length>0?` · ${_.join(" · ")}`:""}`:"—",u=a.tax_code?ie(a.tax_code,n):null;return e.jsxs(pe,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(o,{children:[!a.active&&e.jsx(N,{severity:"warning",sx:{mb:2},children:t("admin.taxRate.inactiveWarning")}),e.jsxs(m,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(m,{direction:"row",onClick:()=>le("/admin/tax/rates"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(P,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(x,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.taxRates")})]}),e.jsx(ne,{data:a,onChange:F})]}),e.jsxs(o,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(m,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(m,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(x,{variant:"h2",sx:{color:"text.primary"},children:a.display_name}),a.description&&e.jsx(x,{variant:"subtitle1",sx:{color:"text.lighter"},children:a.description})]})}),e.jsxs(m,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(g,{label:t("common.id"),value:e.jsx(Q,{text:r,style:{marginLeft:4}}),divider:!0}),e.jsx(g,{label:t("admin.taxRate.percentage"),value:`${a.percentage}%`,divider:!0}),e.jsx(g,{label:t("admin.taxRate.location"),value:p?e.jsxs(o,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(D,{iso2:a.country.toLowerCase(),style:{width:24}}),e.jsx(x,{variant:"body2",children:k})]}):k,divider:!0}),e.jsx(g,{label:t("common.createdAt"),value:M(a.created_at),divider:!0})]})]}),e.jsx(v,{})]}),e.jsxs(m,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".tax-column-1":{minWidth:{xs:"100%",lg:"600px"}},".tax-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(o,{className:"tax-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(o,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(R,{title:t("admin.details"),children:e.jsx(b,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:c.editing.taxRate,onClick:B,children:t("common.edit")})}),e.jsxs(Z,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(d,{label:t("admin.taxRate.displayName"),value:a.display_name}),e.jsx(d,{label:t("admin.taxRate.country"),value:p?e.jsxs(o,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(D,{iso2:a.country.toLowerCase(),style:{width:24}}),e.jsx(x,{variant:"body2",children:p.name})]}):"—"}),e.jsx(d,{label:t("admin.taxRate.state"),value:a.state||"—"}),e.jsx(d,{label:t("admin.taxRate.postalCode"),value:a.postal_code||"—"}),e.jsx(d,{label:t("admin.taxRate.percentage"),value:`${a.percentage}%`}),e.jsx(d,{label:t("admin.taxRate.taxCode"),value:u?e.jsx(q,{title:u.description,arrow:!0,placement:"top",children:e.jsxs(o,{children:[e.jsx(x,{variant:"body2",sx:{fontWeight:500},children:u.name}),e.jsx(x,{variant:"caption",sx:{color:"text.secondary"},children:u.id})]})}):a.tax_code||"—"}),e.jsx(d,{label:t("common.status"),value:a.active?t("common.active"):t("common.inactive")}),e.jsx(d,{label:t("common.updatedAt"),value:M(a.updated_at)})]})]}),e.jsx(v,{}),e.jsxs(o,{className:"section",children:[e.jsx(R,{title:t("admin.taxRate.associatedInvoices")}),e.jsx(o,{className:"section-body",children:e.jsx(ee,{features:{customer:!0,filter:!1,toolbar:!1},tax_rate_id:r,mode:"admin",status:""})})]})]}),O&&e.jsx(v,{}),e.jsx(o,{className:"tax-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(o,{className:"section",children:[e.jsx(R,{title:t("common.metadata.label"),children:e.jsx(b,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:c.editing.metadata,onClick:I,children:t("common.edit")})}),e.jsxs(o,{className:"section-body",children:[e.jsx(ae,{data:a.metadata||{},handleEditMetadata:I}),c.editing.metadata&&e.jsx(te,{data:a,loading:c.loading.metadata,onSave:E,onCancel:()=>l(s=>({editing:{...s.editing,metadata:!1}}))})]})]})})]}),c.editing.taxRate&&e.jsx(re,{icon:e.jsx(H,{}),text:t("admin.taxRate.edit"),open:c.editing.taxRate,onClose:()=>l(s=>({editing:{...s.editing,taxRate:!1}})),width:640,addons:e.jsx(b,{variant:"contained",size:"small",disabled:c.loading.taxRate,onClick:j.handleSubmit(L),children:t("common.save")}),children:e.jsx(K,{...j,children:e.jsx(oe,{})})})]})}const pe=J(m)``;export{He as default};
1
+ import{j as e,w as z,A as N,B as o,a3 as m,bv as P,q as x,Y as v,x as b,O as q,cA as H,bf as J}from"./vendor-mui-BXZut9Pz.js";import{V as U,Y as V,P as Y,Z as f}from"./vendor-blocklet-B67R14so.js";import{d as G,h as Z,ac as D,j as M,F as K,e as w,b8 as S,k as A}from"./index-B4yaPb7B.js";import{C as Q}from"./copyable-CprMHdhV.js";import{I as g}from"./info-metric-ukWq8INi.js";import{I as d}from"./info-row-CaPaNF4L.js";import{I as X}from"./info-row-group-Cxo-4Gk5.js";import{I as ee}from"./list-ZaBapEXW.js";import{M as te}from"./editor-vZvxDUTl.js";import{M as ae}from"./list-B2b-s8wM.js";import{S as R}from"./header-ivXuPt06.js";import{g as se,a as ie,T as ne}from"./tax-utils-B8J0Kfnz.js";import{T as oe}from"./index-C3AP4jq0.js";import{D as re}from"./drawer-form-CQjNFFWk.js";import{g as le}from"./util-B8B3fsMa.js";import{a as de}from"./vendor-react-BPknnnEA.js";import"./table-BN3WBnr3.js";import"./cache-state-lld4zuDg.js";import"./link-DsltSF2Q.js";import"./filter-toolbar-VvmMATj0.js";import"./lodash-B4Ozcv0x.js";import"./product-select-_72p-5lF.js";import"./info-card-C9dRgztS.js";import"./action-C2c0yWuW.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./form-CnrBCyTJ.js";import"./tax-code-select-j2arPbaE.js";import"./collapse-BvbJGg1V.js";import"./collapse-CSrlJ0eG.js";const ce=r=>w.get(`/api/tax-rates/${r}`).then(t=>t.data),xe=(r={})=>Object.entries(r).map(([t,n])=>({key:t,value:typeof n=="object"?JSON.stringify(n,null,2):String(n)})),me=r=>r.reduce((t,n)=>{if(!n.key||!n.value)return t;try{t[n.key]=JSON.parse(n.value)}catch{t[n.key]=n.value}return t},{});function He({id:r}){const{t,locale:n}=U(),{isMobile:O}=G(),W=de(),[c,l]=V({editing:{metadata:!1,taxRate:!1},loading:{metadata:!1,taxRate:!1}}),j=Z({defaultValues:{display_name:"",description:"",country:"",state:"",postal_code:"",tax_code:"",percentage:0,metadata:[{key:"",value:""}]}}),{data:a,loading:$,error:C,runAsync:h}=Y(()=>ce(r));if($&&!a)return e.jsx(z,{});if(C)return e.jsx(N,{severity:"error",children:C.message});if(!a)return null;const F=s=>{s==="delete"?W("/admin/tax/rates"):h()},I=()=>{l(s=>({editing:{...s.editing,metadata:!0}}))},B=()=>{j.reset({display_name:a.display_name,description:a.description||"",country:(a.country||"").toLowerCase(),state:a.state||"",postal_code:a.postal_code||"",tax_code:a.tax_code||"",percentage:a.percentage,metadata:xe(a.metadata||{})}),l(s=>({editing:{...s.editing,taxRate:!0}}))},E=async s=>{try{l(i=>({loading:{...i.loading,metadata:!0}})),await w.put(`/api/tax-rates/${r}`,s),f.success(t("common.saved")),S("tax-rate.updated"),h()}catch(i){console.error(i),f.error(A(i))}finally{l(i=>({loading:{...i.loading,metadata:!1}}))}},L=async s=>{try{l(y=>({loading:{...y.loading,taxRate:!0}}));const{metadata:i,...T}=s;await w.put(`/api/tax-rates/${r}`,{...T,percentage:Number(T.percentage),metadata:me(i||[])}),f.success(t("admin.taxRate.updated")),S("tax-rate.updated"),l(y=>({editing:{...y.editing,taxRate:!1}})),h()}catch(i){console.error(i),f.error(A(i))}finally{l(i=>({loading:{...i.loading,taxRate:!1}}))}},p=a.country?se(a.country):null,_=[a.state,a.postal_code].filter(Boolean),k=p?`${p.name}${_.length>0?` · ${_.join(" · ")}`:""}`:"—",u=a.tax_code?ie(a.tax_code,n):null;return e.jsxs(pe,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(o,{children:[!a.active&&e.jsx(N,{severity:"warning",sx:{mb:2},children:t("admin.taxRate.inactiveWarning")}),e.jsxs(m,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(m,{direction:"row",onClick:()=>le("/admin/tax/rates"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(P,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(x,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.taxRates")})]}),e.jsx(ne,{data:a,onChange:F})]}),e.jsxs(o,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(m,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(m,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(x,{variant:"h2",sx:{color:"text.primary"},children:a.display_name}),a.description&&e.jsx(x,{variant:"subtitle1",sx:{color:"text.lighter"},children:a.description})]})}),e.jsxs(m,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(g,{label:t("common.id"),value:e.jsx(Q,{text:r,style:{marginLeft:4}}),divider:!0}),e.jsx(g,{label:t("admin.taxRate.percentage"),value:`${a.percentage}%`,divider:!0}),e.jsx(g,{label:t("admin.taxRate.location"),value:p?e.jsxs(o,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(D,{iso2:a.country.toLowerCase(),style:{width:24}}),e.jsx(x,{variant:"body2",children:k})]}):k,divider:!0}),e.jsx(g,{label:t("common.createdAt"),value:M(a.created_at),divider:!0})]})]}),e.jsx(v,{})]}),e.jsxs(m,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".tax-column-1":{minWidth:{xs:"100%",lg:"600px"}},".tax-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(o,{className:"tax-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(o,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(R,{title:t("admin.details"),children:e.jsx(b,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:c.editing.taxRate,onClick:B,children:t("common.edit")})}),e.jsxs(X,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(d,{label:t("admin.taxRate.displayName"),value:a.display_name}),e.jsx(d,{label:t("admin.taxRate.country"),value:p?e.jsxs(o,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(D,{iso2:a.country.toLowerCase(),style:{width:24}}),e.jsx(x,{variant:"body2",children:p.name})]}):"—"}),e.jsx(d,{label:t("admin.taxRate.state"),value:a.state||"—"}),e.jsx(d,{label:t("admin.taxRate.postalCode"),value:a.postal_code||"—"}),e.jsx(d,{label:t("admin.taxRate.percentage"),value:`${a.percentage}%`}),e.jsx(d,{label:t("admin.taxRate.taxCode"),value:u?e.jsx(q,{title:u.description,arrow:!0,placement:"top",children:e.jsxs(o,{children:[e.jsx(x,{variant:"body2",sx:{fontWeight:500},children:u.name}),e.jsx(x,{variant:"caption",sx:{color:"text.secondary"},children:u.id})]})}):a.tax_code||"—"}),e.jsx(d,{label:t("common.status"),value:a.active?t("common.active"):t("common.inactive")}),e.jsx(d,{label:t("common.updatedAt"),value:M(a.updated_at)})]})]}),e.jsx(v,{}),e.jsxs(o,{className:"section",children:[e.jsx(R,{title:t("admin.taxRate.associatedInvoices")}),e.jsx(o,{className:"section-body",children:e.jsx(ee,{features:{customer:!0,filter:!1,toolbar:!1},tax_rate_id:r,mode:"admin",status:""})})]})]}),O&&e.jsx(v,{}),e.jsx(o,{className:"tax-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(o,{className:"section",children:[e.jsx(R,{title:t("common.metadata.label"),children:e.jsx(b,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:c.editing.metadata,onClick:I,children:t("common.edit")})}),e.jsxs(o,{className:"section-body",children:[e.jsx(ae,{data:a.metadata||{},handleEditMetadata:I}),c.editing.metadata&&e.jsx(te,{data:a,loading:c.loading.metadata,onSave:E,onCancel:()=>l(s=>({editing:{...s.editing,metadata:!1}}))})]})]})})]}),c.editing.taxRate&&e.jsx(re,{icon:e.jsx(H,{}),text:t("admin.taxRate.edit"),open:c.editing.taxRate,onClose:()=>l(s=>({editing:{...s.editing,taxRate:!1}})),width:640,addons:e.jsx(b,{variant:"contained",size:"small",disabled:c.loading.taxRate,onClick:j.handleSubmit(L),children:t("common.save")}),children:e.jsx(K,{...j,children:e.jsx(oe,{})})})]})}const pe=J(m)``;export{He as default};
@@ -0,0 +1,10 @@
1
+ import{r as y,j as e,A as f,w as _,B as i,a3 as s,bv as C,q as n,x as h,N as I,Y as k,a7 as S,bf as D}from"./vendor-mui-BXZut9Pz.js";import{V as A,P as E}from"./vendor-blocklet-B67R14so.js";import{u as T,a3 as N,i as G,j as m,N as z,p as B,e as $}from"./index-B4yaPb7B.js";import{S as R}from"./source-data-viewer-D1GShrs5.js";import{I as d}from"./info-metric-ukWq8INi.js";import{S as j}from"./header-ivXuPt06.js";import{I as o}from"./info-row-CaPaNF4L.js";import{I as M}from"./info-row-group-Cxo-4Gk5.js";import{u as W}from"./browser-DF2vfpBa.js";import{i as P}from"./did-Bqcz-NjH.js";import{e as q,a as H}from"./vendor-react-BPknnnEA.js";import"./util-B8B3fsMa.js";import"./lodash-B4Ozcv0x.js";const O=c=>$.get(`/api/credit-transactions/${c}`).then(a=>a.data);function ne(){const{id:c}=q(),a=H(),{t:r}=A(),{session:x}=T(),g=W(),{loading:v,error:u,data:t}=E(()=>O(c)),b=y.useCallback(()=>{a("/customer",{replace:!0})},[a]);if(t?.customer?.did&&x?.user?.did&&!P(t.customer.did,x.user.did))return e.jsx(f,{severity:"error",children:r("common.accessDenied")});if(u)return e.jsx(f,{severity:"error",children:u.message});if(v||!t)return e.jsx(_,{});const w=l=>{if(!l)return null;const p={pending:{label:r("common.pending"),color:"warning"},completed:{label:r("common.completed"),color:"success"},failed:{label:r("common.failed"),color:"error"}}[l]||{label:l,color:"default"};return e.jsx(S,{label:p.label,size:"small",color:p.color})};return e.jsxs(V,{children:[e.jsxs(i,{children:[e.jsxs(s,{className:"page-header",direction:"row",justifyContent:"space-between",alignItems:"center",sx:{position:"relative"},children:[g?e.jsx(i,{}):e.jsxs(s,{direction:"row",onClick:b,alignItems:"center",sx:{fontWeight:"normal",cursor:"pointer"},children:[e.jsx(C,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(n,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:r("admin.creditTransactions.title")})]}),e.jsxs(s,{direction:"row",spacing:1,children:[t.creditGrant&&e.jsx(h,{variant:"outlined",size:"small",onClick:()=>a(`/customer/credit-grant/${t.credit_grant_id}`),children:r("common.viewGrant")}),t.subscription&&e.jsx(h,{variant:"outlined",size:"small",onClick:()=>a(`/customer/subscription/${t.subscription_id}`),children:r("common.viewSubscription")})]})]}),e.jsxs(i,{mt:4,sx:{display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(s,{direction:"row",justifyContent:"space-between",alignItems:"center",children:e.jsxs(s,{direction:"column",alignItems:"flex-start",justifyContent:"space-around",children:[e.jsx(n,{variant:"h2",color:"text.primary",children:t.description||r("common.creditTransaction")}),e.jsx(n,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:t.id})]})}),e.jsxs(s,{className:"section-body",justifyContent:"flex-start",flexWrap:"wrap",sx:{"hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(d,{label:r("common.creditAmount"),value:e.jsx(s,{direction:"row",alignItems:"center",spacing:.5,children:e.jsxs(n,{variant:"body2",sx:{color:"error.main"},children:["-",N(G(t.credit_amount,t.creditGrant?.paymentCurrency?.decimal||0),t.creditGrant?.paymentCurrency?.symbol||"")]})}),divider:!0}),t.transfer_status&&e.jsx(d,{label:r("common.transferStatus"),value:w(t.transfer_status),divider:!0}),e.jsx(d,{label:r("common.createdAt"),value:m(t.created_at)})]})]})]}),e.jsxs(i,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(j,{title:r("admin.details")}),e.jsxs(M,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(o,{label:r("common.customer"),value:e.jsxs(s,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(I,{src:z(t.customer?.did,t.customer?.updated_at?new Date(t.customer.updated_at).toISOString():"",24),alt:t.customer?.name,sx:{width:24,height:24}}),e.jsx(n,{children:t.customer?.name})]})}),e.jsx(o,{label:r("common.creditGrant"),value:e.jsx(n,{component:"span",onClick:()=>a(`/customer/credit-grant/${t.credit_grant_id}`),sx:{color:"text.link",cursor:"pointer"},children:t.creditGrant?.name||t.credit_grant_id})}),t.subscription&&e.jsx(o,{label:r("admin.subscription.name"),value:e.jsx(n,{component:"span",onClick:()=>a(`/customer/subscription/${t.subscription_id}`),sx:{color:"text.link",cursor:"pointer"},children:t.subscription.description||t.subscription_id})}),t.transfer_hash&&t.paymentMethod&&e.jsx(o,{label:r("common.transferTxHash"),value:e.jsx(B,{details:{arcblock:{tx_hash:t.transfer_hash,payer:""}},method:t.paymentMethod,mode:"customer"})}),e.jsx(o,{label:r("admin.meterEvent.reportedAt"),value:m(t.meterEvent?.timestamp?t.meterEvent.timestamp*1e3:t.meterEvent?.created_at||t.created_at)}),e.jsx(o,{label:r("admin.meterEvent.processedAt"),value:m(t.meterEvent?.processed_at?t.meterEvent.processed_at*1e3:t.created_at)})]})]}),t.meterEvent?.source_data&&e.jsxs(e.Fragment,{children:[e.jsx(k,{}),e.jsxs(i,{className:"section",children:[e.jsx(j,{title:r("common.sourceData")}),e.jsx(i,{className:"section-body",children:e.jsx(R,{data:t.meterEvent.source_data})})]})]})]})}const V=D(s)`
2
+ margin-bottom: 24px;
3
+ gap: 24px;
4
+ flex-direction: column;
5
+ @media (max-width: ${({theme:c})=>c.breakpoints.values.md}px) {
6
+ .section-header {
7
+ font-size: 18px;
8
+ }
9
+ }
10
+ `;export{ne as default};
@@ -0,0 +1 @@
1
+ import{j as e,b$ as U,a3 as d,B as s,q as c,bf as C,bg as q,a7 as v,A as z,w as H,z as Y,bv as G,Y as f,x as O}from"./vendor-mui-BXZut9Pz.js";import{V as E,P as W,Y as Z,Z as A}from"./vendor-blocklet-B67R14so.js";import{e as w,d as J,a as K,n as Q,j as N,b8 as X,k as ee}from"./index-B4yaPb7B.js";import{C as oe}from"./copyable-CprMHdhV.js";import{E as ie}from"./list-CvM46TsP.js";import{I as b}from"./info-metric-ukWq8INi.js";import{I as p}from"./info-row-CaPaNF4L.js";import{I as te}from"./info-row-group-Cxo-4Gk5.js";import{M as ne}from"./editor-vZvxDUTl.js";import{M as se}from"./list-B2b-s8wM.js";import{S as g}from"./header-ivXuPt06.js";import{g as re}from"./util-B8B3fsMa.js";import{P as ae,C as ce,A as de,a as le}from"./currency-restrictions-Dsupz2ce.js";import{C as me}from"./link-DsltSF2Q.js";import{a as pe}from"./vendor-react-BPknnnEA.js";import"./table-BN3WBnr3.js";import"./lodash-B4Ozcv0x.js";import"./form-CnrBCyTJ.js";import"./index-oy7LrXGT.js";import"./collapse-CSrlJ0eG.js";import"./drawer-form-CQjNFFWk.js";import"./currency-select-C8j7QQMP.js";import"./currency-GstdXsJf.js";import"./product-select-_72p-5lF.js";import"./form-AFzUvoFE.js";import"./info-card-C9dRgztS.js";import"./uploader-BLdAbLR6.js";import"./tax-code-select-j2arPbaE.js";import"./collapse-BvbJGg1V.js";import"./actions-BEUwbsq1.js";import"./link-DMWJcQvZ.js";import"./description-BHxdy5I3.js";import"./status-3Swm2gK5.js";const xe=()=>w.get("/api/customers?limit=1000").then(t=>t.data);function ue({data:t}){const{t:o}=E(),{data:M}=W(xe,{ready:t.verification_type==="user_restricted"&&(t.customer_dids?.length??0)>0}),S=M?.list||[],k=()=>t.nft_config?e.jsxs(d,{spacing:2,children:[t.nft_config.nft_addresses&&t.nft_config.nft_addresses.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.nftAddresses")}),e.jsx(_,{children:t.nft_config.nft_addresses.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"default",sx:{backgroundColor:"grey.50",borderColor:"grey.300",fontFamily:"monospace",fontSize:"0.75rem",maxWidth:200}},n))})]}),t.nft_config.nft_tags&&t.nft_config.nft_tags.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.nftTags")}),e.jsx(_,{children:t.nft_config.nft_tags.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"primary",sx:{backgroundColor:"primary.50",fontWeight:500}},n))})]}),t.nft_config.min_balance&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.minBalance")}),e.jsx(c,{variant:"body2",sx:{fontWeight:"medium"},children:t.nft_config.min_balance})]})]}):e.jsx(c,{variant:"body2",sx:{color:"text.secondary"},children:o("admin.promotionCode.noNftConfig")}),x=()=>t.vc_config?e.jsxs(d,{spacing:2,children:[t.vc_config.vc_roles&&t.vc_config.vc_roles.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.requiredRoles")}),e.jsx(_,{children:t.vc_config.vc_roles.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"secondary",sx:{backgroundColor:"secondary.50",fontWeight:500,textTransform:"capitalize"}},n))})]}),t.vc_config.vc_trusted_issuers&&t.vc_config.vc_trusted_issuers.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.trustedIssuers")}),e.jsx(_,{children:t.vc_config.vc_trusted_issuers.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"info",sx:{backgroundColor:"info.50",fontFamily:"monospace",fontSize:"0.75rem",maxWidth:200}},n))})]})]}):e.jsx(c,{variant:"body2",sx:{color:"text.secondary"},children:o("admin.promotionCode.noVcConfig")}),l=()=>t.customer_dids?.length?e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.allowedUsers")}),e.jsx(ge,{children:t.customer_dids.map(n=>{const i=S.find(u=>u.did===n||u.id===n);return i?e.jsx(me,{customer:i,size:"small",cardProps:{sx:{border:"none",p:0,minWidth:0}}},n):e.jsx(v,{label:n,size:"small",variant:"outlined",color:"default",sx:{maxWidth:200,backgroundColor:"grey.50",borderColor:"grey.300"}},n)})})]}):e.jsx(c,{variant:"body2",sx:{color:"text.secondary"},children:o("admin.promotionCode.noUsersSpecified")}),I=()=>{switch(t.verification_type){case"nft":return k();case"vc":return x();case"user_restricted":return l();default:return e.jsx(c,{variant:"body2",sx:{color:"text.secondary",fontStyle:"italic"},children:o("admin.promotionCode.codeVerificationOnly")})}};return e.jsx(fe,{children:e.jsx(U,{children:e.jsxs(d,{spacing:2,children:[e.jsxs(s,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},gap:{xs:1,sm:2},alignItems:{xs:"flex-start",sm:"center"}},children:[e.jsx(c,{variant:"caption",sx:{color:"text.secondary"},children:o("admin.promotionCode.verificationType")}),e.jsx(c,{variant:"subtitle2",sx:{color:"text.primary",fontWeight:"medium"},children:o(`admin.promotionCode.verificationTypeMap.${t.verification_type}`)})]}),I()]})})})}const fe=C(q)(({theme:t})=>({border:`1px solid ${t.palette.divider}`,boxShadow:"none",backgroundColor:t.palette.background.paper})),j=C(s)({display:"flex",flexDirection:"column",gap:8}),h=C(c)(({theme:t})=>({fontSize:"0.875rem",fontWeight:500,color:t.palette.text.secondary})),_=C(s)({display:"flex",flexDirection:"row",flexWrap:"wrap",gap:8}),ge=C(s)({display:"flex",flexDirection:"row",flexWrap:"wrap",gap:8,alignItems:"center"}),je=t=>w.get(`/api/promotion-codes/${t}`).then(o=>o.data),he=t=>w.get(`/api/coupons/${t}`).then(o=>o.data);function eo(t){const{t:o}=E(),{isMobile:M}=J(),S=pe(),{settings:k}=K(),[x,l]=Z({editing:{metadata:!1},loading:{metadata:!1},editModalOpen:!1}),{loading:I,error:n,data:i,runAsync:u}=W(()=>je(t.id)),{data:m}=W(()=>i?.coupon_id?he(i.coupon_id):Promise.resolve(null),{refreshDeps:[i?.coupon_id]});if(n)return e.jsx(z,{severity:"error",children:n.message});if(I||!i)return e.jsx(H,{});const T=(()=>{const r=k.paymentMethods?.flatMap(y=>y.payment_currencies)||[];if(!m||m.percent_off)return r;const a=new Set;return m.currency_id&&a.add(m.currency_id),m.currency_options&&typeof m.currency_options=="object"&&Object.keys(m.currency_options).forEach(y=>{a.add(y)}),r.filter(y=>a.has(y.id))})(),P=async r=>{try{l(a=>({loading:{...a.loading,metadata:!0}})),await w.put(`/api/promotion-codes/${t.id}`,{metadata:r.metadata}),A.success(o("common.saved")),X("promotion-code.updated"),u()}catch(a){console.error(a),A.error(ee(a))}finally{l(a=>({loading:{...a.loading,metadata:!1}}))}},D=()=>{l(r=>({editing:{...r.editing,metadata:!0}}))},$=(r,a)=>{r==="edit"&&a?l({editModalOpen:!0}):u()},B=()=>{l({editModalOpen:!1})},L=()=>{l({editModalOpen:!1}),u()},V=()=>{const r=i.expires_at&&Math.floor(Date.now()/1e3)>i.expires_at,a=i.max_redemptions&&i.times_redeemed>=i.max_redemptions;return r?{label:o("admin.promotionCode.expired"),color:"default"}:a?{label:o("admin.promotionCode.maxedOut"),color:"default"}:i.active?{label:o("admin.promotionCode.active"),color:"success"}:{label:o("admin.promotionCode.inactive"),color:"default"}},F=()=>{const r=i.max_redemptions?i.max_redemptions.toString():o("admin.promotionCode.unlimited");return`${i.times_redeemed||0}/${r}`},R=V();return e.jsxs(Ce,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[!i.active&&e.jsxs(z,{severity:"warning",children:[e.jsx(Y,{children:o("admin.promotionCode.inactiveTitle")}),o("admin.promotionCode.inactiveTip")]}),e.jsxs(d,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(d,{direction:"row",onClick:()=>re("/admin/products/coupons"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(G,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(c,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:o("admin.coupons")})]}),e.jsx(d,{direction:"row",spacing:2,children:e.jsx(ae,{data:i,onChange:$,variant:"normal"})})]}),e.jsxs(s,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(d,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:e.jsx(c,{variant:"h2",sx:{color:"text.primary",fontFamily:"monospace",letterSpacing:1},children:i.code})}),e.jsxs(d,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(b,{label:o("admin.promotionCode.id"),value:e.jsx(oe,{text:t.id,style:{marginLeft:4}}),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.redemptions"),value:F(),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.status"),value:e.jsx(Q,{label:R.label,color:R.color}),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.verificationType"),value:o(`admin.promotionCode.verificationTypeMap.${i.verification_type}`),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.created"),value:N(i.created_at),divider:!0})]})]}),e.jsx(f,{})]}),e.jsxs(d,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".promotion-code-column-1":{minWidth:{xs:"100%",lg:"600px"}},".promotion-code-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(s,{className:"promotion-code-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("common.details")}),e.jsxs(te,{children:[e.jsx(p,{label:o("common.active"),value:i.active?o("admin.promotionCode.yes"):o("admin.promotionCode.no")}),i.description&&e.jsx(p,{label:o("admin.coupon.desc"),value:i.description}),e.jsx(p,{label:o("admin.promotionCode.couponId"),value:e.jsx(O,{variant:"text",color:"inherit",size:"small",sx:{color:"secondary.main"},onClick:()=>S(`/admin/products/coupons/${i.coupon_id}`),children:i.coupon_id})}),e.jsx(p,{label:o("admin.promotionCode.maxRedemptions"),value:i.max_redemptions||o("admin.promotionCode.unlimited")}),e.jsx(p,{label:o("admin.promotionCode.timesRedeemed"),value:i.times_redeemed||0}),e.jsx(p,{label:o("admin.promotionCode.expires"),value:i.expires_at?N(i.expires_at*1e3):o("admin.promotionCode.never")}),e.jsx(p,{label:o("admin.promotionCode.updated"),value:N(i.updated_at)})]})]}),e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("admin.promotionCode.verificationConfig")}),e.jsx(s,{className:"section-body",children:e.jsx(ue,{data:i})})]}),i.restrictions?.currency_options&&Object.keys(i.restrictions.currency_options).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("admin.coupon.currencies")}),e.jsx(s,{className:"section-body",children:e.jsx(ce,{currencyOptions:i.restrictions.currency_options,type:"promotion_code"})})]})]}),e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("admin.coupon.activeRedemptions")}),e.jsx(s,{className:"section-body",children:e.jsx(de,{promotionCodeId:i.id})})]}),e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("common.events")}),e.jsx(s,{className:"section-body",children:e.jsx(ie,{features:{toolbar:!1},object_id:i.id})})]})]}),M&&e.jsx(f,{}),e.jsx(s,{className:"promotion-code-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("common.metadata.label"),children:e.jsx(O,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:x.editing.metadata,onClick:D,children:o("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(se,{data:i.metadata,handleEditMetadata:D}),x.editing.metadata&&e.jsx(ne,{data:i,loading:x.loading.metadata,onSave:P,onCancel:()=>l(r=>({editing:{...r.editing,metadata:!1}}))})]})]})})]}),e.jsx(le,{open:x.editModalOpen,onClose:B,onSubmit:L,couponId:i.coupon_id,promotionCode:i,isEditing:!0,availableCurrencies:T})]})}const Ce=C(d)``;export{eo as default};
@@ -1 +1 @@
1
- import{j as e,A as x,w as p,B as a,a3 as r,bv as u,q as n,O as h,bf as j}from"./vendor-mui-BXZut9Pz.js";import{V as b,O as f}from"./vendor-blocklet-D_i_QeSo.js";import{n as g,j as c,e as v}from"./index-DgSc1Qy8.js";import{C as w}from"./copyable-DpX04wZz.js";import{I as o}from"./info-metric-CNse3r66.js";import{S as y}from"./header-ivXuPt06.js";import{W as k}from"./attempts-DySeqBYU.js";import{g as C,w as S}from"./util-mDHAL0lx.js";import"./vendor-react-BPknnnEA.js";import"./vendor-arcblock-ChFCRdyx.js";import"./lodash-B4Ozcv0x.js";import"./info-card-C1yxhxJG.js";const W=i=>v.get(`/api/webhook-endpoints/${i}`).then(s=>s.data);function H(i){const{t:s}=b(),{loading:m,error:l,data:t}=f(()=>W(i.id));return l?e.jsx(x,{severity:"error",children:l.message}):m||!t?e.jsx(p,{}):e.jsxs(_,{direction:"column",spacing:4,sx:{mb:4},children:[e.jsxs(a,{children:[e.jsxs(r,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(r,{direction:"row",onClick:()=>C("/admin/developers/webhooks"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(u,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(n,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:s("admin.webhooks")})]}),e.jsx(w,{text:i.id,style:{marginLeft:4}})]}),e.jsxs(a,{sx:{mt:2},children:[e.jsx(r,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(r,{direction:"column",sx:{alignItems:"flex-start"},children:[e.jsx(n,{variant:"h5",children:t.url}),e.jsx(n,{variant:"body1",sx:{color:"text.secondary"},children:t.description})]})}),e.jsxs(r,{className:"section-body",direction:"row",spacing:3,sx:{justifyContent:"flex-start",flexWrap:"wrap",pt:2,mt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(o,{label:s("common.status"),value:e.jsx(g,{label:t.status,color:S(t.status)}),divider:!0}),e.jsx(o,{label:s("admin.webhookEndpoint.listen"),value:e.jsx(h,{arrow:!0,title:e.jsx("ul",{style:{padding:0,margin:0},children:t.enabled_events.map(d=>e.jsx("li",{style:{fontSize:"0.7875rem"},children:d},d))}),children:e.jsxs(n,{sx:{backgroundColor:"grey.100",paddingX:.5,borderRadius:.5},children:[t.enabled_events.length," events"]})}),divider:!0}),e.jsx(o,{label:s("admin.webhookEndpoint.version"),value:t.api_version,divider:!0}),e.jsx(o,{label:s("common.createdAt"),value:c(t.created_at),divider:!0}),e.jsx(o,{label:s("common.updatedAt"),value:c(t.updated_at)})]})]})]}),e.jsxs(a,{className:"section",children:[e.jsx(y,{title:s("admin.webhookEndpoint.attempts"),mb:0}),e.jsx(a,{className:"section-body",children:e.jsx(k,{webhook_endpoint_id:t.id})})]})]})}const _=j(r)``;export{H as default};
1
+ import{j as e,A as x,w as p,B as a,a3 as r,bv as u,q as n,O as h,bf as j}from"./vendor-mui-BXZut9Pz.js";import{V as b,P as f}from"./vendor-blocklet-B67R14so.js";import{n as g,j as c,e as v}from"./index-B4yaPb7B.js";import{C as w}from"./copyable-CprMHdhV.js";import{I as o}from"./info-metric-ukWq8INi.js";import{S as y}from"./header-ivXuPt06.js";import{W as k}from"./attempts-BfbYfiJa.js";import{g as C,w as S}from"./util-B8B3fsMa.js";import"./vendor-react-BPknnnEA.js";import"./vendor-arcblock-D1drrE7q.js";import"./lodash-B4Ozcv0x.js";import"./info-card-C9dRgztS.js";const W=i=>v.get(`/api/webhook-endpoints/${i}`).then(s=>s.data);function F(i){const{t:s}=b(),{loading:m,error:l,data:t}=f(()=>W(i.id));return l?e.jsx(x,{severity:"error",children:l.message}):m||!t?e.jsx(p,{}):e.jsxs(_,{direction:"column",spacing:4,sx:{mb:4},children:[e.jsxs(a,{children:[e.jsxs(r,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(r,{direction:"row",onClick:()=>C("/admin/developers/webhooks"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(u,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(n,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:s("admin.webhooks")})]}),e.jsx(w,{text:i.id,style:{marginLeft:4}})]}),e.jsxs(a,{sx:{mt:2},children:[e.jsx(r,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(r,{direction:"column",sx:{alignItems:"flex-start"},children:[e.jsx(n,{variant:"h5",children:t.url}),e.jsx(n,{variant:"body1",sx:{color:"text.secondary"},children:t.description})]})}),e.jsxs(r,{className:"section-body",direction:"row",spacing:3,sx:{justifyContent:"flex-start",flexWrap:"wrap",pt:2,mt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(o,{label:s("common.status"),value:e.jsx(g,{label:t.status,color:S(t.status)}),divider:!0}),e.jsx(o,{label:s("admin.webhookEndpoint.listen"),value:e.jsx(h,{arrow:!0,title:e.jsx("ul",{style:{padding:0,margin:0},children:t.enabled_events.map(d=>e.jsx("li",{style:{fontSize:"0.7875rem"},children:d},d))}),children:e.jsxs(n,{sx:{backgroundColor:"grey.100",paddingX:.5,borderRadius:.5},children:[t.enabled_events.length," events"]})}),divider:!0}),e.jsx(o,{label:s("admin.webhookEndpoint.version"),value:t.api_version,divider:!0}),e.jsx(o,{label:s("common.createdAt"),value:c(t.created_at),divider:!0}),e.jsx(o,{label:s("common.updatedAt"),value:c(t.updated_at)})]})]})]}),e.jsxs(a,{className:"section",children:[e.jsx(y,{title:s("admin.webhookEndpoint.attempts"),mb:0}),e.jsx(a,{className:"section-body",children:e.jsx(k,{webhook_endpoint_id:t.id})})]})]})}const _=j(r)``;export{F as default};
@@ -0,0 +1 @@
1
+ import{j as e,A as L,w as R,B as s,a3 as n,bv as $,q as E,N as B,Y as r,O as W,be as z,x as O,bf as H}from"./vendor-mui-BXZut9Pz.js";import{V as q,Y as G,P as U,cw as V,a7 as Y,Z as I}from"./vendor-blocklet-B67R14so.js";import{d as F,i as w,a5 as J,n as _,o as C,j as N,p as Z,e as k,k as K}from"./index-B4yaPb7B.js";import{T as Q}from"./gas-kw2KMH1u.js";import{L as M}from"./vendor-react-BPknnnEA.js";import{l as X}from"./lodash-B4Ozcv0x.js";import{C as ee}from"./copyable-CprMHdhV.js";import{C as te}from"./link-DsltSF2Q.js";import{E as ae}from"./list-CvM46TsP.js";import{I as S}from"./info-metric-ukWq8INi.js";import{I as i}from"./info-row-CaPaNF4L.js";import{M as se}from"./editor-vZvxDUTl.js";import{M as ie}from"./list-B2b-s8wM.js";import{P as ne}from"./actions-JHsqbHpB.js";import{P as oe}from"./list-Cd1O-aDi.js";import{S as l}from"./header-ivXuPt06.js";import{g as re}from"./util-B8B3fsMa.js";import{R as le}from"./list-BzgF4i3i.js";import{I as me}from"./info-row-group-Cxo-4Gk5.js";import"./table-BN3WBnr3.js";import"./form-CnrBCyTJ.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./cache-state-lld4zuDg.js";import"./filter-toolbar-VvmMATj0.js";import"./product-select-_72p-5lF.js";import"./info-card-C9dRgztS.js";import"./actions-DeCPtfTK.js";const ce=x=>k.get(`/api/payment-intents/${x}`).then(a=>a.data),m="column",c="flex-start";function Oe(x){const{t:a}=q(),{isMobile:f}=F(),[j,p]=G({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:D,error:y,data:t,runAsync:h}=U(()=>ce(x.id));if(y)return e.jsx(L,{severity:"error",children:y.message});if(D||!t)return e.jsx(R,{});const A=(d=>async P=>{try{p(o=>({loading:{...o.loading,[d]:!0}})),await k.put(`/api/payment-intents/${x.id}`,P).then(o=>o.data),I.success(a("common.saved")),h()}catch(o){console.error(o),I.error(K(o))}finally{p(o=>({loading:{...o.loading,[d]:!1}}))}})("metadata"),u=t.paymentCurrency,g=[w(t?.amount_received,u.decimal),u.symbol].join(" "),b=[w(t?.amount,u.decimal),u.symbol].join(" "),v=()=>{p(d=>({editing:{...d.editing,metadata:!0}}))},T=t.subscription?.status==="canceled";return e.jsxs(de,{direction:"column",spacing:2.5,mb:4,children:[e.jsxs(s,{children:[e.jsxs(n,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(n,{direction:"row",onClick:()=>re("/admin/payments/intents"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx($,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(E,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.payments")})]}),e.jsx(ne,{data:t,variant:"normal",onChange:h})]}),e.jsxs(s,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(n,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(n,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(B,{src:t.paymentCurrency.logo,alt:t.paymentCurrency.symbol,variant:"square",sx:{width:"52px",height:"52px",borderRadius:.5}}),e.jsxs(n,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(J,{amount:t?.amount_received==="0"?b:g,sx:{my:0,fontSize:"1.75rem",lineHeight:"32px"}}),e.jsx(ee,{text:x.id})]})]})}),e.jsxs(n,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(S,{label:a("common.status"),value:e.jsx(_,{label:t.status,color:C(t.status)}),divider:!0}),e.jsx(S,{label:a("common.customer"),value:t.metadata?.payerDid&&V(t.metadata?.payerDid)?e.jsx(Y,{did:t.metadata?.payerDid,...f?{responsive:!1,compact:!0}:{}}):e.jsx(te,{customer:t.customer}),divider:!0})]})]}),e.jsx(r,{})]}),e.jsxs(n,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".payment-link-column-1":{minWidth:{xs:"100%",lg:"600px"}},".payment-link-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(s,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(l,{title:a("admin.details")}),e.jsxs(me,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(i,{label:a("common.status"),value:e.jsxs(n,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(_,{label:t.status,color:C(t.status)}),t.last_payment_error&&e.jsx(W,{title:e.jsx("pre",{style:{whiteSpace:"break-spaces"},children:JSON.stringify({...t.last_payment_error,type:X.startCase(t.last_payment_error?.type)},null,2)}),children:e.jsx(z,{fontSize:"small",color:"error"})})]})}),e.jsx(i,{label:a("common.amount"),value:b}),e.jsx(i,{label:a("admin.paymentIntent.received"),value:g}),e.jsx(i,{label:a("common.createdAt"),value:N(t.created_at)}),e.jsx(i,{label:a("common.description"),value:t.description}),e.jsx(i,{label:a("common.updatedAt"),value:N(t.updated_at)}),e.jsx(i,{label:a("common.statementDescriptor"),value:t.statement_descriptor})]})]}),e.jsx(r,{}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.payouts")}),e.jsx(s,{className:"section-body",children:e.jsx(oe,{features:{toolbar:!1},payment_intent_id:t?.id,isCanceledSubscription:T})})]}),e.jsx(r,{}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.refunds")}),e.jsx(s,{className:"section-body",children:e.jsx(le,{features:{customer:!1,toolbar:!1},payment_intent_id:t?.id})})]}),e.jsx(r,{}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.events.title")}),e.jsx(s,{className:"section-body",children:e.jsx(ae,{features:{toolbar:!1},object_id:t.id})})]})]}),f&&e.jsx(r,{}),e.jsxs(s,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.paymentMethod._name")}),e.jsxs(n,{children:[e.jsx(i,{label:a("common.id"),value:t.paymentMethod?.id,direction:m,alignItems:c}),e.jsx(i,{label:a("admin.paymentMethod.type"),value:t.paymentMethod?.type,direction:m,alignItems:c}),e.jsx(i,{label:a("admin.paymentCurrency.name"),value:`${t.paymentCurrency.symbol} (${t.paymentMethod?.name})`,direction:m,alignItems:c}),(!!t.payment_details?.ethereum||!!t.payment_details?.base)&&e.jsx(i,{label:a("common.txGas"),value:e.jsx(Q,{details:t.payment_details,method:t.paymentMethod}),direction:m,alignItems:c}),e.jsx(i,{label:a(`common.${t.payment_details?.arcblock?.type||"transfer"}TxHash`),value:e.jsx(Z,{details:t.payment_details,method:t.paymentMethod}),direction:m,alignItems:c})]})]}),e.jsx(r,{}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.connections")}),e.jsxs(n,{children:[t.subscription&&e.jsx(i,{label:a("admin.subscription.name"),value:e.jsx(M,{to:`/admin/billing/${t.subscription.id}`,children:t.subscription.id}),direction:m,alignItems:c}),t.invoice_id&&e.jsx(i,{label:a("admin.invoice.name"),value:e.jsx(M,{to:`/admin/billing/${t.invoice_id}`,children:t.invoice_id}),direction:m,alignItems:c})]})]}),e.jsx(r,{}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("common.metadata.label"),children:e.jsx(O,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:j.editing.metadata,onClick:v,children:a("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(ie,{data:t.metadata,handleEditMetadata:v}),j.editing.metadata&&e.jsx(se,{data:t,loading:j.loading.metadata,onSave:A,onCancel:()=>p(d=>({editing:{...d.editing,metadata:!1}}))})]})]})]})]})]})}const de=H(n)``;export{Oe as default};
@@ -1 +1 @@
1
- import{j as e,A as M,w as W,$ as p,a3 as n,bv as _,q as f,B as i,Y as d,x as $,bf as A}from"./vendor-mui-BXZut9Pz.js";import{V as E,X as L,O as B,E as w,Y as y}from"./vendor-blocklet-D_i_QeSo.js";import{a as R,T as U,j as v,e as I,k as z}from"./index-DgSc1Qy8.js";import{a as O,L as q}from"./vendor-react-BPknnnEA.js";import{C as k}from"./copyable-DpX04wZz.js";import{E as G}from"./list-D1aevUOI.js";import{I as H}from"./info-card-C1yxhxJG.js";import{I as C}from"./info-row-DOK2whMn.js";import{M as Y}from"./editor-BF5I0siU.js";import{M as F}from"./list-C521zE_7.js";import{P as V}from"./actions-Bt_jST94.js";import{P as X}from"./preview-DjYRpRA8.js";import{S as l}from"./header-ivXuPt06.js";import{g as J,n as K}from"./util-mDHAL0lx.js";import{I as Q}from"./info-metric-CNse3r66.js";import{I as Z}from"./info-row-group-BeUhWnnY.js";import"./table-BRU4Enia.js";import"./lodash-B4Ozcv0x.js";import"./form-BGm5NPDn.js";import"./actions-jxGAdGfb.js";import"./click-boundary-y8dVA_tr.js";import"./assign-CkV5Q2LP.js";import"./chrome-BPS46pXA.js";const ee=o=>I.get(`/api/pricing-tables/${o}`).then(t=>t.data);function Ne(o){const{t,locale:u}=E(),N=O(),{settings:P}=R(),[m,c]=L({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:T,error:g,data:a,runAsync:j}=B(()=>ee(o.id));if(g)return e.jsx(M,{severity:"error",children:g.message});if(T||!a)return e.jsx(W,{});const D=(r=>async x=>{try{c(s=>({loading:{...s.loading,[r]:!0}})),await I.put(`/api/pricing-tables/${o.id}`,x).then(s=>s.data),y.success(t("common.saved")),j()}catch(s){console.error(s),y.error(z(s))}finally{c(s=>({loading:{...s.loading,[r]:!1}}))}})("metadata"),S=r=>{r==="remove"?N("/admin/products/pricing-tables"):j()},h=()=>{c(r=>({editing:{...r.editing,metadata:!0}}))};return e.jsxs(p,{container:!0,spacing:4,sx:{mb:4},children:[e.jsxs(p,{size:12,children:[e.jsxs(n,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(n,{direction:"row",onClick:()=>J("/admin/products/pricing-tables"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(_,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(f,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.pricingTables")})]}),e.jsx(V,{data:a,onChange:S,variant:"normal"})]}),e.jsxs(i,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(n,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center",gap:5},children:e.jsxs(n,{direction:"column",sx:{alignItems:"flex-start"},children:[e.jsx(f,{variant:"h1",children:a.name}),e.jsx(k,{text:w(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pricing-table/${a.id}`),children:e.jsx(f,{variant:"h6",sx:{color:"text.secondary",mr:1,maxWidth:{xs:300,md:"100%"},textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap"},children:w(window.blocklet.prefix,`/checkout/pricing-table/${a.id}`)})})]})}),e.jsx(n,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:e.jsx(Q,{label:t("common.id"),value:e.jsx(k,{text:o.id,style:{marginLeft:4}}),divider:!0})})]}),e.jsx(d,{})]}),e.jsx(p,{size:12,children:e.jsxs(n,{sx:{flexDirection:{xs:"column",lg:"row"},gap:4,".payment-link-column-1":{minWidth:{xs:"100%",lg:"600px"}},".payment-link-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsx(i,{className:"payment-link-column-1",sx:{flex:1},children:e.jsxs(te,{direction:"column",spacing:3,children:[e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("admin.products")}),e.jsx(i,{className:"section-body",children:e.jsx(U,{className:"link-products-table",toolbar:!1,footer:!1,locale:u,data:a.items,columns:[{label:t("common.title"),name:"product_id",options:{sort:!1,customBodyRenderLite:(r,x)=>{const s=a.items[x],b=a?.currency||P.baseCurrency;return e.jsx(q,{to:`/admin/products/${s.product_id}?currency_id=${b?.id}&price_id=${s.price.id}`,children:e.jsx(H,{name:s.product.name,description:K({...s.product,prices:[s.price]},b,u),logo:s.product.images[0]})})}}}],options:{count:a.items.length,page:0,rowsPerPage:20},emptyNodeText:t("empty.products")})})]}),e.jsx(d,{}),e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("admin.details")}),e.jsxs(Z,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(C,{label:t("common.createdAt"),value:v(a.created_at)}),e.jsx(C,{label:t("common.updatedAt"),value:v(a.updated_at)})]})]}),e.jsx(d,{}),e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("common.preview")}),e.jsx(i,{className:"section-body",sx:{maxWidth:1050},children:e.jsx(X,{id:a.id})})]}),e.jsx(d,{}),e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("admin.events.title")}),e.jsx(i,{className:"section-body",children:e.jsx(G,{features:{toolbar:!1},object_id:a.id})})]})]})}),e.jsx(i,{className:"payment-link-column-2",children:e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("common.metadata.label"),children:e.jsx($,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:m.editing.metadata,onClick:h,children:t("common.edit")})}),e.jsxs(i,{className:"section-body",children:[e.jsx(F,{data:a.metadata,handleEditMetadata:h}),m.editing.metadata&&e.jsx(Y,{data:a,loading:m.loading.metadata,onSave:D,onCancel:()=>c(r=>({editing:{...r.editing,metadata:!1}}))})]})]})})]})})]})}const te=A(n)``;export{Ne as default};
1
+ import{j as e,A as M,w as W,$ as p,a3 as n,bv as _,q as f,B as i,Y as d,x as $,bf as A}from"./vendor-mui-BXZut9Pz.js";import{V as L,Y as B,P as E,F as w,Z as y}from"./vendor-blocklet-B67R14so.js";import{a as R,T as U,j as v,e as I,k as z}from"./index-B4yaPb7B.js";import{a as O,L as q}from"./vendor-react-BPknnnEA.js";import{C as k}from"./copyable-CprMHdhV.js";import{E as F}from"./list-CvM46TsP.js";import{I as G}from"./info-card-C9dRgztS.js";import{I as C}from"./info-row-CaPaNF4L.js";import{M as H}from"./editor-vZvxDUTl.js";import{M as Y}from"./list-B2b-s8wM.js";import{P as V}from"./actions--FNKSNIs.js";import{P as Z}from"./preview-F3lma170.js";import{S as l}from"./header-ivXuPt06.js";import{g as J,n as K}from"./util-B8B3fsMa.js";import{I as Q}from"./info-metric-ukWq8INi.js";import{I as X}from"./info-row-group-Cxo-4Gk5.js";import"./table-BN3WBnr3.js";import"./lodash-B4Ozcv0x.js";import"./form-CnrBCyTJ.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./assign-DKRfmN7W.js";import"./chrome-BPS46pXA.js";const ee=o=>I.get(`/api/pricing-tables/${o}`).then(t=>t.data);function Ne(o){const{t,locale:u}=L(),N=O(),{settings:P}=R(),[m,c]=B({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:T,error:g,data:a,runAsync:j}=E(()=>ee(o.id));if(g)return e.jsx(M,{severity:"error",children:g.message});if(T||!a)return e.jsx(W,{});const D=(r=>async x=>{try{c(s=>({loading:{...s.loading,[r]:!0}})),await I.put(`/api/pricing-tables/${o.id}`,x).then(s=>s.data),y.success(t("common.saved")),j()}catch(s){console.error(s),y.error(z(s))}finally{c(s=>({loading:{...s.loading,[r]:!1}}))}})("metadata"),S=r=>{r==="remove"?N("/admin/products/pricing-tables"):j()},h=()=>{c(r=>({editing:{...r.editing,metadata:!0}}))};return e.jsxs(p,{container:!0,spacing:4,sx:{mb:4},children:[e.jsxs(p,{size:12,children:[e.jsxs(n,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(n,{direction:"row",onClick:()=>J("/admin/products/pricing-tables"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(_,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(f,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.pricingTables")})]}),e.jsx(V,{data:a,onChange:S,variant:"normal"})]}),e.jsxs(i,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(n,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center",gap:5},children:e.jsxs(n,{direction:"column",sx:{alignItems:"flex-start"},children:[e.jsx(f,{variant:"h1",children:a.name}),e.jsx(k,{text:w(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pricing-table/${a.id}`),children:e.jsx(f,{variant:"h6",sx:{color:"text.secondary",mr:1,maxWidth:{xs:300,md:"100%"},textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap"},children:w(window.blocklet.prefix,`/checkout/pricing-table/${a.id}`)})})]})}),e.jsx(n,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:e.jsx(Q,{label:t("common.id"),value:e.jsx(k,{text:o.id,style:{marginLeft:4}}),divider:!0})})]}),e.jsx(d,{})]}),e.jsx(p,{size:12,children:e.jsxs(n,{sx:{flexDirection:{xs:"column",lg:"row"},gap:4,".payment-link-column-1":{minWidth:{xs:"100%",lg:"600px"}},".payment-link-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsx(i,{className:"payment-link-column-1",sx:{flex:1},children:e.jsxs(te,{direction:"column",spacing:3,children:[e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("admin.products")}),e.jsx(i,{className:"section-body",children:e.jsx(U,{className:"link-products-table",toolbar:!1,footer:!1,locale:u,data:a.items,columns:[{label:t("common.title"),name:"product_id",options:{sort:!1,customBodyRenderLite:(r,x)=>{const s=a.items[x],b=a?.currency||P.baseCurrency;return e.jsx(q,{to:`/admin/products/${s.product_id}?currency_id=${b?.id}&price_id=${s.price.id}`,children:e.jsx(G,{name:s.product.name,description:K({...s.product,prices:[s.price]},b,u),logo:s.product.images[0]})})}}}],options:{count:a.items.length,page:0,rowsPerPage:20},emptyNodeText:t("empty.products")})})]}),e.jsx(d,{}),e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("admin.details")}),e.jsxs(X,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(C,{label:t("common.createdAt"),value:v(a.created_at)}),e.jsx(C,{label:t("common.updatedAt"),value:v(a.updated_at)})]})]}),e.jsx(d,{}),e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("common.preview")}),e.jsx(i,{className:"section-body",sx:{maxWidth:1050},children:e.jsx(Z,{id:a.id})})]}),e.jsx(d,{}),e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("admin.events.title")}),e.jsx(i,{className:"section-body",children:e.jsx(F,{features:{toolbar:!1},object_id:a.id})})]})]})}),e.jsx(i,{className:"payment-link-column-2",children:e.jsxs(i,{className:"section",children:[e.jsx(l,{title:t("common.metadata.label"),children:e.jsx($,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:m.editing.metadata,onClick:h,children:t("common.edit")})}),e.jsxs(i,{className:"section-body",children:[e.jsx(Y,{data:a.metadata,handleEditMetadata:h}),m.editing.metadata&&e.jsx(H,{data:a,loading:m.loading.metadata,onSave:D,onCancel:()=>c(r=>({editing:{...r.editing,metadata:!1}}))})]})]})})]})})]})}const te=A(n)``;export{Ne as default};
@@ -0,0 +1,24 @@
1
+ import{j as e,r as D,q as l,B as c,w as G,a3 as x,x as S,bf as H,u as Q,A as P,bv as X,O as E,Y as k}from"./vendor-mui-BXZut9Pz.js";import{V as $,P as F,ah as ee,Y as te,Z as N,F as se}from"./vendor-blocklet-B67R14so.js";import{i as O,n as w,o as q,j as b,p as A,T as ae,q as ne,e as K,d as oe,a as ie,u as re,k as W,r as ce,s as le,t as me,v as de,l as pe,w as ue}from"./index-B4yaPb7B.js";import{T as xe}from"./gas-kw2KMH1u.js";import{b as he,e as ye,L as fe}from"./vendor-react-BPknnnEA.js";import{l as j}from"./lodash-B4Ozcv0x.js";import{C as ge}from"./currency-GstdXsJf.js";import{C as be}from"./link-DsltSF2Q.js";import{I as h}from"./info-row-CaPaNF4L.js";import{D as je,R as ve,I as _e}from"./related-credit-grants-DnKdAit6.js";import{g as we}from"./util-B8B3fsMa.js";import{i as Ce}from"./did-Bqcz-NjH.js";import{I}from"./info-metric-ukWq8INi.js";import{I as ke}from"./info-row-group-Cxo-4Gk5.js";import{u as Ie}from"./browser-DF2vfpBa.js";import"./browser-Bb9g-cvG.js";import"./usage-records-BAwNs1y8.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./generateCategoricalChart-BCpuUeC_.js";const Se=s=>{const o={};return s.forEach(a=>{const r=new Date(a.created_at).toLocaleDateString();o[r]||(o[r]=[]),o[r]?.push(a)}),o},U=(s={})=>{const o=new URLSearchParams;return Object.keys(s).forEach(a=>{o.set(a,String(s[a]))}),K.get(`/api/refunds?${o.toString()}`).then(a=>a.data)},R=10,Re=D.memo(({invoice_id:s})=>{const o="invoice-table",{t:a,locale:r}=$(),[d,y]=D.useState({pageSize:R,page:1}),{loading:f,data:p={list:[],count:0}}=F(()=>U({...d,invoice_id:s}),{refreshDeps:[d]}),u=[{label:a("common.amount"),name:"id",width:80,align:"right",options:{customBodyRenderLite:(n,i)=>{const t=p.list[i];return e.jsxs(l,{component:"strong",sx:{fontWeight:600},children:[O(t?.amount,t?.paymentCurrency.decimal),t?.paymentCurrency.symbol]})}}},{label:a("common.status"),name:"status",width:100,options:{filter:!0,customBodyRenderLite:(n,i)=>{const t=p.list[i];return e.jsx(w,{label:t.status,color:q(t.status)})}}},{label:a("common.type"),name:"type",width:80,options:{filter:!0,customBodyRenderLite:(n,i)=>{const t=p.list[i];return e.jsx(w,{label:a(`refund.type.${t.type}`)})}}},{label:a("common.description"),name:"description",options:{customBodyRenderLite:(n,i)=>{const t=p.list[i];return t.description?j.capitalize(j.toLower(t.description.replace(/_/g," "))):t.id}}},{label:a("common.createdAt"),name:"created_at",options:{sort:!0,customBodyRenderLite:(n,i)=>{const t=p.list[i];return b(t.created_at)}}},{label:a("common.updatedAt"),name:"updated_at",options:{sort:!0,customBodyRenderLite:(n,i)=>{const t=p.list[i];return b(t.updated_at)}}},{label:a("common.txHash"),name:"",options:{customBodyRenderLite:(n,i)=>{const t=p.list[i],v=t.payment_details;return["arcblock","ethereum","base"].map(C=>!!v?.[C]?.tx_hash).find(Boolean)?e.jsx(c,{sx:{".MuiTypography-root":{color:"text.link"}},children:e.jsx(A,{details:v,method:t.paymentMethod,mode:"customer"})}):a("common.none")}}}],m=({page:n,rowsPerPage:i})=>{d.pageSize!==i?y(t=>({...t,pageSize:i,page:1})):d.page!==n+1&&y(t=>({...t,page:n+1}))};return e.jsx(De,{children:e.jsx(ae,{hasRowLink:!0,durable:`__${o}__`,durableKeys:["page","rowsPerPage","searchText"],data:p.list,columns:u,options:{count:p.count,page:d.page-1,rowsPerPage:d.pageSize},loading:f,onChange:m,toolbar:!1,sx:{mt:2},showMobile:!1,locale:r,mobileTDFlexDirection:"row",emptyNodeText:a("payment.customer.refund.emptyList")})})}),De=H(c)`
2
+ @media (max-width: ${({theme:s})=>s.breakpoints.values.md}px) {
3
+ .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root {
4
+ > div {
5
+ width: fit-content;
6
+ flex: inherit;
7
+ font-size: 14px;
8
+ }
9
+ }
10
+ .invoice-summary {
11
+ padding-right: 20px;
12
+ }
13
+ }
14
+ `,Te=D.memo(({invoice_id:s})=>{const{t:o}=$(),{data:a,loadMore:r,loadingMore:d,loading:y}=ee(u=>{const m=u?Math.ceil(u.list.length/R)+1:1;return U({page:m,pageSize:R,invoice_id:s})},{reloadDeps:[s]});if(y||!a)return e.jsx(G,{});if(a&&a.list.length===0)return e.jsx(l,{sx:{color:"text.secondary"},children:o("payment.customer.refund.empty")});const f=a&&a.list.length<a.count,p=Se(a.list);return e.jsxs(x,{direction:"column",sx:{gap:1,mt:1},children:[Object.entries(p).map(([u,m])=>e.jsxs(c,{children:[e.jsx(l,{sx:{fontWeight:"bold",color:"text.secondary",mt:2,mb:1},children:u}),m.map(n=>e.jsxs(x,{direction:{xs:"column",sm:"row"},sx:{gap:{xs:.5,sm:1.5,md:3},flexWrap:"nowrap",my:1},children:[e.jsx(c,{sx:{flex:3},children:e.jsx(l,{children:ne(n.created_at)})}),e.jsx(c,{sx:{flex:2},children:e.jsxs(l,{sx:{textAlign:"right"},children:[O(n.amount,n.paymentCurrency.decimal)," ",n.paymentCurrency.symbol]})}),e.jsx(c,{sx:{flex:3},children:e.jsx(w,{label:n.status,color:q(n.status)})}),e.jsx(c,{sx:{flex:3},children:e.jsx(l,{children:n.description?j.capitalize(j.toLower(n.description.replace(/_/g," "))):"-"})}),e.jsx(c,{sx:{flex:3,minWidth:"220px"},children:(n.payment_details?.arcblock?.tx_hash||n.payment_details?.ethereum?.tx_hash||n.payment_details?.base?.tx_hash)&&e.jsx(A,{details:n.payment_details,method:n.paymentMethod,mode:"customer"})})]},n.id))]},u)),e.jsxs(c,{children:[f&&e.jsx(S,{variant:"text",type:"button",color:"inherit",onClick:r,disabled:d,children:d?o("common.loadingMore",{resource:o("payment.customer.payments")}):o("common.loadMore",{resource:o("payment.customer.payments")})}),!f&&a.count>R&&e.jsx(l,{sx:{color:"text.secondary"},children:o("common.noMore",{resource:o("payment.customer.payments")})})]})]})});function Me({type:s="list",...o}){return s==="table"?e.jsx(Re,{...o}):e.jsx(Te,{...o})}const Le=s=>K.get(`/api/invoices/${s}`).then(o=>o.data);function et(){const{t:s,locale:o}=$(),[a]=he(),{isMobile:r}=oe(),{connect:d}=ie(),y=ye(),f=Q(),p=Ie(),[u,m]=te({downloading:!1,paying:!1}),{loading:n,error:i,data:t,runAsync:v}=F(()=>Le(y.id)),g=a.get("action"),{session:C}=re(),T=t?.checkoutSession?.submit_type==="donate",z=()=>{m({paying:!0}),d.open({action:"collect",saveConnect:!1,locale:o,extraParams:{invoiceId:y.id,action:g,allowCreatePI:t?.status==="uncollectible"},messages:{scan:"",title:s(`payment.customer.invoice.${g||"pay"}`),success:s(`payment.customer.invoice.${g||"pay"}Success`),error:s(`payment.customer.invoice.${g||"pay"}Error`),confirm:""},onSuccess:async()=>{d.close(),m({paying:!1}),await v()},onClose:()=>{d.close(),m({paying:!1})},onError:_=>{m({paying:!1}),N.error(W(_))}})},Y=()=>{m({paying:!0}),d.close()};if(D.useEffect(()=>{i?.response?.status===403?Y():["pay","renew"].includes(g)&&["open","uncollectible"].includes(t?.status)&&z()},[i]),t?.customer?.did&&C?.user?.did&&!Ce(t.customer.did,C.user.did))return e.jsx(P,{severity:"error",children:s("common.accessDenied")});if(i)return e.jsx(P,{severity:"error",children:W(i)});if(n||!t)return e.jsx(G,{});const M=t.paymentMethod?.type==="arcblock"&&["stake","stake_overdraft_protection"].includes(t.billing_reason),L=t.paymentMethod?.type==="arcblock"&&t.billing_reason.includes("slash_stake"),V=t.billing_reason==="overdraft_protection",B=t.paymentIntent?.payment_details||t.metadata?.payment_details,Z=["open","paid","uncollectible"].includes(t.status)&&!T&&!j.isEmpty(t.lines);return e.jsxs(Be,{direction:"column",spacing:3,children:[e.jsxs(x,{direction:"row",sx:{justifyContent:"space-between"},children:[p?e.jsx(c,{}):e.jsxs(x,{direction:"row",onClick:()=>we("/customer"),sx:{alignItems:"center",fontWeight:"normal",padding:"10px 0",cursor:"pointer"},children:[e.jsx(X,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(l,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:s("common.previous")})]}),e.jsxs(x,{direction:"row",spacing:1,sx:{justifyContent:"flex-end",alignItems:"center"},children:[Z&&e.jsx(je,{data:t}),t?.paymentLink?.donation_settings?.reference&&e.jsx(S,{variant:"outlined",onClick:()=>{window.open(t?.paymentLink?.donation_settings?.reference,"_blank")},children:s("customer.payout.viewReference")}),["open","uncollectible"].includes(t.status)&&!V&&(t.paymentMethod?.type==="stripe"?e.jsx(ce,{invoice:t,paymentMethod:t.paymentMethod,onSuccess:async()=>{N.close(),m({paying:!1}),await v()},onError:()=>{m({paying:!1})},onClose:()=>{m({paying:!1})},children:(_,J)=>e.jsx(S,{variant:"outlined",color:"primary",size:"small",sx:{borderColor:"divider"},disabled:u.paying||J,onClick:()=>{m({paying:!0}),_()},children:s("payment.customer.invoice.pay")})}):e.jsx(S,{variant:"outlined",color:"primary",size:"small",sx:{borderColor:"divider"},disabled:u.paying,onClick:z,children:s("payment.customer.invoice.pay")}))]})]}),t.status==="uncollectible"&&t.metadata?.slippage?.below_threshold&&e.jsx(P,{severity:"warning",sx:{mt:2},children:e.jsx(l,{variant:"body2",children:s("payment.customer.invoice.slippageExceededDetail",{currentRate:t.metadata.slippage.rate_at_invoice||"—",minRate:t.metadata.slippage.min_acceptable_rate||"—"})})}),e.jsxs(c,{sx:{mt:r?"0 !important":4,display:"flex",border:r?`1px solid ${f.palette.divider}`:"none",borderRadius:r?1:0,p:r?2:0,gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(x,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(x,{direction:"row",sx:{alignItems:"center",flexWrap:"wrap",gap:1},children:e.jsx(l,{variant:"h1",children:t.number})})}),e.jsxs(x,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},".info-metric-label":{mb:r?.5:1},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"},gap:{xs:1,sm:1,md:3}},children:[e.jsx(I,{label:s("common.status"),value:e.jsxs(x,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(E,{title:t.status==="void"?s("payment.customer.invoice.noPaymentRequired"):"",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(w,{label:t.status,color:le(t.status)})})}),t.status==="uncollectible"&&t.metadata?.slippage?.below_threshold&&e.jsx(E,{title:s("payment.customer.invoice.slippageExceededDetail",{currentRate:t.metadata.slippage.rate_at_invoice||"—",minRate:t.metadata.slippage.min_acceptable_rate||"—"}),arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(w,{label:s("payment.customer.invoice.slippageExceeded"),color:"warning"})})})]}),divider:!0}),t.subscription&&e.jsx(I,{label:s("admin.subscription.name"),value:e.jsx(fe,{to:`/customer/subscription/${t.subscription.id}`,children:e.jsx(l,{variant:"body1",sx:{color:"text.link"},children:t.subscription.description||t.subscription.id})}),divider:!0}),e.jsx(I,{label:s("common.createdAt"),value:b(t.created_at),divider:!0}),t.period_start>0&&t.period_end>0&&e.jsx(I,{label:s("admin.subscription.currentPeriod"),value:[b(t.period_start*1e3),b(t.period_end*1e3)].join(" ~ "),divider:!0})]})]}),e.jsx(k,{}),e.jsxs(c,{className:"section",sx:{containerType:"inline-size",border:r?_=>`1px solid ${_.palette.divider}`:"none",borderRadius:r?1:0,p:r?2:0},children:[e.jsx(l,{variant:"h3",className:"section-header",sx:{mb:3},children:s("payment.customer.invoice.details")}),e.jsxs(ke,{sx:{display:"grid",columnGap:16,gridTemplateColumns:{xs:"repeat(1, 1fr)",lg:"repeat(2, 1fr)"},"@container (min-width: 980px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:r?.5:1,flexDirection:{xs:"column",lg:"row"},alignItems:{xs:"flex-start",lg:"center"},"@container (min-width: 980px)":{flexDirection:"row",alignItems:"center"}},".currency-name":{color:"text.secondary",fontSize:14,lineHeight:1},".tx-link-text":{fontSize:14,lineHeight:1}},children:[e.jsx(h,{label:s("admin.invoice.billTo"),value:e.jsx(be,{customer:t.customer,linked:!1,size:"small"})}),e.jsx(h,{label:s("admin.invoice.from"),value:t.statement_descriptor||blocklet.appName}),e.jsx(h,{label:s("admin.invoice.description"),value:me(t,o)?.description}),t.status_transitions?.paid_at&&e.jsx(h,{label:s("admin.invoice.paidAt"),value:b(t.status_transitions.paid_at*1e3)}),e.jsx(h,{label:s("admin.paymentCurrency.name"),value:e.jsx(ge,{logo:t.paymentCurrency.logo,name:`${t.paymentCurrency.symbol} (${t.paymentMethod.name})`})}),(M||L)&&e.jsx(h,{label:s(L?"common.slashStakeAmount":"common.stakeAmount"),value:`${de(t.total,t.paymentCurrency.decimal)} ${t.paymentCurrency.symbol}`}),(!!t.paymentIntent?.payment_details?.ethereum||!!t.paymentIntent?.payment_details?.base)&&e.jsx(h,{label:s("common.txGas"),value:e.jsx(xe,{details:t.paymentIntent.payment_details,method:t.paymentMethod})}),B&&e.jsx(h,{label:s(M?"common.stakeTxHash":`common.${B?.arcblock?.type||"transfer"}TxHash`),value:e.jsx(A,{details:B,method:t.paymentMethod,mode:"customer"})}),t?.relatedInvoice&&e.jsx(h,{label:s("customer.invoice.relatedInvoice"),value:e.jsx(l,{variant:"body1",component:"a",onClick:()=>{window.open(se(pe(),`/customer/invoice/${t.relatedInvoice?.id}`),"_self")},sx:{color:"text.link",cursor:"pointer"},children:t.relatedInvoice?.number})})]})]}),T&&!j.isEmpty(t.paymentIntent?.beneficiaries)&&e.jsxs(e.Fragment,{children:[e.jsx(k,{}),e.jsx(c,{className:"section",children:e.jsx(l,{variant:"h3",className:"section-header",children:s("customer.invoice.donation")})}),e.jsx(c,{sx:{maxWidth:800},children:e.jsx(ue,{data:t?.paymentIntent?.beneficiaries,currency:t.paymentCurrency,totalAmount:t?.amount_paid})})]}),t?.relatedCreditGrants&&t.relatedCreditGrants.length>0&&e.jsx(ve,{grants:t.relatedCreditGrants}),!L&&!T&&e.jsxs(e.Fragment,{children:[!M&&e.jsxs(e.Fragment,{children:[e.jsx(k,{}),e.jsxs(c,{className:"section",children:[e.jsx(l,{variant:"h3",className:"section-header",sx:{mb:1.5},children:s("admin.invoiceItems")}),e.jsx(_e,{invoice:t,simple:!0})]})]}),e.jsx(k,{}),e.jsxs(c,{className:"section",children:[e.jsx(l,{variant:"h3",className:"section-header",children:s("admin.refunds")}),e.jsx(c,{className:"section-body",children:e.jsx(Me,{invoice_id:t.id,type:"table"})})]})]})]})}const Be=H(x)`
15
+ .invoice-summary-wrapper {
16
+ display: 'grid';
17
+ grid-template-columns: '50% 50%';
18
+ }
19
+ @media (max-width: ${({theme:s})=>s.breakpoints.values.md}px) {
20
+ .section-header {
21
+ font-size: 18px;
22
+ }
23
+ }
24
+ `;export{et as default};