"use strict";function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var b=l(require("react")),c=j(require("prop-types")),d=require("../utils/common"),e=j(require("classnames")),f=require("../utils/withActionHandler"),g=require("react-i18next"),h=require("@carbon/icons-react"),i=require("react-router-dom");function j(a){return a&&a.__esModule?a:{default:a}}function k(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(k=function(a){return a?c:b})(a)}function l(b,c){if(!c&&b&&b.__esModule)return b;if(null===b||"object"!==a(b)&&"function"!=typeof b)return{default:b};var d=k(c);if(d&&d.has(b))return d.get(b);var e={},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var g in b)if("default"!=g&&Object.prototype.hasOwnProperty.call(b,g)){var h=f?Object.getOwnPropertyDescriptor(b,g):null;h&&(h.get||h.set)?Object.defineProperty(e,g,h):e[g]=b[g]}return e["default"]=b,d&&d.set(b,e),e}function m(a,b){return r(a)||q(a,b)||o(a,b)||n()}function n(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(a,b){if(a){if("string"==typeof a)return p(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?p(a,b):void 0}}function p(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function q(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f=[],g=!0,h=!1;try{for(c=c.call(a);!(g=(d=c.next()).done)&&(f.push(d.value),!(b&&f.length===b));g=!0);}catch(a){h=!0,e=a}finally{try{g||null==c["return"]||c["return"]()}finally{if(h)throw e}}return f}}function r(a){if(Array.isArray(a))return a}var s=function(a){var c=a.displayName,j=a.selected,k=a.menuItems,l=a.onToggle,n=void 0===l?function(){}:l,o=a.to,p=a.nestedMenus,q=void 0===p?{}:p,r=a.isExpanded,u=a.highlightedQuery,v=(0,g.useTranslation)(),w=v.t,t=(0,b.useState)(!1),x=m(t,2),y=x[0],z=x[1];(0,b.useEffect)(function(){null!==r&&z(r)},[r]);var A,B=(0,f.withActionHandler)(function(){z(!y),n()});u&&(A=(0,d.highlightCleaner)(c,u));return b["default"].createElement("div",{"data-testid":"menu-dropdown"},b["default"].createElement("div",{className:"clickable",tabIndex:o?null:"0",role:o?null:"button",onClick:!o&&B?B:void 0,onKeyDown:!o&&B?B:void 0},function renderLink(a){return o?b["default"].createElement(i.Link,{className:(0,e["default"])("menuDropdown tocHeader",{selected:j}),to:o,title:c,"aria-label":c,"data-testid":"menuDropdown-navigate"},a):b["default"].createElement("div",{className:(0,e["default"])("menuDropdown tocHeader",{selected:j}),"aria-label":c},a)}(b["default"].createElement(b["default"].Fragment,null,b["default"].createElement("button",{className:(0,e["default"])("iconOnlyButton"),onClick:B,"aria-label":w("menu_button"),"data-testid":"menuDropdown-button"},b["default"].createElement(h.CaretRight32,{className:(0,e["default"])("expand-arrow",{rotate90:y})})),b["default"].createElement("div",{className:"menuDropdown__label truncate"},b["default"].createElement("p",{className:"truncate"},A?b["default"].createElement("span",{dangerouslySetInnerHTML:{__html:A}}):c))))),y&&b["default"].createElement("ul",null,q&&Object.entries(q).map(function(a){var c=m(a,2),d=c[0],e=c[1];return b["default"].createElement("li",{key:d,className:"tocItem tocHeader","data-testid":"grouped-menu-item"},b["default"].createElement(s,{className:"nestedTag",menuItems:e.menuItems,displayName:d,nestedMenus:e.nested,onToggle:e.onToggle,isExpanded:r}))}),k.map(function(a){var f=(0,d.cleanUpKey)(a.displayName);return b["default"].createElement("li",{className:"tocItem",key:c+"/"+f},b["default"].createElement(i.Link,{to:a.route,className:(0,e["default"])("bx--side-nav__link","truncate toc-selectable menuDropdown__item","toc-navigate-".concat((0,d.cleanUpKey)(f)),{selected:a.selected}),title:a.displayName,"data-testid":"dropdown-item-list"},b["default"].createElement("span",{className:"bx--side-nav__link-text",dangerouslySetInnerHTML:{__html:a.displayName},"data-testid":"grouped-menu-item"})))})))};s.propTypes={displayName:c["default"].string,menuItems:c["default"].arrayOf(c["default"].shape({displayName:c["default"].string,selected:c["default"].bool,route:c["default"].string})),nestedMenus:c["default"].object,className:c["default"].string,onToggle:c["default"].func,expanded:c["default"].bool,highlightedQuery:c["default"].string};var t=s;exports["default"]=t;