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:"b328887f403197a57d135c7cce3597f13b197c2b",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:"b0f2d9d485a02daad98ec6b6924a3b600b6931ec",style:{opacity:"0.5"},slot:"prefix"},h(this.currencyCode)),i("span",{key:"1928eddff6ba481206b07dcb4dde2e9fa16ff61e",slot:"suffix"},i("slot",{key:"1ec7381ec4e06e5b248e90f5d001416c89c48a5d",name:"suffix"},this.showCode&&(this===null||this===void 0?void 0:this.currencyCode)&&i("span",{key:"eae58ef3d84e0ace4d267c5facdd53f927da7fd8",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-6867fb7a.entry.js.map