text: "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("hassanreact/core");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function a(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&&l(e,t)}function u(e){return(u="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 c(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return s(e)}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function m(){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 p,f,h,v=function(n){a(b,e.Component);var l,u,p,f,h,v=(l=b,u=m(),function(){var e,t=d(l);if(u){var n=d(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return c(this,e)});function b(e){var t;return i(this,b),(t=v.call(this,e)).state={visible:!e.popup},t.onEnter=t.onEnter.bind(s(t)),t.onEntered=t.onEntered.bind(s(t)),t.onExit=t.onExit.bind(s(t)),t.onExited=t.onExited.bind(s(t)),t.onPanelClick=t.onPanelClick.bind(s(t)),t.menuRef=r.default.createRef(),t}return p=b,(f=[{key:"onPanelClick",value:function(e){this.props.popup&&t.OverlayService.emit("overlay-click",{originalEvent:e,target:this.target})}},{key:"onItemClick",value:function(e,t){t.disabled?e.preventDefault():(t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t}),this.props.popup&&this.hide(e))}},{key:"onItemKeyDown",value:function(e,t){var n=e.currentTarget.parentElement;switch(e.which){case 40:var r=this.findNextItem(n);r&&r.children[0].focus(),e.preventDefault();break;case 38:var i=this.findPrevItem(n);i&&i.children[0].focus(),e.preventDefault()}}},{key:"findNextItem",value:function(e){var n=e.nextElementSibling;return n?t.DomHandler.hasClass(n,"p-disabled")||!t.DomHandler.hasClass(n,"p-menuitem")?this.findNextItem(n):n:null}},{key:"findPrevItem",value:function(e){var n=e.previousElementSibling;return n?t.DomHandler.hasClass(n,"p-disabled")||!t.DomHandler.hasClass(n,"p-menuitem")?this.findPrevItem(n):n:null}},{key:"toggle",value:function(e){this.props.popup&&(this.state.visible?this.hide(e):this.show(e))}},{key:"show",value:function(e){var t=this;this.target=e.currentTarget;var n=e;this.setState({visible:!0},(function(){t.props.onShow&&t.props.onShow(n)}))}},{key:"hide",value:function(e){var t=this,n=e;this.setState({visible:!1},(function(){t.props.onHide&&t.props.onHide(n)}))}},{key:"onEnter",value:function(){t.ZIndexUtils.set("menu",this.menuRef.current,this.props.baseZIndex),t.DomHandler.absolutePosition(this.menuRef.current,this.target)}},{key:"onEntered",value:function(){this.bindDocumentListeners(),this.bindScrollListener()}},{key:"onExit",value:function(){this.target=null,this.unbindDocumentListeners(),this.unbindScrollListener()}},{key:"onExited",value:function(){t.ZIndexUtils.clear(this.menuRef.current)}},{key:"bindDocumentListeners",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.visible&&e.isOutsideClicked(t)&&e.hide(t)},document.addEventListener("click",this.documentClickListener)),this.documentResizeListener||(this.documentResizeListener=function(n){e.state.visible&&!t.DomHandler.isAndroid()&&e.hide(n)},window.addEventListener("resize",this.documentResizeListener))}},{key:"unbindDocumentListeners",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null),this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new t.ConnectedOverlayScrollHandler(this.target,(function(t){e.state.visible&&e.hide(t)}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"isOutsideClicked",value:function(e){return this.menuRef&&this.menuRef.current&&!(this.menuRef.current.isSameNode(e.target)||this.menuRef.current.contains(e.target))}},{key:"componentWillUnmount",value:function(){this.unbindDocumentListeners(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),t.ZIndexUtils.clear(this.menuRef.current)}},{key:"renderSubmenu",value:function(e,n){var i=this,o=t.classNames("p-submenu-header",{"p-disabled":e.disabled},e.className),s=e.items.map((function(e,t){return i.renderMenuitem(e,t)}));return r.default.createElement(r.default.Fragment,{key:e.label+"_"+n},r.default.createElement("li",{className:o,style:e.style,role:"presentation","aria-disabled":e.disabled},e.label),s)}},{key:"renderSeparator",value:function(e){return r.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator",role:"separator"})}},{key:"renderMenuitem",value:function(e,n){var i=this,o=t.classNames("p-menuitem",e.className),s=t.classNames("p-menuitem-link",{"p-disabled":e.disabled}),l=t.classNames("p-menuitem-icon",e.icon),a=e.disabled?null:0,u=r.default.createElement("a",{href:e.url||"#",className:s,role:"menuitem",target:e.target,onClick:function(t){return i.onItemClick(t,e)},onKeyDown:function(t){return i.onItemKeyDown(t,e)},tabIndex:a,"aria-disabled":e.disabled},e.icon&&r.default.createElement("span",{className:l}),e.label&&r.default.createElement("span",{className:"p-menuitem-text"},e.label));return e.template&&(u=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return i.onItemClick(t,e)},onKeyDown:function(t){return i.onItemKeyDown(t,e)},className:s,tabIndex:a,labelClassName:"p-menuitem-text",iconClassName:l,element:u,props:this.props})),r.default.createElement("li",{key:e.label+"_"+n,className:o,style:e.style,role:"none"},u)}},{key:"renderItem",value:function(e,t){return e.separator?this.renderSeparator(t):e.items?this.renderSubmenu(e,t):this.renderMenuitem(e,t)}},{key:"renderMenu",value:function(){var e=this;return this.props.model.map((function(t,n){return e.renderItem(t,n)}))}},{key:"renderElement",value:function(){if(this.props.model){var e=t.classNames("p-menu p-component",this.props.className,{"p-menu-overlay":this.props.popup}),n=this.renderMenu();return r.default.createElement(t.CSSTransition,{nodeRef:this.menuRef,classNames:"p-connected-overlay",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},r.default.createElement("div",{ref:this.menuRef,id:this.props.id,className:e,style:this.props.style,onClick:this.onPanelClick},r.default.createElement("ul",{className:"p-menu-list p-reset",role:"menu"},n)))}return null}},{key:"render",value:function(){var e=this.renderElement();return this.props.popup?r.default.createElement(t.Portal,{element:e,appendTo:this.props.appendTo}):e}}])&&o(p.prototype,f),h&&o(p,h),b}();h={id:null,model:null,popup:!1,style:null,className:null,autoZIndex:!0,baseZIndex:0,appendTo:null,transitionOptions:null,onShow:null,onHide:null},(f="defaultProps")in(p=v)?Object.defineProperty(p,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):p[f]=h,exports.Menu=v;
  