var c=class{constructor(e){this.heightCalculated=!1;this.isEnabled=!1;this.isCalculating=!1;this.fadeClasses={base:["absolute","top-0","left-0","w-full","h-full","visible","transition-opacity","duration-x-slow","ease-in-out"],active:["opacity-100","z-[1]"],inactive:["opacity-0","z-0"]};this.handleResize=()=>{this.isEnabled&&(this.resizeTimeout&&clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout(()=>{this.isEnabled&&(this.heightCalculated=!1,this.calculateHeight())},250))};this.carousel=e}enable(){this.isEnabled||(this.isEnabled=!0,this.calculateHeight(),window.addEventListener("resize",this.handleResize))}disable(){this.isEnabled&&(this.isEnabled=!1,this.removeFadeStyles(),this.carousel.style.removeProperty("--carousel-height"),this.carousel.scrollContainer&&this.carousel.scrollContainer.style.removeProperty("height"),this.heightCalculated=!1,this.isCalculating=!1,window.removeEventListener("resize",this.handleResize),this.resizeTimeout&&(clearTimeout(this.resizeTimeout),this.resizeTimeout=void 0))}updateActiveSlide(e){if(!this.isEnabled)return;this.carousel.getSlides().forEach((l,i)=>{i===e?this.show(l):this.hide(l)})}show(e){if(!this.isEnabled)return;let t=e.classList;t.remove(...this.getAllFadeClasses()),t.add(...this.fadeClasses.base,...this.fadeClasses.active),e.removeAttribute("inert"),e.setAttribute("aria-hidden","false")}hide(e){if(!this.isEnabled)return;let t=e.classList;t.remove(...this.getAllFadeClasses()),t.add(...this.fadeClasses.base,...this.fadeClasses.inactive),e.toggleAttribute("inert",!0),e.setAttribute("aria-hidden","true")}removeFadeStyles(){this.carousel.getSlides().forEach(t=>{t.classList.remove(...this.getAllFadeClasses()),t.removeAttribute("inert"),t.removeAttribute("aria-hidden")})}getAllFadeClasses(){return[...this.fadeClasses.base,...this.fadeClasses.active,...this.fadeClasses.inactive]}calculateHeight(){if(this.heightCalculated||!this.isEnabled||this.isCalculating)return;let e=this.carousel.getSlides(),t=this.carousel.scrollContainer;if(e.length===0||!t)return;this.isCalculating=!0,t.style.removeProperty("height"),this.carousel.style.removeProperty("--carousel-height");let l=e.map(i=>{let s=i,a={position:s.style.position,opacity:s.style.opacity,zIndex:s.style.zIndex,transform:s.style.transform,classes:s.className};return s.classList.remove(...this.getAllFadeClasses()),s.classList.add("relative","opacity-1","z-auto","transform-none"),a});requestAnimationFrame(()=>{if(!this.isEnabled){this.isCalculating=!1;return}let i=e.map(a=>a.getBoundingClientRect().height),s=Math.max(...i);e.forEach((a,u)=>{let r=a,h=l[u];r.className=h.classes,["position","opacity","zIndex","transform"].forEach(o=>{let n=h[o];n?r.style.setProperty(o,n):r.style.removeProperty(o)})}),s>0&&(this.carousel.style.setProperty("--carousel-height",`${s}px`),t.style.height=`${s}px`,this.heightCalculated=!0,this.updateActiveSlide(this.carousel.activeSlide)),this.isCalculating=!1})}recalculateHeight(){this.isEnabled&&(this.resizeTimeout&&(clearTimeout(this.resizeTimeout),this.resizeTimeout=void 0),this.heightCalculated=!1,this.calculateHeight())}};export{c as a};
