import{Component}from"@theme/component";import{debounce,onDocumentReady}from"@theme/utilities";import{MegaMenuHoverEvent}from"@theme/events";const ACTIVATE_DELAY=250,DEACTIVATE_DELAY=350;class HeaderMenu extends Component{connectedCallback(){super.connectedCallback(),onDocumentReady(this.#preloadImages)}#state={activeItem:null};get animationDelay(){const value=this.dataset.animationDelay;return value?parseInt(value,10):0}activate=event=>{this.#debouncedDeactivate.cancel(),this.#state.activeItem?this.#activateHandler(event):this.#debouncedActivateHandler(event)};#activateHandler=event=>{if(this.#debouncedDeactivate.cancel(),this.dispatchEvent(new MegaMenuHoverEvent),this.removeAttribute("data-animating"),!(event.target instanceof Element))return;let item=findMenuItem(event.target);if(!item||item==this.#state.activeItem)return;this.dataset.overflowExpanded=(event.target.slot!=="").toString(),this.#deactivate(),this.#state.activeItem=item,this.ariaExpanded="true",item.ariaExpanded="true";const submenu=findSubmenu(item);submenu&&this.style.setProperty("--submenu-height",`${submenu.offsetHeight}px`)};#debouncedActivateHandler=debounce(this.#activateHandler,ACTIVATE_DELAY);deactivate(event){if(this.#debouncedActivateHandler.cancel(),!(event.target instanceof Element))return;findMenuItem(event.target)===this.#state.activeItem&&this.#debouncedDeactivate(event)}#debouncedDeactivate=debounce(event=>{this.dataset.overflowExpanded="false";const item=findMenuItem(event.target);item==this.#state.activeItem&&this.#deactivate(item)},DEACTIVATE_DELAY);#deactivate=(item=this.#state.activeItem)=>{this.style.setProperty("--submenu-height","0px"),item&&(this.#state.activeItem=null,this.ariaExpanded="false",item.ariaExpanded="false",item.setAttribute("data-animating",""),setTimeout(()=>{item.removeAttribute("data-animating")},this.animationDelay))};#preloadImages=()=>{this.querySelectorAll('img[loading="lazy"]')?.forEach(image=>image.removeAttribute("loading"))}}customElements.get("header-menu")||customElements.define("header-menu",HeaderMenu);function findMenuItem(element){return element instanceof Element?element?.matches('[slot="more"')?findMenuItem(element.parentElement?.querySelector('[slot="overflow"]')):element?.querySelector('[role="menuitem"]'):null}function findSubmenu(element){const submenu=element?.parentElement?.querySelector('[ref="submenu[]"]');return submenu instanceof HTMLElement?submenu:null}
//# sourceMappingURL=/s/files/1/0677/1399/0759/t/1/assets/header-menu.js.map?v=1783128502
