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