import{g as d,aD as h,aA as p,r as i,j as y,x as t,k as _}from"./main-TIUJvpaR.js";import{l as b}from"./index-U9JJOqTM.js";import{B as S}from"./billing-redirect-message-yudZRzMw.js";import{i as x}from"./use-billing-user-De1g37WG.js";import"./TaskAlt-S5LLkcsW.js";import"./skeleton-uSF3jNnm.js";const m="/billing";function j(){const{billing:{stripe_public_key:s}}=d(),l=h(),[g]=p(),r=g.get("setup_intent_client_secret"),[f,o]=i.useState(),n=i.useRef(!1);return i.useEffect(()=>{n.current||!r||(b(s).then(c=>{if(!c){o(u());return}c.retrieveSetupIntent(r).then(({setupIntent:e})=>{(e==null?void 0:e.status)==="succeeded"&&v(e.payment_method).then(()=>{x()}),o(u(e==null?void 0:e.status))})}),n.current=!0)},[s,r]),r?y.jsx(S,{config:f}):(l(m),null)}function u(s){switch(s){case"succeeded":return{...a,message:t("Payment method changed successfully!"),status:"success"};case"processing":return{...a,message:t("Your request is processing. We'll update you when your payment method is confirmed."),status:"success"};case"requires_payment_method":return{...a,message:t("Payment method confirmation failed. Please try another payment method."),status:"error"};default:return{...a,message:t("Something went wrong"),status:"error"}}}const a={link:m,buttonLabel:t("Go back")};function v(s){return _.post("billing/stripe/change-default-payment-method",{payment_method_id:s})}export{j as Component};
