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:"717822f90bd4b067a9c7ec7cb3a18f9ab9c65843",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:"0d658ca09d2719d7a2e644b4504d0b3ced56ccd4",style:{opacity:"0.5"},slot:"prefix"},h(this.currencyCode)),i("span",{key:"ee82dcb8f6bfd16ba0dac9e822a04b58dae7959c",slot:"suffix"},i("slot",{key:"2cfa1330e29679186a4f9966b2da27f68443dfc5",name:"suffix"},this.showCode&&(this===null||this===void 0?void 0:this.currencyCode)&&i("span",{key:"e262e091030baf65d3dcfbed7831658c541f839d",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-df511e08.entry.js.map