import{r as t,c as s,h as i,a as e}from"./p-e97fde0a.js";import{c as h}from"./p-4df6e0c5.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:"8bddd9c31d391ab901f055f913ee3a7ee77d1799",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:"4895d79ec1a84d9cf3d444149f6c8c7ac3b91cc2",style:{opacity:"0.5"},slot:"prefix"},h(this.currencyCode)),i("span",{key:"b6d8f75f28b978991bfee8a9085fbbfacd0ae6bc",slot:"suffix"},i("slot",{key:"9f9674cc9a387658eceb01a7654906e201b58444",name:"suffix"},this.showCode&&(this===null||this===void 0?void 0:this.currencyCode)&&i("span",{key:"0f55aa2439908cd89659d34688ef03d9299a5a15",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-66df5bda.entry.js.map