let AutoPlayPlugin=e=>{let n,o=e.options.autoplay??{},t=!1,r=!1,a=null,i=e?.container?.closest('[data-component-type="component"]')?.querySelector(".carousel-dots");function s(e){e.forEach(e=>{(r=e.isIntersecting)?v():c()})}function u(){!a&&e.container&&(a=new IntersectionObserver(s,{root:null,threshold:0})).observe(e.container)}function c(){clearTimeout(n)}function v(){c(),n=setTimeout(()=>{!t&&o.enable&&r&&e.next()},o.delay??2e3)}function d(){t=!0,c()}function l(){t=!1,v()}e.on("created",()=>{i?.addEventListener("mouseover",d),i?.addEventListener("mouseout",l),o.pauseOnHover&&e.container&&(e.container.addEventListener("mouseover",d),e.container.addEventListener("mouseout",l)),o.enable&&(u(),v())}),e.on("dragStarted",c),e.on("animationEnded",v),e.on("updated",e=>{(o=e.options?.autoplay??{}).enable&&(u(),v())}),e.on("optionsChanged",n=>{n.options.autoplay?.pauseOnHover!==o.pauseOnHover&&e.container&&(n.options.autoplay?.pauseOnHover?(e.container.addEventListener("mouseover",d),e.container.addEventListener("mouseout",l)):(e.container.removeEventListener("mouseover",d),e.container.removeEventListener("mouseout",l),t=!1)),(o=n.options.autoplay??{}).enable&&(u(),v())}),e.on("destroyed",()=>{e.container&&(e.container.removeEventListener("mouseover",d),e.container.removeEventListener("mouseout",l)),i?.removeEventListener("mouseover",d),i?.removeEventListener("mouseout",l),c(),a&&(a.disconnect(),a=null)})};export{AutoPlayPlugin};
