import{ZIndexUtils as e,DomHandler as t,ConnectedOverlayScrollHandler as s}from"primevue/utils";import i from"primevue/overlayeventbus";import n from"primevue/inputtext";import{resolveComponent as l,openBlock as r,createBlock as a,createVNode as o,mergeProps as p,createCommentVNode as d,Teleport as u,Transition as h,withCtx as c,renderSlot as m,toDisplayString as g}from"vue";var y={name:"Password",emits:["update:modelValue"],inheritAttrs:!1,props:{modelValue:String,promptLabel:{type:String,default:null},mediumRegex:{type:String,default:"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"},strongRegex:{type:String,default:"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})"},weakLabel:{type:String,default:null},mediumLabel:{type:String,default:null},strongLabel:{type:String,default:null},feedback:{type:Boolean,default:!0},appendTo:{type:String,default:"body"},toggleMask:{type:Boolean,default:!1},hideIcon:{type:String,default:"pi pi-eye-slash"},showIcon:{type:String,default:"pi pi-eye"},inputClass:String,inputStyle:null,style:null,class:String,panelClass:String},data:()=>({overlayVisible:!1,meter:null,infoText:null,focused:!1,unmasked:!1}),mediumCheckRegExp:null,strongCheckRegExp:null,resizeListener:null,scrollHandler:null,overlay:null,mounted(){this.infoText=this.promptText,this.mediumCheckRegExp=new RegExp(this.mediumRegex),this.strongCheckRegExp=new RegExp(this.strongRegex)},beforeUnmount(){this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.overlay&&(e.clear(this.overlay),this.overlay=null)},methods:{onOverlayEnter(t){e.set("overlay",t,this.$primevue.config.zIndex.overlay),this.alignOverlay(),this.bindScrollListener(),this.bindResizeListener()},onOverlayLeave(){this.unbindScrollListener(),this.unbindResizeListener(),this.overlay=null},onOverlayAfterLeave(t){e.clear(t)},alignOverlay(){this.appendDisabled?t.relativePosition(this.overlay,this.$refs.input.$el):(this.overlay.style.minWidth=t.getOuterWidth(this.$refs.input.$el)+"px",t.absolutePosition(this.overlay,this.$refs.input.$el))},testStrength(e){let t=0;return this.strongCheckRegExp.test(e)?t=3:this.mediumCheckRegExp.test(e)?t=2:e.length&&(t=1),t},onInput(e){this.$emit("update:modelValue",e.target.value)},onFocus(){this.focused=!0,this.feedback&&(this.overlayVisible=!0)},onBlur(){this.focused=!1,this.feedback&&(this.overlayVisible=!1)},onKeyUp(e){if(this.feedback){let t=e.target.value,s=null,i=null;switch(this.testStrength(t)){case 1:s=this.weakText,i={strength:"weak",width:"33.33%"};break;case 2:s=this.mediumText,i={strength:"medium",width:"66.66%"};break;case 3:s=this.strongText,i={strength:"strong",width:"100%"};break;default:s=this.promptText,i=null}this.meter=i,this.infoText=s,this.overlayVisible||(this.overlayVisible=!0)}},bindScrollListener(){this.scrollHandler||(this.scrollHandler=new s(this.$refs.input.$el,(()=>{this.overlayVisible&&(this.overlayVisible=!1)}))),this.scrollHandler.bindScrollListener()},unbindScrollListener(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener(){this.resizeListener||(this.resizeListener=()=>{this.overlayVisible&&(this.overlayVisible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},overlayRef(e){this.overlay=e},onMaskToggle(){this.unmasked=!this.unmasked},onOverlayClick(e){i.emit("overlay-click",{originalEvent:e,target:this.$el})}},computed:{containerClass(){return["p-password p-component p-inputwrapper",this.class,{"p-inputwrapper-filled":this.filled,"p-inputwrapper-focus":this.focused,"p-input-icon-right":this.toggleMask}]},inputFieldClass(){return["p-password-input",this.inputClass,{"p-disabled":this.$attrs.disabled}]},panelStyleClass(){return["p-password-panel p-component",this.panelClass,{"p-input-filled":"filled"===this.$primevue.config.inputStyle,"p-ripple-disabled":!1===this.$primevue.config.ripple}]},toggleIconClass(){return this.unmasked?this.hideIcon:this.showIcon},strengthClass(){return`p-password-strength ${this.meter?this.meter.strength:""}`},inputType(){return this.unmasked?"text":"password"},filled(){return null!=this.modelValue&&this.modelValue.toString().length>0},weakText(){return this.weakLabel||this.$primevue.config.locale.weak},mediumText(){return this.mediumLabel||this.$primevue.config.locale.medium},strongText(){return this.strongLabel||this.$primevue.config.locale.strong},promptText(){return this.promptLabel||this.$primevue.config.locale.passwordPrompt},appendDisabled(){return"self"===this.appendTo},appendTarget(){return this.appendDisabled?null:this.appendTo}},components:{PInputText:n}};const v={class:"p-password-meter"},f={className:"p-password-info"};!function(e,t){void 0===t&&(t={});var s=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===s&&i.firstChild?i.insertBefore(n,i.firstChild):i.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}("\n.p-password {\n    position: relative;\n    display: -webkit-inline-box;\n    display: -ms-inline-flexbox;\n    display: inline-flex;\n}\n.p-password-panel {\n    position: absolute;\n}\n.p-password .p-password-panel {\n    min-width: 100%;\n}\n.p-password-meter {\n    height: 10px;\n}\n.p-password-strength {\n    height: 100%;\n    width: 0%;\n    -webkit-transition: width 1s ease-in-out;\n    transition: width 1s ease-in-out;\n}\n.p-fluid .p-password {\n    display: -webkit-box;\n    display: -ms-flexbox;\n    display: flex;\n}\n"),y.render=function(e,t,s,i,n,y){const b=l("PInputText");return r(),a("div",{class:y.containerClass,style:s.style},[o(b,p({ref:"input",class:y.inputFieldClass,style:s.inputStyle,type:y.inputType,value:s.modelValue,onInput:y.onInput,onFocus:y.onFocus,onBlur:y.onBlur,onKeyup:y.onKeyUp},e.$attrs),null,16,["class","style","type","value","onInput","onFocus","onBlur","onKeyup"]),s.toggleMask?(r(),a("i",{key:0,class:y.toggleIconClass,onClick:t[1]||(t[1]=(...e)=>y.onMaskToggle&&y.onMaskToggle(...e))},null,2)):d("",!0),(r(),a(u,{to:y.appendTarget,disabled:y.appendDisabled},[o(h,{name:"p-connected-overlay",onEnter:y.onOverlayEnter,onLeave:y.onOverlayLeave,onAfterLeave:y.onOverlayAfterLeave},{default:c((()=>[n.overlayVisible?(r(),a("div",{key:0,ref:y.overlayRef,class:y.panelStyleClass,onClick:t[2]||(t[2]=(...e)=>y.onOverlayClick&&y.onOverlayClick(...e))},[m(e.$slots,"header"),m(e.$slots,"content",{},(()=>[o("div",v,[o("div",{class:y.strengthClass,style:{width:n.meter?n.meter.width:""}},null,6)]),o("div",f,g(n.infoText),1)])),m(e.$slots,"footer")],2)):d("",!0)])),_:3},8,["onEnter","onLeave","onAfterLeave"])],8,["to","disabled"]))],6)};export default y;
