document.addEventListener(`DOMContentLoaded`,()=>{document.querySelectorAll(`.submenu-toggle`).forEach(e=>{e.addEventListener(`click`,t=>{t.preventDefault();let n=e.parentElement?.querySelector(`.submenu-link`);if(!n)return;let r=e=>n.getAttribute(e)||``,i=e=>r(e).split(`|||`).filter(Boolean),a=(e,t=0)=>parseInt(r(e)||`${t}`,10),o=r(`data-parent-href`),s=r(`data-parent-target`),c=r(`data-parent-label`),l=i(`data-submenu-hrefs`),u=i(`data-submenu-targets`),d=i(`data-submenu-labels`),f=a(`data-submenu-count`),p=a(`data-submenu-index`);if(f===0||l.length!==f-1||u.length!==f-1||d.length!==f-1){console.error(`[Higan Haozi][shared] Submenu data is inconsistent`);return}p=(p+1)%f;let m=p===0,h=p-1;n.href=m?o:l[h]||``,n.target=m?s:u[h]||``,n.textContent=m?c:d[h]||``,n.setAttribute(`aria-label`,n.textContent||``),n.setAttribute(`data-submenu-index`,p.toString());let g=e.querySelector(`.iconify`);if(g){let e=p===f-1;g.classList.toggle(`material-symbols--keyboard-arrow-up`,e),g.classList.toggle(`material-symbols--keyboard-arrow-down`,!e)}})})});