import{r as t,h as s}from"./p-dfbe004d.js";import{_ as o,s as i}from"./p-8415f806.js";import"./p-fd56940f.js";import{a as e}from"./p-7393a06c.js";import{a as l}from"./p-1c2e2695.js";import"./p-9a7a47e8.js";const n=class{constructor(s){t(this,s),this.methods=[]}componentWillLoad(){this.fetchMethods()}async createPaymentIntent(){var t,s,i,l;try{this.loading=!0,this.error="",this.paymentIntent=await e({method:"POST",path:"surecart/v1/payment_intents",data:{processor_type:"mollie",live_mode:this.liveMode,customer_id:this.customerId,return_url:this.successUrl,payment_method_type:this.selectedMethodId,currency:this.currency}}),console.log(this.paymentIntent),(null===(s=null===(t=this.paymentIntent.processor_data)||void 0===t?void 0:t.mollie)||void 0===s?void 0:s.checkout_url)&&window.location.assign(null===(l=null===(i=this.paymentIntent.processor_data)||void 0===i?void 0:i.mollie)||void 0===l?void 0:l.checkout_url)}catch(t){console.error(t),this.error=(null==t?void 0:t.message)||o("Something went wrong","surecart"),this.loading=!1}}async fetchMethods(){var t,s,i;try{this.loading=!0;const o=await e({path:l(`surecart/v1/processors/${this.processorId}/payment_method_types`,{amount:0,country:this.country,currency:this.currency,reusable:!0})});this.methods=(null==o?void 0:o.data)||[],(null===(t=this.methods)||void 0===t?void 0:t.length)&&(this.selectedMethodId=null===(i=null===(s=this.methods)||void 0===s?void 0:s[0])||void 0===i?void 0:i.id)}catch(t){this.error=(null==t?void 0:t.message)||o("Something went wrong","surecart"),console.error(t)}finally{this.loading=!1}}handleSubmit(){this.createPaymentIntent()}renderLoading(){return s("sc-card",null,s("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),s("sc-skeleton",{style:{width:"30%",marginBottom:"0.5em"}}),s("sc-skeleton",{style:{width:"60%",marginBottom:"0.5em"}}))}render(){var t;return this.loading&&!(null===(t=this.methods)||void 0===t?void 0:t.length)?this.renderLoading():s("sc-form",{onScFormSubmit:()=>this.handleSubmit(),style:{position:"relative"}},s("sc-toggles",{collapsible:!1,theme:"container"},(this.methods||[]).map((t=>s("sc-toggle",{"show-control":!0,shady:!0,borderless:!0,open:this.selectedMethodId===(null==t?void 0:t.id),onScShow:()=>this.selectedMethodId=null==t?void 0:t.id},s("span",{slot:"summary",class:"sc-payment-toggle-summary"},!!(null==t?void 0:t.image)&&s("img",{src:null==t?void 0:t.image}),s("span",null,null==t?void 0:t.description)),s("sc-card",null,s("sc-payment-selected",{label:i(o("%s selected.","surecart"),null==t?void 0:t.description)},!!(null==t?void 0:t.image)&&s("img",{slot:"icon",src:null==t?void 0:t.image,style:{width:"32px"}}),o("Another step will appear after submitting your order to add this payment method.","surecart"))))))),s("sc-button",{type:"primary",submit:!0,full:!0,loading:this.loading},o("Add Payment Method","surecart")),this.loading&&s("sc-block-ui",{"z-index":9,style:{"--sc-block-ui-opacity":"0.75"}}))}};n.style=":host{display:block}";export{n as sc_mollie_add_method}