import{r as i,c as t,h as s,H as e}from"./p-9add63ef.js";import"./p-8dccb656.js";import{o as n}from"./p-4773325d.js";import{a as d}from"./p-259c3935.js";import"./p-401e165e.js";import"./p-d3366af3.js";const r="sc-custom-order-price-input{display:block}";const o=r;const h=class{constructor(s){i(this,s);this.scUpdateLineItem=t(this,"scUpdateLineItem",7);this.priceId=undefined;this.price=undefined;this.loading=false;this.busy=false;this.label=undefined;this.placeholder=undefined;this.required=undefined;this.help=undefined;this.showCode=undefined;this.lineItems=[];this.fetching=false;this.lineItem=undefined}handleBlur(i){var t;const s=parseInt(i.target.value);if(isNaN(s))return;if(((t=this.lineItem)===null||t===void 0?void 0:t.ad_hoc_amount)===s)return;this.scUpdateLineItem.emit({price_id:this.priceId,quantity:1,ad_hoc_amount:s})}handleLineItemsChange(){var i;if(!((i=this.lineItems)===null||i===void 0?void 0:i.length))return;this.lineItem=(this.lineItems||[]).find((i=>i.price.id===this.priceId))}componentDidLoad(){if(!this.price){this.fetchPrice()}}async fetchPrice(){if(!this.priceId)return;try{this.fetching=true;this.price=await d({path:`surecart/v1/prices/${this.priceId}`})}catch(i){}finally{this.fetching=false}}renderEmpty(){var i;if((i=window===null||window===void 0?void 0:window.wp)===null||i===void 0?void 0:i.blocks){return s("sc-alert",{type:"danger",open:true,style:{margin:"0px"}},wp.i18n.__("This price has been archived.","surecart"))}return s(e,{style:{display:"none"}})}render(){var i,t,e,n,d,r;if(this.loading||this.fetching){return s("div",null,s("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),s("sc-skeleton",{style:{width:"100%"}}))}if(!((i=this===null||this===void 0?void 0:this.price)===null||i===void 0?void 0:i.id)||((t=this.price)===null||t===void 0?void 0:t.archived))return this.renderEmpty();return s("div",{class:"sc-custom-order-price-input"},s("sc-price-input",{"currency-code":((e=this.price)===null||e===void 0?void 0:e.currency)||"usd",label:this.label,min:(n=this===null||this===void 0?void 0:this.price)===null||n===void 0?void 0:n.ad_hoc_min_amount,max:(d=this===null||this===void 0?void 0:this.price)===null||d===void 0?void 0:d.ad_hoc_max_amount,placeholder:this.placeholder,required:this.required,value:(r=this.lineItem)===null||r===void 0?void 0:r.ad_hoc_amount.toString(),"show-code":this.showCode,help:this.help}),this.busy&&s("sc-block-ui",{style:{zIndex:"9"}}))}static get watchers(){return{lineItems:["handleLineItemsChange"]}}};n(h,["busy","lineItems"],false);h.style=o;export{h as sc_custom_order_price_input};
//# sourceMappingURL=p-b253bba0.entry.js.map