import{h,proxyCustomElement,HTMLElement,Fragment}from"@stencil/core/internal/client";import{s as state}from"./watchers5.js";import"./watchers4.js";import{s as state$1,c as availableMethodTypes,h as hasMultipleMethodChoices,g as getAvailableProcessor,b as availableManualPaymentMethods}from"./getters5.js";import{e as on,s as state$2}from"./mutations2.js";import{c as checkoutIsLocked}from"./getters2.js";import{l as lockCheckout,b as unLockCheckout}from"./mutations4.js";import{a as apiFetch}from"./fetch.js";import{c as createErrorNotice}from"./mutations3.js";import{d as defineCustomElement$9}from"./sc-alert2.js";import{d as defineCustomElement$8}from"./sc-block-ui2.js";import{d as defineCustomElement$7}from"./sc-card2.js";import{d as defineCustomElement$6}from"./sc-divider2.js";import{d as defineCustomElement$5}from"./sc-icon2.js";import{d as defineCustomElement$4}from"./sc-payment-method-choice2.js";import{d as defineCustomElement$3}from"./sc-payment-selected2.js";import{d as defineCustomElement$2}from"./sc-skeleton2.js";import{d as defineCustomElement$1}from"./sc-spinner2.js";import{a as addQueryArgs}from"./add-query-args.js";const listenTo=(e,t,s)=>on("set",((o,n,i)=>{if(o===e){if(Array.isArray(t)&&t.some((e=>JSON.stringify(null==n?void 0:n[e])!==JSON.stringify(null==i?void 0:i[e]))))return s(n,i);if("string"==typeof t){if(JSON.stringify(null==n?void 0:n[t])===JSON.stringify(null==i?void 0:i[t]))return;return s(null==n?void 0:n[t],null==i?void 0:i[t])}}})),ManualPaymentMethods=({methods:e})=>(e||[]).map((e=>h("sc-payment-method-choice",{"is-manual":!0,"processor-id":null==e?void 0:e.id},h("span",{slot:"summary"},null==e?void 0:e.name),h("sc-card",null,h("sc-payment-selected",{label:wp.i18n.sprintf(
// translators: Manual payment method.
wp.i18n.__("%s selected for check out.","surecart"),null==e?void 0:e.name)},h("div",{innerHTML:null==e?void 0:e.description})))))),MockProcessor=({processor:e})=>(null==e?void 0:e.id)?h("sc-payment-method-choice",{key:null==e?void 0:e.id,"processor-id":"mock"},h("span",{slot:"summary",class:"sc-payment-toggle-summary"},h("sc-icon",{name:"credit-card",style:{fontSize:"24px"},"aria-hidden":"true"}),h("span",null,wp.i18n.__("Test Processor","surecart"))),h("sc-card",null,h("sc-payment-selected",{label:wp.i18n.__("Test processor selected for check out.","surecart")},h("sc-icon",{slot:"icon",name:"credit-card","aria-hidden":"true"}),wp.i18n.__("This is a test payment processor used to simulate test transactions. It is only available in test mode.","surecart")))):null,scCheckoutMolliePaymentCss=":host{display:block}",ScCheckoutMolliePaymentStyle0=":host{display:block}",ScCheckoutMolliePayment=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.processorId=void 0,this.method=void 0,this.error=void 0,this.methods=void 0}componentWillLoad(){state.id="mollie",this.fetchMethods(),listenTo("checkout",["total_amount","currency","reusabled_payment_method_required","shipping_address"],(()=>this.fetchMethods()))}async fetchMethods(){var e;const t=state$2.checkout;if((null==t?void 0:t.currency)&&(null==t?void 0:t.total_amount))try{lockCheckout("methods");const s=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})});state$1.methods=(null==s?void 0:s.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,s;if(checkoutIsLocked("methods")&&!(null===(e=availableMethodTypes())||void 0===e?void 0:e.length))return this.renderLoading();if(!(null===(t=state$2.checkout)||void 0===t?void 0:t.currency))return this.renderLoading();if(!(null===(s=availableMethodTypes())||void 0===s?void 0:s.length))return h("sc-alert",{type:"warning",open:!0},wp.i18n.__("No available payment methods","surecart")," ");const o=hasMultipleMethodChoices()?"sc-toggles":"div";return h(Fragment,null,h(o,{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:wp.i18n.sprintf(wp.i18n.__("%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"}}),wp.i18n.__("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 style(){return":host{display:block}"}},[1,"sc-checkout-mollie-payment",{processorId:[1,"processor-id"],method:[1],error:[32],methods:[32]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-checkout-mollie-payment","sc-alert","sc-block-ui","sc-card","sc-divider","sc-icon","sc-payment-method-choice","sc-payment-selected","sc-skeleton","sc-spinner"].forEach((e=>{switch(e){case"sc-checkout-mollie-payment":customElements.get(e)||customElements.define(e,ScCheckoutMolliePayment);break;case"sc-alert":customElements.get(e)||defineCustomElement$9();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$8();break;case"sc-card":customElements.get(e)||defineCustomElement$7();break;case"sc-divider":customElements.get(e)||defineCustomElement$6();break;case"sc-icon":customElements.get(e)||defineCustomElement$5();break;case"sc-payment-method-choice":customElements.get(e)||defineCustomElement$4();break;case"sc-payment-selected":customElements.get(e)||defineCustomElement$3();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$2();break;case"sc-spinner":customElements.get(e)||defineCustomElement$1()}}))}export{MockProcessor as M,ScCheckoutMolliePayment as S,ManualPaymentMethods as a,defineCustomElement as d};