import{aD as t,aE as s,aF as i,aH as h,aR as e,aZ as o,a_ as a,ax as n}from"./p-BTBbFFOR.js";import{w as u}from"./p-BuolKY1B.js";var r=function(t,s,i,h){var e,o=arguments.length,a=o<3?s:null===h?h=Object.getOwnPropertyDescriptor(s,i):h;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,s,i,h);else for(var n=t.length-1;n>=0;n--)(e=t[n])&&(a=(o<3?e(a):o>3?e(s,i,a):e(s,i))||a);return o>3&&a&&Object.defineProperty(s,i,a),a};class c extends i{constructor(){super(),this.onFocus=t=>{if(this.host&&this.host.value){const s=this.host.value;t.target.value!==s&&(this.inputElement.value=s)}},this.onBlur=t=>{this.blurFormatStrategy&&this.formatValue(t.target.value,"blur")},this.onKeyDown=t=>{const s=t.target,i=s.value,h=s.selectionStart;this.inputFormatStrategy&&(this.formatValue(i,"input",{caretPosition:"insertFromPaste"===t.inputType?void 0:h}),this.updateInputCaretPosition(i,h))},this.onPaste=t=>{this.disableCopyPaste?t.preventDefault():h.notify(e.getSubject(this.host,o),t)}}componentDidRender(){h.notify(e.getSubject(this.host,a),{})}setup(){this.destroy();const t=this.getInputElementRef();t&&(this.inputElement=t,this.inputFormatStrategy=this.getInputModeStrategy(),this.blurFormatStrategy=this.getBlurModeStrategy(),this.formatValueAfterSetup(),this.inputFormatStrategy&&(this.inputElement.addEventListener("input",this.onKeyDown,{capture:!0}),this.inputElement.addEventListener("paste",this.onPaste,{capture:!0})),this.blurFormatStrategy&&(this.inputElement.addEventListener("blur",this.onBlur,{capture:!0}),this.inputElement.addEventListener("focus",this.onFocus,{capture:!0})))}destroy(){this.inputElement&&(this.inputFormatStrategy&&(this.inputElement.removeEventListener("input",this.onKeyDown,{capture:!0}),this.inputElement.removeEventListener("paste",this.onPaste,{capture:!0})),this.blurFormatStrategy&&(this.inputElement.removeEventListener("blur",this.onBlur,{capture:!0}),this.inputElement.removeEventListener("focus",this.onFocus,{capture:!0})))}formatValueAfterValueChange(){u(this.host).then((()=>{this.formatValue(this.inputElement.value,"change")}))}formatValueAfterSetup(){u(this.host).then((()=>{this.formatValue(this.inputElement.value,"init")}))}isOnFocus(){return this.inputElement.matches(":focus")}updateNativeInputValue(t,s){s!==t&&(this.inputElement.value=s)}updateComponentValue(t,s){s!==t&&(this.host.value=s)}updateInputCaretPosition(t,s){var i,h,e;const o=null!==(e=null===(h=(i=this.inputFormatStrategy).calculateCaretPosition)||void 0===h?void 0:h.call(i,t,s))&&void 0!==e?e:s;n(o)&&this.inputElement.setSelectionRange(o,o)}formatValue(t,s,i){const h=!this.isOnFocus(),e=null==i?void 0:i.caretPosition;if(this.inputFormatStrategy){if(this.inputFormatStrategy.canFormat(s,"component")){const s=this.inputFormatStrategy.format(t);this.updateComponentValue(t,s)}if(this.inputFormatStrategy.canFormat(s,"native-input")){const s=this.inputFormatStrategy.format(t,{caretPosition:e});this.updateNativeInputValue(t,s)}}if(this.blurFormatStrategy&&h){if(this.blurFormatStrategy.canFormat(s,"component",{isBlurred:h})){const s=this.blurFormatStrategy.format(t);this.updateComponentValue(t,s)}if(this.blurFormatStrategy.canFormat(s,"native-input",{isBlurred:h})){const s=this.blurFormatStrategy.format(t);this.updateNativeInputValue(t,s)}}}}r([t()],c.prototype,"host",void 0),r([s("componentDidRender")],c.prototype,"componentDidRender",null);export{c as S}