"use strict";(globalThis.webpackChunkglobalheaderweb=globalThis.webpackChunkglobalheaderweb||[]).push([[261],{$ERSP_NIKe$:(t,i,e)=>{e.d(i,{default:()=>c});const s="gh-header__main-sticky",o="down",l="transform 0.22s cubic-bezier(0.33, 1, 0.68, 1)",c=class{headerHeight;stickySectionOffsetTop;stickySectionOffsetBottom;scrollPosition;lastScrollDirection=(()=>o)();upScrollStartPosition=0;downScrollStartPosition=0;isSticky=!1;visiblePercentage=0;initialStateApplied=!1;scrollTimeout=null;resizeTimeout=null;placeholder=null;listenersAttached=!1;constructor(t,i){this.headerSection=t,this.stickySection=i,this.scrollPosition=window.scrollY,this.stickySectionOffsetTop=i.offsetTop,this.stickySectionOffsetBottom=i.offsetTop+i.offsetHeight,this.headerHeight=i.offsetHeight,this.stickySection.style.willChange="transform"}initializeStickyTreatment(){this.headerSection&&this.stickySection&&(this.stickySection.style.width=`${this.headerSection.offsetWidth}px`,this.placeholder=document.createElement("div"),this.placeholder.className="gh-header-placeholder",this.placeholder.style.height=`${this.stickySection.offsetHeight}px`,this.placeholder.style.display="none",this.stickySection.parentNode?.insertBefore(this.placeholder,this.stickySection.nextSibling),window.addEventListener("scroll",()=>this.handleScroll()),window.addEventListener("resize",()=>this.handleResize()),(document.documentElement.scrollTop||document.body.scrollTop)>this.stickySectionOffsetBottom&&(this.initialStateApplied=!0,this.updateDOM(!0,0,!0)))}handleScroll(){null===this.scrollTimeout&&(this.scrollTimeout=window.requestAnimationFrame(()=>{const t=document.documentElement.scrollTop||document.body.scrollTop;if(this.initialStateApplied)return this.initialStateApplied=!1,this.scrollPosition=t,void(this.scrollTimeout=null);const i=this.getScrollDirection(t);if(i===o&&t>this.stickySectionOffsetBottom&&!this.isSticky)return this.updateDOM(!0,0,!0),this.scrollPosition=t,void(this.scrollTimeout=null);const e=this.shouldStick(t,i),s=this.calculateVisibility(t,i);e===this.isSticky&&s===this.visiblePercentage||this.updateDOM(e,s),this.scrollPosition=t,this.scrollTimeout=null}))}handleResize(){null===this.resizeTimeout&&(this.resizeTimeout=window.setTimeout(()=>{this.stickySection.style.width=`${this.headerSection.offsetWidth}px`,this.headerHeight=this.stickySection.offsetHeight,this.placeholder&&(this.placeholder.style.height=`${this.headerHeight}px`),this.resizeTimeout=null},100))}getScrollDirection(t){const i=t>this.scrollPosition?o:"up";return i!==this.lastScrollDirection&&(this["up"===i?"upScrollStartPosition":"downScrollStartPosition"]=this.scrollPosition,this.lastScrollDirection=i),i}shouldStick(t,i){const e=t>this.stickySectionOffsetBottom;return i===o?e:e||this.isSticky&&t>this.stickySectionOffsetTop}applyEasing(t,i){const e=t/100;return"easeOut"===i?100*(1-(1-e)**3):"easeIn"===i?100*e**3:t}calculateVisibility(t,i){if(i===o){if(!this.isSticky)return 0;if(this.downScrollStartPosition>0){const i=this.visiblePercentage-(t-this.downScrollStartPosition)/this.headerHeight*100;return Math.max(0,this.applyEasing(i,"easeIn"))}return this.visiblePercentage}if(t>this.stickySectionOffsetBottom){const i=this.upScrollStartPosition-t;if(i<100)return 0;const e=(i-100)/this.headerHeight*100;return Math.min(100,Math.max(0,this.applyEasing(e,"easeOut")))}return this.isSticky&&this.visiblePercentage<100?Math.min(100,this.visiblePercentage+5):this.visiblePercentage}updateDOM(t,i){let e=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const o=this.isSticky;if(this.isSticky=t,this.visiblePercentage=e?0:i,t){if(!o&&!this.listenersAttached){const t=()=>{this.isSticky&&this.visiblePercentage<100&&this.updateDOM(!0,100)};this.stickySection.addEventListener("click",t);const i=document.querySelector(".gh-search-input");i&&i.addEventListener("click",t),this.listenersAttached=!0}!this.stickySection.classList.contains(s)&&this.stickySection.classList.add(s),this.placeholder&&(this.placeholder.style.display="block");const t=e?this.headerHeight:this.headerHeight*(1-this.visiblePercentage/100);this.stickySection.style.transform=`translateY(-${t}px)`,this.stickySection.style.transition=e?"":l,i<100&&window.eBayAC?.helpers?.hideSuggestions(window.eBayAC)}else this.stickySection.classList.remove(s),this.stickySection.style.transform="",this.stickySection.style.transition=l,this.placeholder&&(this.placeholder.style.display="none")}}}}]);