document.addEventListener("DOMContentLoaded",()=>{function e(e){"true"===e.getAttribute("aria-expanded")?n(e):t(e)}function t(e){e.setAttribute("aria-expanded","true"),e.closest("li").classList.add("is-open");const t=e.nextElementSibling;t&&t.removeAttribute("hidden")}function n(e){if(!e)return;e.setAttribute("aria-expanded","false"),e.closest("li").classList.remove("is-open");const t=e.nextElementSibling;t&&t.setAttribute("hidden","")}document.querySelectorAll(".category-link-panel .has-submenu").forEach(r=>{const a=r.querySelector(".category-link-panel__submenu-trigger"),o=r.querySelector(".category-link-panel__submenu");if(!a||!o)return;const c=()=>Array.from(o.querySelectorAll("a[href]"));a.addEventListener("click",()=>e(a)),a.addEventListener("keydown",n=>{switch(n.key){case"Enter":case" ":n.preventDefault(),e(a);break;case"ArrowDown":{n.preventDefault(),t(a);const e=c();e[0]&&e[0].focus();break}case"ArrowUp":{n.preventDefault(),t(a);const e=c();e.length&&e[e.length-1].focus();break}}}),o.addEventListener("keydown",e=>{const t=c(),n=t.indexOf(document.activeElement);if(-1!==n)switch(e.key){case"ArrowDown":e.preventDefault(),(t[n+1]||t[0]).focus();break;case"ArrowUp":e.preventDefault(),(0===n?a:t[n-1]).focus();break;case"Home":e.preventDefault(),t[0].focus();break;case"End":e.preventDefault(),t[t.length-1].focus()}}),r.addEventListener("focusout",()=>{requestAnimationFrame(()=>{r.contains(document.activeElement)||n(a)})})}),document.addEventListener("keydown",e=>{"Escape"===e.key&&document.querySelectorAll('.category-link-panel .has-submenu .category-link-panel__submenu-trigger[aria-expanded="true"]').forEach(e=>{n(e),e.focus()})}),document.addEventListener("click",e=>{document.querySelectorAll(".category-link-panel .has-submenu.is-open").forEach(t=>{t.contains(e.target)||n(t.querySelector(".category-link-panel__submenu-trigger"))})})});