"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/csstransition");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=r(e);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n-1:this.state.activeItem===e)}},{key:"renderSeparator",value:function(e){return a.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator"})}},{key:"renderSubmenu",value:function(e,r){var i=t.classNames("p-toggleable-content",{"p-toggleable-content-collapsed":!r}),s=a.default.createRef();return e.items?a.default.createElement(n.CSSTransition,{nodeRef:s,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:r,unmountOnExit:!0},a.default.createElement("div",{ref:s,className:i},a.default.createElement(l,{model:e.items,multiple:this.props.multiple}))):null}},{key:"renderMenuitem",value:function(e,n){var r=this,i=this.isItemActive(e),l=t.classNames("p-menuitem",e.className),s=t.classNames("p-menuitem-link",{"p-disabled":e.disabled}),o=t.classNames("p-menuitem-icon",e.icon),u=t.classNames("p-panelmenu-icon pi pi-fw",{"pi-angle-right":!i,"pi-angle-down":i}),c=e.icon&&a.default.createElement("span",{className:o}),p=e.label&&a.default.createElement("span",{className:"p-menuitem-text"},e.label),m=e.items&&a.default.createElement("span",{className:u}),f=this.renderSubmenu(e,i),d=a.default.createElement("a",{href:e.url||"#",className:s,target:e.target,onClick:function(t){return r.onItemClick(t,e,n)},role:"menuitem","aria-disabled":e.disabled},m,c,p);e.template&&(d=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return r.onItemClick(t,e,n)},className:s,labelClassName:"p-menuitem-text",iconClassName:o,submenuIconClassName:u,element:d,props:this.props,leaf:!e.items,active:i}));return a.default.createElement("li",{key:e.label+"_"+n,className:l,style:e.style,role:"none"},d,f)}},{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.className),n=this.renderMenu();return a.default.createElement("ul",{className:e,role:"tree"},n)}}]),l}();I(k,"defaultProps",{model:null,multiple:!1});var x=function(r){h(l,e.Component);var i=g(l);function l(e){var t;return p(this,l),(t=i.call(this,e)).state={id:e.id,activeItem:t.findActiveItem()},t}return f(l,[{key:"onItemClick",value:function(e,t){if(t.disabled)e.preventDefault();else{t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t});var n=this.state.activeItem;this.isItemActive(t)?(t.expanded=!1,this.setState({activeItem:this.props.multiple?n.filter((function(e){return e!==t})):null})):(!this.props.multiple&&n&&(n.expanded=!1),t.expanded=!0,this.setState({activeItem:this.props.multiple?[].concat(c(n||[]),[t]):t}))}}},{key:"findActiveItem",value:function(){if(this.props.model){if(this.props.multiple)return this.props.model.filter((function(e){return e.expanded}));var e=null;return this.props.model.forEach((function(t){t.expanded&&(e?t.expanded=!1:e=t)})),e}return null}},{key:"isItemActive",value:function(e){return this.state.activeItem&&(this.props.multiple?this.state.activeItem.indexOf(e)>-1:this.state.activeItem===e)}},{key:"componentDidMount",value:function(){this.state.id||this.setState({id:t.UniqueComponentId()})}},{key:"renderPanel",value:function(e,r){var i=this,l=this.isItemActive(e),s=t.classNames("p-panelmenu-panel",e.className),o=t.classNames("p-component p-panelmenu-header",{"p-highlight":l,"p-disabled":e.disabled}),u=t.classNames("p-panelmenu-icon pi",{"pi-chevron-right":!l," pi-chevron-down":l}),c=t.classNames("p-menuitem-icon",e.icon),p=e.items&&a.default.createElement("span",{className:u}),m=e.icon&&a.default.createElement("span",{className:c}),f=e.label&&a.default.createElement("span",{className:"p-menuitem-text"},e.label),d=t.classNames("p-toggleable-content",{"p-toggleable-content-collapsed":!l}),h=a.default.createRef(),v=a.default.createElement("a",{href:e.url||"#",className:"p-panelmenu-header-link",onClick:function(t){return i.onItemClick(t,e)},"aria-expanded":l,id:this.state.id+"_header","aria-controls":this.state.id+"content","aria-disabled":e.disabled},p,m,f);e.template&&(v=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return i.onItemClick(t,e)},className:"p-panelmenu-header-link",labelClassName:"p-menuitem-text",submenuIconClassName:u,iconClassName:c,element:v,props:this.props,leaf:!e.items,active:l}));return a.default.createElement("div",{key:e.label+"_"+r,className:s,style:e.style},a.default.createElement("div",{className:o,style:e.style},v),a.default.createElement(n.CSSTransition,{nodeRef:h,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:l,unmountOnExit:!0,options:this.props.transitionOptions},a.default.createElement("div",{ref:h,className:d,role:"region",id:this.state.id+"_content","aria-labelledby":this.state.id+"_header"},a.default.createElement("div",{className:"p-panelmenu-content"},a.default.createElement(k,{model:e.items,className:"p-panelmenu-root-submenu",multiple:this.props.multiple})))))}},{key:"renderPanels",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return e.renderPanel(t,n)})):null}},{key:"render",value:function(){var e=t.classNames("p-panelmenu p-component",this.props.className),n=this.renderPanels();return a.default.createElement("div",{id:this.props.id,className:e,style:this.props.style},n)}}]),l}();I(x,"defaultProps",{id:null,model:null,style:null,className:null,multiple:!1,transitionOptions:null}),exports.PanelMenu=x;