import e,{Component as t}from"react";import{DomHandler as n,classNames as i,ObjectUtils as r,ZIndexUtils as o}from"primereact/utils";import{CSSTransition as s}from"primereact/csstransition";import{Ripple as u}from"primereact/ripple";import{Portal as c}from"primereact/portal";import l from"primereact/api";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(e,t){for(var n=0;ni.width-n.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(t){return e.createElement("li",{key:"separator_"+t,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenu",value:function(t){return t.items?e.createElement(l,{model:t.items,resetMenu:t!==this.state.activeItem,onLeafClick:this.props.onLeafClick}):null}},{key:"renderMenuitem",value:function(t,n){var o=this,s=this.state.activeItem===t,c=i("p-menuitem",{"p-menuitem-active":s},t.className),l=i("p-menuitem-link",{"p-disabled":t.disabled}),a=i("p-menuitem-icon",t.icon),m="p-submenu-icon pi pi-angle-right",f=t.icon&&e.createElement("span",{className:a}),p=t.label&&e.createElement("span",{className:"p-menuitem-text"},t.label),d=t.items&&e.createElement("span",{className:m}),h=this.renderSubmenu(t),v=e.createElement("a",{href:t.url||"#",className:l,target:t.target,onClick:function(e){return o.onItemClick(e,t,n)},role:"menuitem","aria-haspopup":null!=t.items,"aria-disabled":t.disabled},f,p,d,e.createElement(u,null));t.template&&(v=r.getJSXElement(t.template,t,{onClick:function(e){return o.onItemClick(e,t,n)},className:l,labelClassName:"p-menuitem-text",iconClassName:a,submenuIconClassName:m,element:v,props:this.props,active:s}));return e.createElement("li",{key:t.label+"_"+n,role:"none",className:c,style:t.style,onMouseEnter:function(e){return o.onItemMouseEnter(e,t)}},v,h)}},{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 t=i({"p-submenu-list":!this.props.root}),n=this.renderMenu(),r=this.isActive();return e.createElement(s,{nodeRef:this.submenuRef,classNames:"p-contextmenusub",in:r,timeout:{enter:0,exit:0},unmountOnExit:!0,onEnter:this.onEnter},e.createElement("ul",{ref:this.submenuRef,className:t},n))}}],[{key:"getDerivedStateFromProps",value:function(e,t){return!0===e.resetMenu?{activeItem:null}:null}}]),l}();E(R,"defaultProps",{model:null,root:!1,className:null,resetMenu:!1,onLeafClick:null});var x=function(r){h(m,t);var u=k(m);function m(t){var n;return a(this,m),(n=u.call(this,t)).state={visible:!1,reshow:!1,resetMenu:!1},n.onMenuClick=n.onMenuClick.bind(p(n)),n.onLeafClick=n.onLeafClick.bind(p(n)),n.onMenuMouseEnter=n.onMenuMouseEnter.bind(p(n)),n.onEnter=n.onEnter.bind(p(n)),n.onEntered=n.onEntered.bind(p(n)),n.onExit=n.onExit.bind(p(n)),n.onExited=n.onExited.bind(p(n)),n.menuRef=e.createRef(),n}return f(m,[{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&&o.set("menu",this.menuRef.current,l.autoZIndex,this.props.baseZIndex||l.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(){o.clear(this.menuRef.current)}},{key:"position",value:function(e){if(e){var t=e.pageX+1,i=e.pageY+1,r=this.menuRef.current.offsetParent?this.menuRef.current.offsetWidth:n.getHiddenElementOuterWidth(this.menuRef.current),o=this.menuRef.current.offsetParent?this.menuRef.current.offsetHeight:n.getHiddenElementOuterHeight(this.menuRef.current),s=n.getViewport();t+r-document.body.scrollLeft>s.width&&(t-=r),i+o-document.body.scrollTop>s.height&&(i-=o),t