import{proxyCustomElement,HTMLElement,createEvent,h,Host}from"@stencil/core/internal/client";import"./fetch.js";import{o as openWormhole}from"./consumer.js";import{d as defineCustomElement$a}from"./sc-alert2.js";import{d as defineCustomElement$9}from"./sc-block-ui2.js";import{d as defineCustomElement$8}from"./sc-form-control2.js";import{d as defineCustomElement$7}from"./sc-icon2.js";import{d as defineCustomElement$6}from"./sc-input2.js";import{d as defineCustomElement$5}from"./sc-price-input2.js";import{d as defineCustomElement$4}from"./sc-skeleton2.js";import{d as defineCustomElement$3}from"./sc-spinner2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";import{a as apiFetch}from"./index4.js";const scCustomOrderPriceInputCss="sc-custom-order-price-input{display:block}",ScCustomOrderPriceInputStyle0=scCustomOrderPriceInputCss,ScCustomOrderPriceInput$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.scUpdateLineItem=createEvent(this,"scUpdateLineItem",7),this.priceId=void 0,this.price=void 0,this.loading=!1,this.busy=!1,this.label=void 0,this.placeholder=void 0,this.required=void 0,this.help=void 0,this.showCode=void 0,this.lineItems=[],this.fetching=!1,this.lineItem=void 0}handleBlur(e){var t;const s=parseInt(e.target.value);isNaN(s)||(null===(t=this.lineItem)||void 0===t?void 0:t.ad_hoc_amount)!==s&&this.scUpdateLineItem.emit({price_id:this.priceId,quantity:1,ad_hoc_amount:s})}handleLineItemsChange(){var e;(null===(e=this.lineItems)||void 0===e?void 0:e.length)&&(this.lineItem=(this.lineItems||[]).find((e=>e.price.id===this.priceId)))}componentDidLoad(){this.price||this.fetchPrice()}async fetchPrice(){if(this.priceId)try{this.fetching=!0,this.price=await apiFetch({path:`surecart/v1/prices/${this.priceId}`})}catch(e){}finally{this.fetching=!1}}renderEmpty(){var e;return(null===(e=null===window||void 0===window?void 0:window.wp)||void 0===e?void 0:e.blocks)?h("sc-alert",{type:"danger",open:!0,style:{margin:"0px"}},wp.i18n.__("This price has been archived.","surecart")):h(Host,{style:{display:"none"}})}render(){var e,t,s,i,n,o;return this.loading||this.fetching?h("div",null,h("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),h("sc-skeleton",{style:{width:"100%"}})):!(null===(e=null==this?void 0:this.price)||void 0===e?void 0:e.id)||(null===(t=this.price)||void 0===t?void 0:t.archived)?this.renderEmpty():h("div",{class:"sc-custom-order-price-input"},h("sc-price-input",{"currency-code":(null===(s=this.price)||void 0===s?void 0:s.currency)||"usd",label:this.label,min:null===(i=null==this?void 0:this.price)||void 0===i?void 0:i.ad_hoc_min_amount,max:null===(n=null==this?void 0:this.price)||void 0===n?void 0:n.ad_hoc_max_amount,placeholder:this.placeholder,required:this.required,value:null===(o=this.lineItem)||void 0===o?void 0:o.ad_hoc_amount.toString(),"show-code":this.showCode,help:this.help}),this.busy&&h("sc-block-ui",{style:{zIndex:"9"}}))}static get watchers(){return{lineItems:["handleLineItemsChange"]}}static get style(){return ScCustomOrderPriceInputStyle0}},[0,"sc-custom-order-price-input",{priceId:[513,"price-id"],price:[1040],loading:[4],busy:[4],label:[1],placeholder:[1],required:[4],help:[1],showCode:[516,"show-code"],lineItems:[16],fetching:[32],lineItem:[32]},[[0,"scBlur","handleBlur"]],{lineItems:["handleLineItemsChange"]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-custom-order-price-input","sc-alert","sc-block-ui","sc-form-control","sc-icon","sc-input","sc-price-input","sc-skeleton","sc-spinner","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-custom-order-price-input":customElements.get(e)||customElements.define(e,ScCustomOrderPriceInput$1);break;case"sc-alert":customElements.get(e)||defineCustomElement$a();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$9();break;case"sc-form-control":customElements.get(e)||defineCustomElement$8();break;case"sc-icon":customElements.get(e)||defineCustomElement$7();break;case"sc-input":customElements.get(e)||defineCustomElement$6();break;case"sc-price-input":customElements.get(e)||defineCustomElement$5();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$4();break;case"sc-spinner":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}openWormhole(ScCustomOrderPriceInput$1,["busy","lineItems"],!1);const ScCustomOrderPriceInput=ScCustomOrderPriceInput$1,defineCustomElement=defineCustomElement$1;export{ScCustomOrderPriceInput,defineCustomElement};