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right IBM Corp. 2019, 2021\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport settings from 'carbon-components/es/globals/js/settings';\nimport { html, property, query, customElement, LitElement } from 'lit-element';\nimport ChevronDown20 from '@carbon/icons/lib/chevron--down/20';\nimport { forEach } from '../../globals/internal/collection-helpers';\nimport FocusMixin from '../../globals/mixins/focus';\nimport styles from './side-nav.scss';\n\nconst { prefix } = settings;\n\n/**\n * Side nav menu.\n * @element bx-side-nav-menu\n * @slot title-icon - The icon.\n * @csspart expando The expando.\n * @csspart expando-icon-container The expando icon container.\n * @csspart expando-icon The expando icon.\n * @csspart title The title.\n * @csspart title-icon-container The title icon container.\n * @csspart menu-body The menu body.\n */\n@customElement(`${prefix}-side-nav-menu`)\nclass BXSideNavMenu extends FocusMixin(LitElement) {\n  /**\n   * `true` if this menu has an icon.\n   */\n  private _hasIcon = false;\n\n  /**\n   * The container for the title icon.\n   */\n  @query('#title-icon-container')\n  private _titleIconContainerNode!: HTMLDivElement;\n\n  /**\n   * Handles user-initiated toggle request of this side nav menu.\n   * @param expanded The new expanded state.\n   */\n  private _handleUserInitiatedToggle(expanded = !this.expanded) {\n    const { eventBeforeToggle, eventToggle } = this.constructor as typeof BXSideNavMenu;\n    const init = {\n      bubbles: true,\n      cancelable: true,\n      composed: true,\n      detail: {\n        expanded,\n      },\n    };\n    if (this.dispatchEvent(new CustomEvent(eventBeforeToggle, init))) {\n      this.expanded = expanded;\n      this.dispatchEvent(new CustomEvent(eventToggle, init));\n    }\n  }\n\n  /**\n   * Handler for the `click` event on the expando button.\n   */\n  private _handleClickExpando() {\n    this._handleUserInitiatedToggle();\n  }\n\n  /**\n   * Handles `slotchange` event on the non-named `<slot>`.\n   */\n  private _handleSlotChange({ target }) {\n    const { _hasIcon: hasIcon } = this;\n    forEach(target.assignedNodes(), item => {\n      if (item.nodeType === Node.ELEMENT_NODE) {\n        item.toggleAttribute((this.constructor as typeof BXSideNavMenu).attribItemHasIcon, hasIcon);\n      }\n    });\n  }\n\n  /**\n   * Handles `slotchange` event on the `<slot>` for the title icon.\n   */\n  private _handleSlotChangeTitleIcon({ target }) {\n    const constructor = this.constructor as typeof BXSideNavMenu;\n    const hasIcon = target.assignedNodes().length > 0;\n    this._hasIcon = hasIcon;\n    this._titleIconContainerNode?.toggleAttribute('hidden', !hasIcon);\n    forEach(this.querySelectorAll(constructor.selectorItem), item => {\n      item.toggleAttribute(constructor.attribItemHasIcon, hasIcon);\n    });\n  }\n\n  /**\n   * `true` if the menu has active menu item.\n   */\n  @property({ type: Boolean, reflect: true })\n  active = false;\n\n  /**\n   * `true` if the menu should be open.\n   */\n  @property({ type: Boolean, reflect: true })\n  expanded = false;\n\n  /**\n   * `true` if the menu should be forced collapsed upon side nav's expanded state.\n   */\n  @property({ type: Boolean, reflect: true, attribute: 'force-collapsed' })\n  forceCollapsed = false;\n\n  /**\n   * The title text.\n   */\n  @property()\n  title = '';\n\n  createRenderRoot() {\n    return this.attachShadow({\n      mode: 'open',\n      delegatesFocus: Number((/Safari\\/(\\d+)/.exec(navigator.userAgent) ?? ['', 0])[1]) <= 537,\n    });\n  }\n\n  connectedCallback() {\n    if (!this.hasAttribute('role')) {\n      this.setAttribute('role', 'listitem');\n    }\n    super.connectedCallback();\n  }\n\n  updated(changedProperties) {\n    if (changedProperties.has('expanded')) {\n      const { selectorItem } = this.constructor as typeof BXSideNavMenu;\n      const { expanded } = this;\n      forEach(this.querySelectorAll(selectorItem), elem => {\n        (elem as HTMLElement).tabIndex = expanded ? 0 : -1;\n      });\n    }\n  }\n\n  render() {\n    const {\n      expanded,\n      forceCollapsed,\n      title,\n      _handleClickExpando: handleClickExpando,\n      _handleSlotChange: handleSlotChange,\n      _handleSlotChangeTitleIcon: handleSlotChangeTitleIcon,\n    } = this;\n    return html`\n      <button\n        type=\"button\"\n        part=\"expando\"\n        aria-haspopup=\"true\"\n        aria-expanded=\"${String(Boolean(expanded && !forceCollapsed))}\"\n        class=\"${prefix}--side-nav__submenu\"\n        @click=${handleClickExpando}>\n        <div id=\"title-icon-container\" part=\"title-icon-container\" hidden class=\"${prefix}--side-nav__icon\">\n          <slot name=\"title-icon\" @slotchange=${handleSlotChangeTitleIcon}></slot>\n        </div>\n        <span part=\"title\" class=\"${prefix}--side-nav__submenu-title\">${title}</span>\n        <div\n          part=\"expando-icon-container\"\n          class=\"${prefix}--side-nav__icon ${prefix}--side-nav__icon--small ${prefix}--side-nav__submenu-chevron\">\n          ${ChevronDown20({ part: 'expando-icon' })}\n        </div>\n      </button>\n      <ul part=\"menu-body\" class=\"${prefix}--side-nav__menu\">\n        <slot @slotchange=${handleSlotChange}></slot>\n      </ul>\n    `;\n  }\n\n  /**\n   * The attribute name of the menu items, that is set if this menu has an icon.\n   */\n  static attribItemHasIcon = 'parent-has-icon';\n\n  /**\n   * A selector that will return the menu items.\n   */\n  static get selectorItem() {\n    return `${prefix}-side-nav-menu-item`;\n  }\n\n  /**\n   * The name of the custom event fired before this side nav menu is being toggled upon a user gesture.\n   * Cancellation of this event stops the user-initiated action of toggling this side nav menu.\n   */\n  static get eventBeforeToggle() {\n    return `${prefix}-side-nav-menu-beingtoggled`;\n  }\n\n  /**\n   * The name of the custom event fired after this side nav menu is toggled upon a user gesture.\n   */\n  static get eventToggle() {\n    return `${prefix}-side-nav-menu-toggled`;\n  }\n\n  static styles = styles; // `styles` here is a `CSSResult` generated by custom WebPack loader\n}\n\nexport default BXSideNavMenu;\n"]}