// nav.el -- Navigation hamburger menu and Mission dropdown.
// Compiled with: elc --target=js --bundle --minify --obfuscate

fn main() -> Void {
    native_js("(function() {
  var btn  = document.getElementById('nav-hamburger');
  var menu = document.getElementById('nav-mobile');
  var nav  = document.getElementById('nav');
  if (!btn || !menu) return;

  function close() {
    menu.classList.remove('open');
    btn.setAttribute('aria-expanded', 'false');
  }
  function open() {
    menu.classList.add('open');
    btn.setAttribute('aria-expanded', 'true');
  }
  function toggle() {
    if (menu.classList.contains('open')) { close(); } else { open(); }
  }

  btn.addEventListener('click', function(e) { e.stopPropagation(); toggle(); });

  var ddBtn = document.querySelector('.nav-dropdown-btn');
  var dd = document.querySelector('.nav-dropdown');
  if (ddBtn && dd) {
    ddBtn.addEventListener('click', function(e) {
      e.stopPropagation();
      var isOpen = dd.classList.contains('open');
      dd.classList.toggle('open');
      ddBtn.setAttribute('aria-expanded', isOpen ? 'false' : 'true');
    });
    dd.querySelectorAll('.nav-dropdown-item').forEach(function(a) {
      a.addEventListener('click', function() { dd.classList.remove('open'); });
    });
    document.addEventListener('click', function() { dd.classList.remove('open'); });
  }

  menu.querySelectorAll('a').forEach(function(a) {
    a.addEventListener('click', close);
  });

  document.addEventListener('click', function(e) {
    if (!nav.contains(e.target)) { close(); }
  });

  document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape') { close(); }
  });

  window.addEventListener('resize', function() {
    if (window.innerWidth > 1060) { close(); }
  });
})()")
}
