document.querySelectorAll(".auto-carousel").forEach(e=>{const t=e.querySelector("ul");if(!t)return;const n=[...t.children],o=[...e.querySelectorAll("ol li")],p=e.querySelector(".prev"),u=e.querySelector(".next");let r=!1,c=0,l=0;const f=()=>{if(n.length<2)return;const e=n[1].offsetLeft-n[0].offsetLeft;if(e<=0)return;const s=Math.min(Math.round(t.scrollLeft/e),n.length-1);o.forEach((e,t)=>e.classList.toggle("selected",t===s)),n.forEach((e,t)=>e.classList.toggle("selected",t===s))},i=e=>{const s=n[e];s&&(t.scrollLeft=s.offsetLeft)},d=()=>Math.max(0,o.findIndex(e=>e.classList.contains("selected"))),s=()=>t.classList.add("interacted");o[0]?.classList.add("selected"),n[0]?.classList.add("selected"),u?.addEventListener("click",()=>{s(),i((d()+1)%n.length)}),p?.addEventListener("click",()=>{s(),i((d()-1+n.length)%n.length)}),o.forEach((e,t)=>{e.querySelector("a")?.addEventListener("click",e=>{e.preventDefault(),s(),i(t)})});let a=!1;t.addEventListener("scroll",()=>{if(a)return;a=!0,requestAnimationFrame(()=>{a=!1,f()})},{passive:!0}),t.addEventListener("mousedown",e=>{r=!0,s(),t.classList.add("grabbing"),c=e.pageX-t.offsetLeft,l=t.scrollLeft});const h=()=>{r=!1,t.classList.remove("grabbing")};t.addEventListener("mouseleave",h),t.addEventListener("mouseup",h),t.addEventListener("mousemove",e=>{if(!r)return;e.preventDefault();const n=e.pageX-t.offsetLeft;t.scrollLeft=l-(n-c)*3}),t.addEventListener("touchstart",s,{passive:!0});const m=Number(e.getAttribute("duration"));m>0&&!matchMedia("(prefers-reduced-motion: reduce)").matches&&setInterval(()=>{if(t.classList.contains("interacted"))return;if(e.matches(":hover"))return;u?.click()},m)})