/*!
 * EdGEL: The University of Edinburgh Design System v5.0.0 (https://design-system.ed.ac.uk/)
 * Copyright 2014-2023 The University of Edinburgh
 *
 * Bootstrap  v5.3.2 (https://getbootstrap.com/)
 * Copyright 2011-2023 The Bootstrap Authors
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
 */
import{x as e,c as n}from"./base-2Isyko0t.js";import{E as t,S as s}from"./selector-engine-FWBG9T7Z.js";import{D as o}from"./dropdown-6rZsOIxl.js";import{o as a}from"./if-defined-66voXlkv.js";import{E as r}from"./menu-7_PRmfGT.js";import"./collapse-zYCjoaZf.js";import"./collapse-Fp-mMCqS.js";import"./edgel-icon.js";let i,l,d,c,p,u,h,m=e=>e;const f=".edgel.topnav",b=".data-api",v=`click${f}${b}`,g=`keydown${f}${b}`,w=`keyup${f}${b}`;n("edgel-top-nav",class extends r{constructor(){super(),this.controls="uoe-topnav",this.itemClass="nav-link",this.activeClass="active",this._dropdowns=[],this.clearMenus=this.clearMenus.bind(this)}_validateMenu(){if(!this.menu.topnav)throw new Error("No top nav links supplied in the menu object.");if(!Array.isArray(this.menu.topnav))throw new TypeError("The topnav property must be an array of links.");return super._validateMenu()}_processMenu(){}_renderMenu(){const n=[];for(let t=0;t<this.menu.topnav.length;t++){const s={_classes:[],...this.menu.topnav[t]},o=`${this.controls}-${t}`;if(-1!==this.menu.breadcrumb.findIndex((e=>e.url===s.url))&&(1===this.menu.breadcrumb.length?s._active=!0:s._classes.push("active")),s.children&&s.children.length){const t=this._nestedList(s.children,o);s.url="#",s._classes.push("dropdown-toggle"),s._attrs={id:o,role:"button",expanded:"false",click:this._toggleDropdown,toggle:"dropdown"},n.push(e(i||(i=m`<li class="nav-item dropdown">${0}${0}</li>`),this._itemLink(s),t))}else n.push(e(l||(l=m`<li class="nav-item">${0}</li>`),this._itemLink(s)))}return e(d||(d=m`<ul class="navbar-nav">${0}</ul>`),n)}_nestedList(n,t){const s=[];for(const{url:t,text:o,restricted:r,children:i}of n){if(i&&i.length)throw new Error("Only one level of dropdown is allowed in the top nav");const n=["dropdown-item"];let l;const d=this.menu.breadcrumb.findIndex((e=>e.url===t));-1!==d&&(n.push("active"),d===this.menu.breadcrumb.length-1&&(l="page"));const p=this._lockSuffix(r);s.push(e(c||(c=m`
        <li>
          <a
            href=${0}
            class=${0}
            aria-current=${0}
          >
            ${0}
            ${0}
          </a>
        </li>
      `),t,n.join(" "),a(l),o,p))}return e(p||(p=m`<ul class="dropdown-menu" aria-labelledby=${0}>${0}</ul>`),t,s)}clearMenus(e){if(2===e.button||"keyup"===e.type&&"Tab"!==e.key)return;const n=this.shadowRoot.querySelectorAll('[data-bs-toggle="dropdown"]:not(.disabled):not(:disabled).show');for(const t of n){const n=o.getInstance(t),s=e.composedPath();if(s.includes(n._element))continue;if(s.includes(n._menu)&&"keyup"===e.type&&"Tab"===e.key)continue;const a={relatedTarget:n._element};"click"===e.type&&(a.clickEvent=e),n._completeHide(a)}}willUpdate(e){super.willUpdate(e);for(const e of this._dropdowns){t.off(e,g,o.dataApiKeydownHandler);const n=s.next(e._element,".dropdown-menu")[0];t.off(n,g,o.dataApiKeydownHandler),e.dispose()}}updated(e){this.collapseDisabled=!this.menuHtml,super.updated(e),this._dropdowns=[];const n=this.shadowRoot.querySelectorAll("a[role=button]");for(const e of n){this._dropdowns.push(o.getOrCreateInstance(e)),t.on(e,g,o.dataApiKeydownHandler);const n=s.next(e,".dropdown-menu")[0];t.on(n,g,o.dataApiKeydownHandler)}}connectedCallback(){super.connectedCallback(),t.on(document,v,this.clearMenus),t.on(document,w,this.clearMenus)}disconnectedCallback(){super.disconnectedCallback();for(const e of this._dropdowns)e.dispose();t.off(document,v,this.clearMenus),t.off(document,w,this.clearMenus)}_toggleDropdown(e){e.preventDefault(),e.stopPropagation(),this.clearMenus(e),o.getInstance(e.target).toggle()}render(){if(!this.menuHtml)return;const n=this.expanded?"hamburger hamburger-expanded":"hamburger",t=e(u||(u=m`
      <span aria-hidden="true" class=${0}></span>
      <span class="visually-hidden">Toggle section links</span>
    `),n),s=this.buttonHtml(t,"navbar-toggler");return e(h||(h=m`
      <span class="edgel-js">
        <nav class="navbar navbar-expand-md navbar-dark bg-dark" aria-label="Section navigation">
          <div class="container-topnav">
            ${0}
            <div class="collapse navbar-collapse" id=${0}>
              ${0}
            </div>
          </div>
        </nav>
      </span>
    `),s,this.controls,this.menuHtml)}});
