import{D as S,j as o,a6 as B,T,bm as k}from"./vendor-mui-core-CKKG_1TN.js";import{o as M}from"./vendor-arcblock-BCP2x3BR.js";import{V as P,a_ as F}from"./vendor-ux-DjXlxcvL.js";import{r as w}from"./vendor-react-CTtPmzVP.js";import{v as E}from"./vendor-hooks-DQAdyHrE.js";import{b$ as D,ax as I}from"./index-BEfIUbZC.js";import"./vendor-utils-CUs2ebe7.js";import"./lottie-web-4koyQiv_.js";const{Elements:R,PaymentElement:z,useElements:N,useStripe:$,loadStripe:O,LinkAuthenticationElement:V}=globalThis.__STRIPE_COMPONENTS__,W=k("div")`
  width: 100%;
  opacity: 0;
  transition: opacity 300ms ease;
  &.visible {
    opacity: 1;
  }
`;function q({clientSecret:c,intentType:u,customer:e,mode:f,onConfirm:b,returnUrl:g="",submitButtonText:x=""}){const r=$(),l=N(),{t:d}=P(),m=S(),[t,n]=E({message:"",confirming:!1,loaded:!1,showBillingForm:!1,isTransitioning:!1,paymentMethod:"card"}),_=a=>{const i=a.value?.type;(i==="google_pay"||i==="apple_pay")&&!s(e.address)&&!t.showBillingForm?(n({isTransitioning:!0}),setTimeout(()=>{n({isTransitioning:!1,paymentMethod:i,showBillingForm:!0})},300)):n({showBillingForm:!1,paymentMethod:i,isTransitioning:!1})},s=a=>a&&a.line1&&a.city&&a.state&&a.postal_code&&a.country;w.useEffect(()=>{if(!r||!c)return;r[u==="payment_intent"?"retrievePaymentIntent":"retrieveSetupIntent"](c).then(({paymentIntent:i,setupIntent:h})=>{switch((i||h)?.status){case"succeeded":n({message:d("paymentCredit.preparePayMessage.succeeded")});break;case"processing":n({message:d("paymentCredit.preparePayMessage.processing")});break}})},[r,c]);const y=w.useCallback(async a=>{if(a.preventDefault(),!(!r||!l))try{n({confirming:!0,message:""});const i=u==="payment_intent"?"confirmPayment":"confirmSetup",{error:h}=await l.submit();if(h){n({confirming:!1});return}const{error:p,paymentIntent:j,setupIntent:v}=await r[i]({elements:l,redirect:"if_required",confirmParams:{return_url:g||window.location.href,...t.showBillingForm?{}:{payment_method_data:{billing_details:{name:e.name,phone:e.phone,email:e.email,address:{...e.address||{},country:e.address?.country||"us",line1:e.address?.line1||"",line2:e.address?.line2||"",city:e.address?.city||"",state:e.address?.state||"",postal_code:e.address?.postal_code||"00000"}}}}}}),C=j||v;if(C?.status==="canceled"||C?.status==="requires_payment_method"){n({confirming:!1});return}if(n({confirming:!1}),p){if(p.type==="validation_error")return;n({message:p.message});return}b()}catch(i){console.error(i),n({confirming:!1,message:i.message})}},[e,u,r,t.showBillingForm,g]);return o.jsxs(A,{onSubmit:y,children:[(!t.paymentMethod||["link","card"].includes(t.paymentMethod))&&o.jsx(V,{options:{defaultValues:{email:e.email}}}),o.jsx(W,{className:t.isTransitioning?"":"visible",children:o.jsx(z,{options:{layout:"auto",fields:{billingDetails:t.showBillingForm?"auto":"never"},readOnly:t.confirming,defaultValues:{billingDetails:{name:e.name,phone:e.phone,email:e.email,address:e.address}},appearance:{theme:m.palette.mode,variables:{colorPrimary:m.palette.primary.main,colorBackground:m.palette.background.paper,colorText:m.palette.text.primary,colorDanger:m.palette.error.main,borderRadius:"4px"}}},onChange:_,onReady:()=>n({loaded:!0})})}),(!r||!l||!t.loaded)&&o.jsx(M,{relative:"parent",children:o.jsx(B,{})}),r&&l&&t.loaded&&o.jsx(I,{fullWidth:!0,sx:{mt:2,mb:1,borderRadius:0,fontSize:"0.875rem"},type:"submit",disabled:t.confirming||!t.loaded,loading:t.confirming,variant:"contained",color:"primary",size:"large",children:x||d("payment.checkout.continue",{action:d(`payment.checkout.${f}`)})}),t.message&&o.jsx(T,{sx:{mt:1,color:"error.main"},children:t.message})]})}const A=k("form")`
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 320px;
`;function Z({clientSecret:c,intentType:u,publicKey:e,mode:f,customer:b,onConfirm:g,onCancel:x,returnUrl:r="",title:l="",submitButtonText:d=""}){const m=O(e),{isMobile:t}=D(),{t:n,locale:_}=P(),s=S(),[y,a]=E({open:!0,closable:!0}),i=(h,p)=>{p!=="backdropClick"&&(a({open:!1}),x())};return o.jsx(F,{title:l||n("payment.checkout.cardPay",{action:n(`payment.checkout.${f}`)}),showCloseButton:y.closable,open:y.open,onClose:i,disableEscapeKeyDown:!0,sx:{".StripeElement":{minWidth:t?"100%":"500px",py:1},form:{justifyContent:"flex-start"},".StripeElement--focus":{borderColor:s.palette.primary.main},".StripeElement--invalid":{borderColor:s.palette.error.main},".StripeElement--complete":{borderColor:s.palette.success.main}},PaperProps:{style:{minWidth:t?"100%":"500px"}},children:o.jsx(R,{options:{clientSecret:c,locale:_==="zh"?"zh-CN":"en",appearance:{theme:s.palette.mode,variables:{colorPrimary:s.palette.primary.main,colorBackground:s.palette.background.paper,colorText:s.palette.text.primary,colorDanger:s.palette.error.main}}},stripe:m,children:o.jsx(q,{clientSecret:c,intentType:u,mode:f,customer:b,onConfirm:g,returnUrl:r,submitButtonText:d})})})}export{Z as default};
