import e,{Component as t}from"react";import{classNames as n,ObjectUtils as r,UniqueComponentId as i}from"primereact/utils";import{CSSTransition as a}from"primereact/csstransition";function l(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(t){return e.createElement("li",{key:"separator_"+t,className:"p-menu-separator"})}},{key:"renderSubmenu",value:function(t,r){var i=n("p-toggleable-content",{"p-toggleable-content-collapsed":!r}),l=e.createRef();return t.items?e.createElement(a,{nodeRef:l,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:r,unmountOnExit:!0},e.createElement("div",{ref:l,className:i},e.createElement(o,{model:t.items,multiple:this.props.multiple}))):null}},{key:"renderMenuitem",value:function(t,i){var a=this,l=this.isItemActive(t),o=n("p-menuitem",t.className),s=n("p-menuitem-link",{"p-disabled":t.disabled}),u=n("p-menuitem-icon",t.icon),c=n("p-panelmenu-icon pi pi-fw",{"pi-angle-right":!l,"pi-angle-down":l}),p=t.icon&&e.createElement("span",{className:u}),m=t.label&&e.createElement("span",{className:"p-menuitem-text"},t.label),f=t.items&&e.createElement("span",{className:c}),d=this.renderSubmenu(t,l),h=e.createElement("a",{href:t.url||"#",className:s,target:t.target,onClick:function(e){return a.onItemClick(e,t,i)},role:"menuitem","aria-disabled":t.disabled},f,p,m);t.template&&(h=r.getJSXElement(t.template,t,{onClick:function(e){return a.onItemClick(e,t,i)},className:s,labelClassName:"p-menuitem-text",iconClassName:u,submenuIconClassName:c,element:h,props:this.props,leaf:!t.items,active:l}));return e.createElement("li",{key:t.label+"_"+i,className:o,style:t.style,role:"none"},h,d)}},{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=n("p-submenu-list",this.props.className),r=this.renderMenu();return e.createElement("ul",{className:t,role:"tree"},r)}}]),o}();E(x,"defaultProps",{model:null,multiple:!1});var O=function(l){v(s,t);var o=k(s);function s(e){var t;return m(this,s),(t=o.call(this,e)).state={id:e.id,activeItem:t.findActiveItem()},t}return d(s,[{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(p(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:i()})}},{key:"renderPanel",value:function(t,i){var l=this,o=this.isItemActive(t),s=n("p-panelmenu-panel",t.className),u=n("p-component p-panelmenu-header",{"p-highlight":o,"p-disabled":t.disabled}),c=n("p-panelmenu-icon pi",{"pi-chevron-right":!o," pi-chevron-down":o}),p=n("p-menuitem-icon",t.icon),m=t.items&&e.createElement("span",{className:c}),f=t.icon&&e.createElement("span",{className:p}),d=t.label&&e.createElement("span",{className:"p-menuitem-text"},t.label),h=n("p-toggleable-content",{"p-toggleable-content-collapsed":!o}),v=e.createRef(),y=e.createElement("a",{href:t.url||"#",className:"p-panelmenu-header-link",onClick:function(e){return l.onItemClick(e,t)},"aria-expanded":o,id:this.state.id+"_header","aria-controls":this.state.id+"content","aria-disabled":t.disabled},m,f,d);t.template&&(y=r.getJSXElement(t.template,t,{onClick:function(e){return l.onItemClick(e,t)},className:"p-panelmenu-header-link",labelClassName:"p-menuitem-text",submenuIconClassName:c,iconClassName:p,element:y,props:this.props,leaf:!t.items,active:o}));return e.createElement("div",{key:t.label+"_"+i,className:s,style:t.style},e.createElement("div",{className:u,style:t.style},y),e.createElement(a,{nodeRef:v,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:o,unmountOnExit:!0,options:this.props.transitionOptions},e.createElement("div",{ref:v,className:h,role:"region",id:this.state.id+"_content","aria-labelledby":this.state.id+"_header"},e.createElement("div",{className:"p-panelmenu-content"},e.createElement(x,{model:t.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 t=n("p-panelmenu p-component",this.props.className),r=this.renderPanels();return e.createElement("div",{id:this.props.id,className:t,style:this.props.style},r)}}]),s}();E(O,"defaultProps",{id:null,model:null,style:null,className:null,multiple:!1,transitionOptions:null});export{O as PanelMenu};