import e,{createRef as t,Component as n}from"react";import{DomHandler as r,ZIndexUtils as i,ConnectedOverlayScrollHandler as o,ObjectUtils as s,classNames as l}from"primereact/utils";import{tip as p}from"primereact/tooltip";import{InputText as a}from"primereact/inputtext";import{CSSTransition as u}from"primereact/csstransition";import c,{localeOption as h}from"primereact/api";import{OverlayService as f}from"primereact/overlayservice";import{Portal as d}from"primereact/portal";function y(){return y=Object.assign||function(e){for(var t=1;t0||null!=this.props.defaultValue&&this.props.defaultValue.toString().length>0||this.inputRef&&this.inputRef.current&&r.hasClass(this.inputRef.current,"p-filled")}},{key:"getInputType",value:function(){return this.state.unmasked?"text":"password"}},{key:"updateLabels",value:function(){if(this.state.meter){var e=null;switch(this.state.meter.strength){case"weak":e=this.weakLabel();break;case"medium":e=this.mediumLabel();break;case"strong":e=this.strongLabel()}e&&this.state.infoText!==e&&this.setState({infoText:e})}else{var t=this.promptLabel();this.state.infoText!==t&&this.setState({infoText:t})}}},{key:"onPanelClick",value:function(e){this.props.feedback&&f.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"onMaskToggle",value:function(){this.setState((function(e){return{unmasked:!e.unmasked}}))}},{key:"showOverlay",value:function(){this.updateLabels(),this.setState({overlayVisible:!0})}},{key:"hideOverlay",value:function(){this.setState({overlayVisible:!1})}},{key:"alignOverlay",value:function(){this.inputRef&&this.inputRef.current&&r.alignOverlay(this.overlayRef.current,this.inputRef.current.parentElement,this.props.appendTo||c.appendTo)}},{key:"onOverlayEnter",value:function(){i.set("overlay",this.overlayRef.current,c.autoZIndex,c.zIndex.overlay),this.alignOverlay()}},{key:"onOverlayEntered",value:function(){this.bindScrollListener(),this.bindResizeListener(),this.props.onShow&&this.props.onShow()}},{key:"onOverlayExit",value:function(){this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onOverlayExited",value:function(){i.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"onFocus",value:function(e){var t=this;e.persist(),this.setState({focused:!0},(function(){t.props.feedback&&t.showOverlay(),t.props.onFocus&&t.props.onFocus(e)}))}},{key:"onBlur",value:function(e){var t=this;e.persist(),this.setState({focused:!1},(function(){t.props.feedback&&t.hideOverlay(),t.props.onBlur&&t.props.onBlur(e)}))}},{key:"onKeyup",value:function(e){var t=this,n=e.keyCode||e.which;if(this.props.feedback){var r=null,i=null;switch(this.testStrength(e.target.value)){case 1:r=this.weakLabel(),i={strength:"weak",width:"33.33%"};break;case 2:r=this.mediumLabel(),i={strength:"medium",width:"66.66%"};break;case 3:r=this.strongLabel(),i={strength:"strong",width:"100%"};break;default:r=this.promptLabel(),i=null}this.setState({meter:i,infoText:r},(function(){n&&!t.state.overlayVisible&&t.showOverlay()}))}this.props.onKeyUp&&this.props.onKeyUp(e)}},{key:"onInput",value:function(e,t){this.props.onInput&&this.props.onInput(e,t),this.props.onChange||(e.target.value.length>0?r.addClass(this.container,"p-inputwrapper-filled"):r.removeClass(this.container,"p-inputwrapper-filled"))}},{key:"testStrength",value:function(e){var t=0;return this.strongCheckRegExp.test(e)?t=3:this.mediumCheckRegExp.test(e)?t=2:e.length&&(t=1),t}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new o(this.inputEl,(function(){e.state.overlayVisible&&e.hideOverlay()}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindResizeListener",value:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.state.overlayVisible&&!r.isTouchDevice()&&e.hideOverlay()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"updateInputRef",value:function(){var e=this.props.inputRef;e&&("function"==typeof e?e(this.inputRef.current):e.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(e){e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(L({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip()),e.mediumRegex!==this.props.mediumRegex&&(this.mediumCheckRegExp=new RegExp(this.props.mediumRegex)),e.strongRegex!==this.props.strongRegex&&(this.strongCheckRegExp=new RegExp(this.props.strongRegex)),!this.isFilled()&&r.hasClass(this.container,"p-inputwrapper-filled")&&r.removeClass(this.container,"p-inputwrapper-filled")}},{key:"componentWillUnmount",value:function(){this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=null),i.clear(this.overlayRef.current)}},{key:"renderTooltip",value:function(){this.tooltip=p({target:this.inputEl,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderIcon",value:function(){if(this.props.toggleMask){var t=this.state.unmasked?"pi pi-eye-slash":"pi pi-eye",n=e.createElement("i",{className:t,onClick:this.onMaskToggle});return this.props.icon&&(n=s.getJSXElement(this.props.icon,{onClick:this.onMaskToggle,className:t,element:n,props:this.props})),n}return null}},{key:"renderPanel",value:function(){var t=l("p-password-panel p-component",this.props.panelClassName),n=this.state.meter||{strength:"",width:"0%"},r=n.strength,i=n.width,o=s.getJSXElement(this.props.header,this.props),p=s.getJSXElement(this.props.footer,this.props),a=this.props.content?s.getJSXElement(this.props.content,this.props):e.createElement(e.Fragment,null,e.createElement("div",{className:"p-password-meter"},e.createElement("div",{className:"p-password-strength ".concat(r),style:{width:i}})),e.createElement("div",{className:"p-password-info"},this.state.infoText));return e.createElement(d,{element:e.createElement(u,{nodeRef:this.overlayRef,classNames:"p-connected-overlay",in:this.state.overlayVisible,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited},e.createElement("div",{ref:this.overlayRef,className:t,style:this.props.panelStyle,onClick:this.onPanelClick},o,a,p)),appendTo:this.props.appendTo})}},{key:"render",value:function(){var t=this,n=l("p-password p-component p-inputwrapper",{"p-inputwrapper-filled":this.isFilled(),"p-inputwrapper-focus":this.state.focused,"p-input-icon-right":this.props.toggleMask},this.props.className),r=l("p-password-input",this.props.inputClassName),i=this.getInputType(),o=s.findDiffKeys(this.props,j.defaultProps),p=this.renderIcon(),u=this.renderPanel();return e.createElement("div",{ref:function(e){return t.container=e},id:this.props.id,className:n,style:this.props.style},e.createElement(a,y({ref:this.inputRef,id:this.props.inputId},o,{type:i,className:r,style:this.props.inputStyle,onFocus:this.onFocus,onBlur:this.onBlur,onKeyUp:this.onKeyup,onInput:this.onInput})),p,u)}}])&&v(x.prototype,P),T&&v(x,T),Object.defineProperty(x,"prototype",{writable:!1}),j}();R(P,"defaultProps",{id:null,inputId:null,inputRef:null,promptLabel:null,weakLabel:null,mediumLabel:null,strongLabel:null,mediumRegex:"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})",strongRegex:"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})",feedback:!0,toggleMask:!1,appendTo:null,header:null,content:null,footer:null,icon:null,tooltip:null,tooltipOptions:null,style:null,className:null,inputStyle:null,inputClassName:null,panelStyle:null,panelClassName:null,transitionOptions:null,onInput:null,onShow:null,onHide:null});export{P as Password};