import{Fragment,h}from"@stencil/core";import{sprintf,__}from"@wordpress/i18n";import{addQueryArgs}from"@wordpress/url";import{state as selectedProcessor}from"../../../../store/selected-processor/index";import{state as processorsState}from"../../../../store/processors/index";import{hasMultipleMethodChoices,availableMethodTypes,availableManualPaymentMethods,getAvailableProcessor}from"../../../../store/processors/getters";import{state as checkoutState}from"../../../../store/checkout/index";import{listenTo}from"../../../../store/checkout/functions";import{checkoutIsLocked}from"../../../../store/checkout/getters";import{lockCheckout,unLockCheckout}from"../../../../store/checkout/mutations";import apiFetch from"../../../../functions/fetch";import{ManualPaymentMethods}from"../payment/ManualPaymentMethods";import{createErrorNotice}from"../../../../store/notices/mutations";import{MockProcessor}from"../payment/MockProcessor";export class ScCheckoutMolliePayment{constructor(){this.processorId=void 0,this.method=void 0,this.error=void 0,this.methods=void 0}componentWillLoad(){selectedProcessor.id="mollie",this.fetchMethods(),listenTo("checkout",["total_amount","subtotal_amount","currency","reusabled_payment_method_required","shipping_address"],(()=>this.fetchMethods()))}async fetchMethods(){var e;const t=checkoutState.checkout;if(null==t?void 0:t.currency)try{lockCheckout("methods");const o=await apiFetch({path:addQueryArgs(`surecart/v1/processors/${this.processorId}/payment_method_types`,{amount:null==t?void 0:t.total_amount,country:(null===(e=null==t?void 0:t.shipping_address)||void 0===e?void 0:e.country)||"us",currency:null==t?void 0:t.currency,...(null==t?void 0:t.reusable_payment_method_required)?{reusable:null==t?void 0:t.reusable_payment_method_required}:{},per_page:100})});processorsState.methods=(null==o?void 0:o.data)||[]}catch(e){createErrorNotice(e),console.error(e)}finally{unLockCheckout("methods")}}renderLoading(){return h("sc-card",null,h("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),h("sc-skeleton",{style:{width:"30%",marginBottom:"0.5em"}}),h("sc-skeleton",{style:{width:"60%",marginBottom:"0.5em"}}))}render(){var e,t,o;if(checkoutIsLocked("methods")&&!(null===(e=availableMethodTypes())||void 0===e?void 0:e.length))return this.renderLoading();if(!(null===(t=checkoutState.checkout)||void 0===t?void 0:t.currency))return this.renderLoading();if(!(null===(o=availableMethodTypes())||void 0===o?void 0:o.length))return h("sc-alert",{type:"warning",open:!0},__("No available payment methods","surecart")," ");const r=hasMultipleMethodChoices()?"sc-toggles":"div";return h(Fragment,null,h(r,{collapsible:!1,theme:"container"},(availableMethodTypes()||[]).map((e=>h("sc-payment-method-choice",{"processor-id":"mollie","method-id":null==e?void 0:e.id,key:null==e?void 0:e.id},h("span",{slot:"summary",class:"sc-payment-toggle-summary"},!!(null==e?void 0:e.image)&&h("img",{src:null==e?void 0:e.image,"aria-hidden":"true"}),h("span",null,null==e?void 0:e.description)),h("sc-card",null,h("sc-payment-selected",{label:sprintf(__("%s selected for check out.","surecart"),null==e?void 0:e.description)},!!(null==e?void 0:e.image)&&h("img",{slot:"icon",src:null==e?void 0:e.image,style:{width:"32px"}}),__("Another step will appear after submitting your order to complete your purchase details.","surecart")))))),h(MockProcessor,{processor:getAvailableProcessor("mock")}),h(ManualPaymentMethods,{methods:availableManualPaymentMethods()})),!!checkoutIsLocked("methods")&&h("sc-block-ui",{class:"busy-block-ui","z-index":9,style:{"--sc-block-ui-opacity":"0.4"}}))}static get is(){return"sc-checkout-mollie-payment"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-checkout-mollie-payment.css"]}}static get styleUrls(){return{$:["sc-checkout-mollie-payment.css"]}}static get properties(){return{processorId:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"processor-id",reflect:!1},method:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"method",reflect:!1}}}static get states(){return{error:{},methods:{}}}}