import{c as t,M as s,V as i}from"./p-6e1ab235.js";import{i as h}from"./p-e4c4ea35.js";import{C as e}from"./p-2d0d575f.js";import{d as o}from"./p-f28a6074.js";import{r,s as n}from"./p-6c43d54a.js";import{w as a}from"./p-5e50dbb9.js";var u=function(t,s,i,h){var e,o=arguments.length,r=o<3?s:null===h?h=Object.getOwnPropertyDescriptor(s,i):h;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,s,i,h);else for(var n=t.length-1;n>=0;n--)(e=t[n])&&(r=(o<3?e(r):o>3?e(s,i,r):e(s,i))||r);return o>3&&r&&Object.defineProperty(s,i,r),r};class p extends i{constructor(){super(...arguments),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():e.notify(o.getSubject(this.host,r),t)}}componentDidRender(){e.notify(o.getSubject(this.host,n),{})}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(){a(this.host).then((()=>{this.formatValue(this.inputElement.value,"change")}))}formatValueAfterSetup(){a(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,e,o;const r=null!==(o=null===(e=(i=this.inputFormatStrategy).calculateCaretPosition)||void 0===e?void 0:e.call(i,t,s))&&void 0!==o?o:s;h(r)&&this.inputElement.setSelectionRange(r,r)}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)}}}}u([t()],p.prototype,"host",void 0),u([s("componentDidRender")],p.prototype,"componentDidRender",null);export{p as S}