import{c as M,d as S}from"./chunk-U46PHU2W.js";import{q as D,s as V}from"./chunk-V2ECYACM.js";import{E as R,m as w}from"./chunk-JPHJ3OD7.js";import{Fb as c,Ib as v,Jd as m,Ka as h,Kd as o,Na as r,Nd as b,Od as g,Sb as f,Za as u,Zd as y,be as C,ya as l,zb as p}from"./chunk-WL5U2YIT.js";import{e as N}from"./chunk-ADEKKGI2.js";var L,F=N(()=>{C();S();R();V();C();L=(()=>{let n=class n{constructor(){this.showClear=g(!1,{transform:y}),this.onClear=b(),this.el=l(u),this.renderer=l(v),this.ngModel=l(w,{optional:!0}),this.destroyRef=l(h),this.pInputText=l(D),this.clearIcon=r(null),this.wrapper=r(null),this.nativeValue=r(""),this.isDisabled=r(!1),this.isReadonly=r(!1),this.isFluid=r(!1),this.ngModelValue=this.ngModel?M(this.ngModel.valueChanges,{initialValue:this.ngModel.value??""}):null,this.isVisible=m(()=>this.showClear()?!!(this.ngModelValue?.()??this.nativeValue())&&!this.isDisabled()&&!this.isReadonly():!1),c(()=>{this.setupClearButton(),this.ngModel||this.setupNativeValueListener(),this.observeInputState()}),o(()=>{let e=this.clearIcon(),t=this.isVisible();e&&this.renderer.setStyle(e,"display",t?"block":"none")}),o(()=>{let e=this.wrapper(),t=this.isFluid();e&&(t?this.renderer.addClass(e,"w-full"):this.renderer.removeClass(e,"w-full"))})}setupClearButton(){let e=this.el.nativeElement,t=this.renderer.parentNode(e),s=this.renderer.createElement("span");this.renderer.setAttribute(s,"class","relative inline-block"),this.renderer.insertBefore(t,s,e),this.renderer.removeChild(t,e),this.renderer.appendChild(s,e),this.renderer.addClass(e,"pr-8");let i=this.renderer.createElement("i");this.renderer.setAttribute(i,"class","pi pi-times absolute top-1/2 -translate-y-1/2 right-3 cursor-pointer"),this.renderer.setStyle(i,"--p-icon-size","12px",p.DashCase),this.renderer.setStyle(i,"color","var(--text-400)"),this.renderer.setStyle(i,"display","none");let E=this.renderer.listen(i,"click",()=>this.onClearHandler());this.destroyRef.onDestroy(E),this.renderer.appendChild(s,i),this.clearIcon.set(i),this.wrapper.set(s),this.destroyRef.onDestroy(()=>{let d=this.renderer.parentNode(s);d&&this.renderer.removeChild(d,s)})}setupNativeValueListener(){this.nativeValue.set(this.el.nativeElement.value);let e=this.renderer.listen(this.el.nativeElement,"input",()=>{this.nativeValue.set(this.el.nativeElement.value)});this.destroyRef.onDestroy(e)}observeInputState(){let e=this.el.nativeElement;this.syncState(e);let t=new MutationObserver(()=>this.syncState(e));t.observe(e,{attributes:!0,attributeFilter:["disabled","readonly"]}),this.destroyRef.onDestroy(()=>t.disconnect())}syncState(e){this.isDisabled.set(e.disabled),this.isReadonly.set(e.readOnly),this.isFluid.set(this.pInputText.hasFluid||e.classList.contains("w-full"))}onClearHandler(){this.ngModel?.control?this.ngModel.control.setValue(""):this.el.nativeElement.value="",this.el.nativeElement.dispatchEvent(new Event("input")),this.onClear.emit()}};n.\u0275fac=function(t){return new(t||n)},n.\u0275dir=f({type:n,selectors:[["input","pInputText","","showClear",""]],inputs:{showClear:[1,"showClear"]},outputs:{onClear:"onClear"}});let a=n;return a})()});export{L as a,F as b};
