import{r as t,h as i}from"./p-e97fde0a.js";import{a as e}from"./p-d9fa04f9.js";import{a as s}from"./p-401e165e.js";import"./p-d3366af3.js";const o=":host{display:block}";const n=o;const d=class{constructor(i){t(this,i);this.country=undefined;this.successUrl=undefined;this.processorId=undefined;this.currency=undefined;this.liveMode=undefined;this.customerId=undefined;this.methods=[];this.loading=undefined;this.error=undefined;this.selectedMethodId=undefined;this.paymentIntent=undefined}componentWillLoad(){this.fetchMethods()}async createPaymentIntent(){var t,i,s,o;try{this.loading=true;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,refresh_status:true}});if((i=(t=this.paymentIntent.processor_data)===null||t===void 0?void 0:t.mollie)===null||i===void 0?void 0:i.checkout_url){window.location.assign((o=(s=this.paymentIntent.processor_data)===null||s===void 0?void 0:s.mollie)===null||o===void 0?void 0:o.checkout_url)}}catch(t){console.error(t);this.error=(t===null||t===void 0?void 0:t.message)||wp.i18n.__("Something went wrong","surecart");this.loading=false}}async fetchMethods(){var t,i,o;try{this.loading=true;const n=await e({path:s(`surecart/v1/processors/${this.processorId}/payment_method_types`,{amount:0,country:this.country,currency:this.currency,reusable:true})});this.methods=(n===null||n===void 0?void 0:n.data)||[];if((t=this.methods)===null||t===void 0?void 0:t.length){this.selectedMethodId=(o=(i=this.methods)===null||i===void 0?void 0:i[0])===null||o===void 0?void 0:o.id}}catch(t){this.error=(t===null||t===void 0?void 0:t.message)||wp.i18n.__("Something went wrong","surecart");console.error(t)}finally{this.loading=false}}handleSubmit(){this.createPaymentIntent()}renderLoading(){return i("sc-card",null,i("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),i("sc-skeleton",{style:{width:"30%",marginBottom:"0.5em"}}),i("sc-skeleton",{style:{width:"60%",marginBottom:"0.5em"}}))}render(){var t;if(this.loading&&!((t=this.methods)===null||t===void 0?void 0:t.length)){return this.renderLoading()}return i("sc-form",{onScFormSubmit:()=>this.handleSubmit(),style:{position:"relative"}},i("sc-toggles",{collapsible:false,theme:"container"},(this.methods||[]).map((t=>i("sc-toggle",{"show-control":true,shady:true,borderless:true,open:this.selectedMethodId===(t===null||t===void 0?void 0:t.id),onScShow:()=>this.selectedMethodId=t===null||t===void 0?void 0:t.id},i("span",{slot:"summary",class:"sc-payment-toggle-summary"},!!(t===null||t===void 0?void 0:t.image)&&i("img",{src:t===null||t===void 0?void 0:t.image}),i("span",null,t===null||t===void 0?void 0:t.description)),i("sc-card",null,i("sc-payment-selected",{label:wp.i18n.sprintf(wp.i18n.__("%s selected.","surecart"),t===null||t===void 0?void 0:t.description)},!!(t===null||t===void 0?void 0:t.image)&&i("img",{slot:"icon",src:t===null||t===void 0?void 0:t.image,style:{width:"32px"}}),wp.i18n.__("Another step will appear after submitting your order to add this payment method.","surecart"))))))),i("sc-button",{type:"primary",submit:true,full:true,loading:this.loading},wp.i18n.__("Add Payment Method","surecart")),this.loading&&i("sc-block-ui",{"z-index":9,style:{"--sc-block-ui-opacity":"0.75"}}))}};d.style=n;export{d as sc_mollie_add_method};
//# sourceMappingURL=p-a4c8c943.entry.js.map