text: import e,{Component as t}from"react";import{UniqueComponentId as n,ConnectedOverlayScrollHandler as i,DomHandler as r,OverlayService as o,ZIndexUtils as s,Ripple as l,classNames as a,CSSTransition as c,Portal as u}from"hassanreact/core";function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&p(e,t)}function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function m(e,t){if(t&&("object"===v(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return d(e)}function b(e){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function k(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var E,C,L,g=function(p){y(w,t);var v,E,C,L,g,R=(v=w,E=k(),function(){var e,t=b(v);if(E){var n=b(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return m(this,e)});function w(t){var i;return h(this,w),(i=R.call(this,t)).state={visible:!1},i.onCloseClick=i.onCloseClick.bind(d(i)),i.onPanelClick=i.onPanelClick.bind(d(i)),i.onEnter=i.onEnter.bind(d(i)),i.onEntered=i.onEntered.bind(d(i)),i.onExit=i.onExit.bind(d(i)),i.onExited=i.onExited.bind(d(i)),i.attributeSelector=n(),i.overlayRef=e.createRef(),i}return C=w,(L=[{key:"bindDocumentClickListener",value:function(){var e=this;!this.documentClickListener&&this.props.dismissable&&(this.documentClickListener=function(t){!e.isPanelClicked&&e.isOutsideClicked(t.target)&&e.hide(),e.isPanelClicked=!1},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new i(this.target,(function(){e.state.visible&&e.hide()}))),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.visible&&!r.isAndroid()&&e.hide()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"isOutsideClicked",value:function(e){return this.overlayRef&&this.overlayRef.current&&!(this.overlayRef.current.isSameNode(e)||this.overlayRef.current.contains(e))}},{key:"hasTargetChanged",value:function(e,t){return null!=this.target&&this.target!==(t||e.currentTarget||e.target)}},{key:"onCloseClick",value:function(e){this.hide(),e.preventDefault()}},{key:"onPanelClick",value:function(e){this.isPanelClicked=!0,o.emit("overlay-click",{originalEvent:e,target:this.target})}},{key:"toggle",value:function(e,t){var n=this;this.state.visible?(this.hide(),this.hasTargetChanged(e,t)&&(this.target=t||e.currentTarget||e.target,setTimeout((function(){n.show(e,n.target)}),200))):this.show(e,t)}},{key:"show",value:function(e,t){var n=this;this.target=t||e.currentTarget||e.target,this.state.visible?this.align():this.setState({visible:!0},(function(){n.overlayEventListener=function(e){n.isOutsideClicked(e.target)||(n.isPanelClicked=!0)},o.on("overlay-click",n.overlayEventListener)}))}},{key:"hide",value:function(){var e=this;this.setState({visible:!1},(function(){o.off("overlay-click",e.overlayEventListener),e.overlayEventListener=null}))}},{key:"onEnter",value:function(){s.set("overlay",this.overlayRef.current),this.overlayRef.current.setAttribute(this.attributeSelector,""),this.align()}},{key:"onEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.props.onShow&&this.props.onShow()}},{key:"onExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onExited",value:function(){s.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"align",value:function(){if(this.target){r.absolutePosition(this.overlayRef.current,this.target);var e=r.getOffset(this.overlayRef.current),t=r.getOffset(this.target),n=0;e.left<t.left&&(n=t.left-e.left),this.overlayRef.current.style.setProperty("--overlayArrowLeft","".concat(n,"px")),e.top<t.top&&r.addClass(this.overlayRef.current,"p-overlaypanel-flipped")}}},{key:"createStyle",value:function(){if(!this.styleElement){this.styleElement=document.createElement("style"),document.head.appendChild(this.styleElement);var e="";for(var t in this.props.breakpoints)e+="\n                    @media screen and (max-width: ".concat(t,") {\n                        .p-overlaypanel[").concat(this.attributeSelector,"] {\n                            width: ").concat(this.props.breakpoints[t]," !important;\n                        }\n                    }\n                ");this.styleElement.innerHTML=e}}},{key:"componentDidMount",value:function(){this.props.breakpoints&&this.createStyle()}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null),this.overlayEventListener&&(o.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null),s.clear(this.overlayRef.current)}},{key:"renderCloseIcon",value:function(){return this.props.showCloseIcon?e.createElement("button",{type:"button",className:"p-overlaypanel-close p-link",onClick:this.onCloseClick,"aria-label":this.props.ariaCloseLabel},e.createElement("span",{className:"p-overlaypanel-close-icon pi pi-times"}),e.createElement(l,null)):null}},{key:"renderElement",value:function(){var t=a("p-overlaypanel p-component",this.props.className),n=this.renderCloseIcon();return e.createElement(c,{nodeRef:this.overlayRef,classNames:"p-overlaypanel",in:this.state.visible,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExit:this.onExit,onExited:this.onExited},e.createElement("div",{ref:this.overlayRef,id:this.props.id,className:t,style:this.props.style,onClick:this.onPanelClick},e.createElement("div",{className:"p-overlaypanel-content"},this.props.children),n))}},{key:"render",value:function(){var t=this.renderElement();return e.createElement(u,{element:t,appendTo:this.props.appendTo})}}])&&f(C.prototype,L),g&&f(C,g),w}();L={id:null,dismissable:!0,showCloseIcon:!1,style:null,className:null,appendTo:null,breakpoints:null,ariaCloseLabel:"close",transitionOptions:null,onShow:null,onHide:null},(C="defaultProps")in(E=g)?Object.defineProperty(E,C,{value:L,enumerable:!0,configurable:!0,writable:!0}):E[C]=L;export{g as OverlayPanel};
  