import{r as t,c as s,h as i,a as e}from"./p-9add63ef.js";import{c as h}from"./p-610295e2.js";import{F as a}from"./p-8b323bfb.js";import{m as n,i as d}from"./p-3f6362a4.js";const r=":host{display:block}";const o=r;const u=class{constructor(i){t(this,i);this.scChange=s(this,"scChange",7);this.scInput=s(this,"scInput",7);this.scFocus=s(this,"scFocus",7);this.scBlur=s(this,"scBlur",7);this.size="medium";this.name=undefined;this.value="";this.pill=false;this.label=undefined;this.showLabel=true;this.help="";this.clearable=false;this.placeholder=undefined;this.disabled=false;this.readonly=false;this.minlength=undefined;this.maxlength=undefined;this.max=undefined;this.min=undefined;this.required=false;this.invalid=false;this.autofocus=undefined;this.hasFocus=undefined;this.currencyCode=undefined;this.showCode=undefined}async reportValidity(){const t=this.input.shadowRoot.querySelector("input");t.setCustomValidity("");if(this.min&&this.value&&parseFloat(this.value)<this.min){this.invalid=true;t.setCustomValidity(wp.i18n.sprintf(wp.i18n.__("Must be %d or more.","surecart"),n(this.min,this.currencyCode).toString()))}if(this.max&&this.value&&parseFloat(this.value)>this.max){this.invalid=true;t.setCustomValidity(wp.i18n.sprintf(wp.i18n.__("Must be %d or less.","surecart"),n(this.max,this.currencyCode).toString()))}return t.reportValidity()}async triggerFocus(t){return this.input.triggerFocus(t)}async setCustomValidity(t){this.input.setCustomValidity(t)}async triggerBlur(){return this.input.blur()}handleFocusChange(){var t,s,i,e;this.hasFocus?(s=(t=this.input)===null||t===void 0?void 0:t.focus)===null||s===void 0?void 0:s.call(t):(e=(i=this.input)===null||i===void 0?void 0:i.blur)===null||e===void 0?void 0:e.call(i)}handleChange(){this.updateValue();this.scChange.emit()}handleInput(){this.updateValue();this.scInput.emit()}updateValue(){const t=parseFloat(this.input.value);if(isNaN(t)){this.value="";return}const s=d(this.currencyCode)?t:(t*100).toFixed(2);this.value=s.toString();this.setCustomValidity("")}componentDidLoad(){this.handleFocusChange();this.formController=new a(this.el).addFormData();document.addEventListener("wheel",(()=>{this.input.triggerBlur()}))}disconnectedCallback(){var t;(t=this.formController)===null||t===void 0?void 0:t.removeFormData()}getFormattedValue(){if(!this.value)return"";const t=parseFloat(this.value);if(isNaN(t))return"";return n(t,this.currencyCode).toString()}render(){return i("sc-input",{key:"e62d968a6c813a1012e852b2b6c602405c830a7c",exportparts:"base, input, form-control, label, help-text, prefix, suffix",size:this.size,label:this.label,showLabel:this.showLabel,help:this.help,ref:t=>this.input=t,type:"text",name:this.name,disabled:this.disabled,readonly:this.readonly,required:this.required,placeholder:this.placeholder,minlength:this.minlength,maxlength:this.maxlength,min:!!this.min?this.min/100:0,step:.01,max:!!this.max?this.max/100:null,autofocus:this.autofocus,inputmode:"decimal",onScChange:()=>this.handleChange(),onScInput:()=>this.handleInput(),onScBlur:()=>this.scBlur.emit(),onScFocus:()=>this.scFocus.emit(),pattern:"^\\d*(\\.\\d{0,2})?$",value:this.getFormattedValue()},i("span",{key:"700d7fd67e20a134af7ce8244fe8e7da6a953c33",style:{opacity:"0.5"},slot:"prefix"},h(this.currencyCode)),i("span",{key:"f68a39cdad7b71b40480ae80f4eec6cf1174d128",slot:"suffix"},i("slot",{key:"df3334dfc5938d85c5f365637bdd657de580f82d",name:"suffix"},this.showCode&&(this===null||this===void 0?void 0:this.currencyCode)&&i("span",{key:"b9a4736d1c0b2fb3b1716a3fff4b9cff937a29a5",style:{opacity:"0.5"}},this.currencyCode.toUpperCase()))))}get el(){return e(this)}static get watchers(){return{hasFocus:["handleFocusChange"]}}};u.style=o;export{u as sc_price_input};
//# sourceMappingURL=p-d25c38a2.entry.js.map