"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/csstransition"),i=require("primereact/ripple"),r=require("primereact/portal"),o=require("primereact/api");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=u(e),l=u(o);function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ni.width-t.DomHandler.calculateScrollbarWidth()?-1*r+"px":o+"px"}},{key:"onEnter",value:function(){this.position()}},{key:"isActive",value:function(){return this.props.root||!this.props.resetMenu}},{key:"componentDidUpdate",value:function(){this.isActive()&&this.position()}},{key:"renderSeparator",value:function(e){return s.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenu",value:function(e){return e.items?s.default.createElement(u,{model:e.items,resetMenu:e!==this.state.activeItem,onLeafClick:this.props.onLeafClick}):null}},{key:"renderMenuitem",value:function(e,n){var r=this,o=this.state.activeItem===e,u=t.classNames("p-menuitem",{"p-menuitem-active":o},e.className),l=t.classNames("p-menuitem-link",{"p-disabled":e.disabled}),a=t.classNames("p-menuitem-icon",e.icon),c="p-submenu-icon pi pi-angle-right",m=e.icon&&s.default.createElement("span",{className:a}),f=e.label&&s.default.createElement("span",{className:"p-menuitem-text"},e.label),d=e.items&&s.default.createElement("span",{className:c}),p=this.renderSubmenu(e),h=s.default.createElement("a",{href:e.url||"#",className:l,target:e.target,onClick:function(t){return r.onItemClick(t,e,n)},role:"menuitem","aria-haspopup":null!=e.items,"aria-disabled":e.disabled},m,f,d,s.default.createElement(i.Ripple,null));e.template&&(h=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return r.onItemClick(t,e,n)},className:l,labelClassName:"p-menuitem-text",iconClassName:a,submenuIconClassName:c,element:h,props:this.props,active:o}));return s.default.createElement("li",{key:e.label+"_"+n,role:"none",className:u,style:e.style,onMouseEnter:function(t){return r.onItemMouseEnter(t,e)}},h,p)}},{key:"renderItem",value:function(e,t){return e.separator?this.renderSeparator(t):this.renderMenuitem(e,t)}},{key:"renderMenu",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return e.renderItem(t,n)})):null}},{key:"render",value:function(){var e=t.classNames({"p-submenu-list":!this.props.root}),i=this.renderMenu(),r=this.isActive();return s.default.createElement(n.CSSTransition,{nodeRef:this.submenuRef,classNames:"p-contextmenusub",in:r,timeout:{enter:0,exit:0},unmountOnExit:!0,onEnter:this.onEnter},s.default.createElement("ul",{ref:this.submenuRef,className:e},i))}}],[{key:"getDerivedStateFromProps",value:function(e,t){return!0===e.resetMenu?{activeItem:null}:null}}]),u}();y(L,"defaultProps",{model:null,root:!1,className:null,resetMenu:!1,onLeafClick:null});var x=function(i){p(u,e.Component);var o=E(u);function u(e){var t;return a(this,u),(t=o.call(this,e)).state={visible:!1,reshow:!1,resetMenu:!1},t.onMenuClick=t.onMenuClick.bind(f(t)),t.onLeafClick=t.onLeafClick.bind(f(t)),t.onMenuMouseEnter=t.onMenuMouseEnter.bind(f(t)),t.onEnter=t.onEnter.bind(f(t)),t.onEntered=t.onEntered.bind(f(t)),t.onExit=t.onExit.bind(f(t)),t.onExited=t.onExited.bind(f(t)),t.menuRef=s.default.createRef(),t}return m(u,[{key:"onMenuClick",value:function(){this.setState({resetMenu:!1})}},{key:"onMenuMouseEnter",value:function(){this.setState({resetMenu:!1})}},{key:"show",value:function(e){var t=this;e instanceof Event||e.persist(),e.stopPropagation(),e.preventDefault(),this.currentEvent=e,this.state.visible?this.setState({reshow:!0}):this.setState({visible:!0},(function(){t.props.onShow&&t.props.onShow(t.currentEvent)}))}},{key:"hide",value:function(e){var t=this;e instanceof Event||e.persist(),this.currentEvent=e,this.setState({visible:!1,reshow:!1},(function(){t.props.onHide&&t.props.onHide(t.currentEvent)}))}},{key:"onEnter",value:function(){this.props.autoZIndex&&t.ZIndexUtils.set("menu",this.menuRef.current,l.default.autoZIndex,this.props.baseZIndex||l.default.zIndex.menu),this.position(this.currentEvent)}},{key:"onEntered",value:function(){this.bindDocumentListeners()}},{key:"onExit",value:function(){this.currentEvent=null,this.unbindDocumentListeners()}},{key:"onExited",value:function(){t.ZIndexUtils.clear(this.menuRef.current)}},{key:"position",value:function(e){if(e){var n=e.pageX+1,i=e.pageY+1,r=this.menuRef.current.offsetParent?this.menuRef.current.offsetWidth:t.DomHandler.getHiddenElementOuterWidth(this.menuRef.current),o=this.menuRef.current.offsetParent?this.menuRef.current.offsetHeight:t.DomHandler.getHiddenElementOuterHeight(this.menuRef.current),u=t.DomHandler.getViewport();n+r-document.body.scrollLeft>u.width&&(n-=r),i+o-document.body.scrollTop>u.height&&(i-=o),n