"use strict";
const hamburger = document.getElementById('hamburger');
const sidebar = document.getElementById('sidebar');
const list = matchMedia('(max-width: 640px)');
const LS_KEY = 'pfe-tools-dev-server-maximized';
function toggleNav(force) {
    const old = sidebar?.getAttribute('aria-expanded') === 'true';
    const next = force ?? !old;
    sidebar?.setAttribute('aria-expanded', String(next));
    document.body.classList.toggle('menu-open', next);
}
function attachShadowRoots(root) {
    root.querySelectorAll('template[shadowroot]').forEach(template => {
        if (template instanceof HTMLTemplateElement) {
            const mode = template.getAttribute('shadowroot');
            const shadowRoot = template.parentNode.attachShadow({ mode });
            shadowRoot.appendChild(template.content);
            template.remove();
            attachShadowRoots(shadowRoot);
        }
    });
}
function onClick() {
    const next = sidebar?.getAttribute('aria-expanded') !== 'true';
    if (next) {
        localStorage.removeItem(LS_KEY);
    }
    else {
        localStorage.setItem(LS_KEY, 'true');
    }
    toggleNav();
}
function onKeydown(event) {
    if (sidebar?.getAttribute('aria-expanded') === 'true') {
        switch (event.key) {
            case 'Escape':
                event.preventDefault();
                event.stopPropagation();
                toggleNav(false);
        }
    }
}
function onMediaChange() {
    toggleNav(!list.matches);
}
sidebar?.addEventListener('keydown', onKeydown);
hamburger?.addEventListener('click', onClick);
document.documentElement.removeAttribute('unresolved');
list.addEventListener('change', onMediaChange);
onMediaChange();
if (!Object.prototype.hasOwnProperty.call(HTMLTemplateElement.prototype, 'shadowRoot')) {
    attachShadowRoots(document);
}
if (localStorage.getItem(LS_KEY)) {
    toggleNav(false);
}
//# sourceMappingURL=demo.js.map