import{calculateHeaderGroupHeight}from"@theme/critical";import{Component}from"@theme/component";import{onDocumentLoaded,changeMetaThemeColor}from"@theme/utilities";class HeaderComponent extends Component{requiredRefs=["headerDrawerContainer","headerMenu","headerRowTop"];#menuDrawerHiddenWidth=null;#intersectionObserver=null;#offscreen=!1;#lastScrollTop=0;#timeout=null;#animationDelay=150;#resizeObserver=new ResizeObserver(([entry])=>{if(!entry)return;const{height}=entry.target.getBoundingClientRect();document.body.style.setProperty("--header-height",`${height}px`),this.#menuDrawerHiddenWidth&&window.innerWidth>this.#menuDrawerHiddenWidth&&this.#updateMenuVisibility(!1)});#observeStickyPosition=(alwaysSticky=!0)=>{if(this.#intersectionObserver)return;const config={threshold:alwaysSticky?1:0};this.#intersectionObserver=new IntersectionObserver(([entry])=>{if(!entry)return;const{isIntersecting}=entry;alwaysSticky?(this.dataset.stickyState=isIntersecting?"inactive":"active",changeMetaThemeColor(this.refs.headerRowTop)):this.#offscreen=!isIntersecting||this.dataset.stickyState==="active"},config),this.#intersectionObserver.observe(this)};#handleOverflowMinimum=event=>{this.#updateMenuVisibility(event.detail.minimumReached)};#updateMenuVisibility(hideMenu){hideMenu?(this.refs.headerDrawerContainer.classList.remove("desktop:hidden"),this.#menuDrawerHiddenWidth=window.innerWidth,this.refs.headerMenu.classList.add("hidden")):(this.refs.headerDrawerContainer.classList.add("desktop:hidden"),this.#menuDrawerHiddenWidth=null,this.refs.headerMenu.classList.remove("hidden"))}#handleWindowScroll=()=>{const stickyMode=this.getAttribute("sticky");if(!this.#offscreen&&stickyMode!=="always")return;const scrollTop=document.scrollingElement?.scrollTop??0,isScrollingUp=scrollTop=0?this.dataset.scrollDirection="none":isScrollingUp?this.dataset.scrollDirection="up":this.dataset.scrollDirection="down",this.#lastScrollTop=scrollTop;return}isScrollingUp?(this.removeAttribute("data-animating"),this.getBoundingClientRect().top>=0?(this.#offscreen=!1,this.dataset.stickyState="inactive",this.dataset.scrollDirection="none"):(this.dataset.stickyState="active",this.dataset.scrollDirection="up")):this.dataset.stickyState==="active"?(this.dataset.scrollDirection="none",this.setAttribute("data-animating",""),this.#timeout=setTimeout(()=>{this.dataset.stickyState="idle",this.removeAttribute("data-animating")},this.#animationDelay)):(this.dataset.scrollDirection="none",this.dataset.stickyState="idle"),this.#lastScrollTop=scrollTop};connectedCallback(){super.connectedCallback(),this.#resizeObserver.observe(this),this.addEventListener("overflowMinimum",this.#handleOverflowMinimum);const stickyMode=this.getAttribute("sticky");stickyMode&&(this.#observeStickyPosition(stickyMode==="always"),(stickyMode==="scroll-up"||stickyMode==="always")&&document.addEventListener("scroll",this.#handleWindowScroll))}disconnectedCallback(){super.disconnectedCallback(),this.#resizeObserver.disconnect(),this.#intersectionObserver?.disconnect(),this.removeEventListener("overflowMinimum",this.#handleOverflowMinimum),document.removeEventListener("scroll",this.#handleWindowScroll),document.body.style.setProperty("--header-height","0px")}}customElements.get("header-component")||customElements.define("header-component",HeaderComponent),onDocumentLoaded(()=>{const header=document.querySelector("#header-component"),headerGroup=document.querySelector("#header-group");if(headerGroup){const resizeObserver=new ResizeObserver(()=>calculateHeaderGroupHeight(header,headerGroup)),children=headerGroup.children;for(let i=0;i{for(const mutation of mutations)if(mutation.type==="childList"){const children2=headerGroup.children;for(let i=0;i