import{g as e}from"./swiper-core-DAv5_-eK.js";function a(a){let t,n,{swiper:r,extendParams:i,on:o,emit:s,params:p}=a;r.autoplay={running:!1,paused:!1,timeLeft:0},i({autoplay:{enabled:!1,delay:3e3,waitForTransition:!0,disableOnInteraction:!1,stopOnLastSlide:!1,reverseDirection:!1,pauseOnMouseEnter:!1}});let l,u,d,y,m,c,v,g,T=p&&p.autoplay?p.autoplay.delay:3e3,f=p&&p.autoplay?p.autoplay.delay:3e3,w=(new Date).getTime();function b(e){r&&!r.destroyed&&r.wrapperEl&&e.target===r.wrapperEl&&(r.wrapperEl.removeEventListener("transitionend",b),g||e.detail&&e.detail.bySwiperTouchMove||D())}const E=()=>{if(r.destroyed||!r.autoplay.running)return;r.autoplay.paused?u=!0:u&&(f=l,u=!1);const e=r.autoplay.paused?l:w+f-(new Date).getTime();r.autoplay.timeLeft=e,s("autoplayTimeLeft",e,e/T),n=requestAnimationFrame((()=>{E()}))},L=e=>{if(r.destroyed||!r.autoplay.running)return;cancelAnimationFrame(n),E();let a=void 0===e?r.params.autoplay.delay:e;T=r.params.autoplay.delay,f=r.params.autoplay.delay;const i=(()=>{let e;if(e=r.virtual&&r.params.virtual.enabled?r.slides.filter((e=>e.classList.contains("swiper-slide-active")))[0]:r.slides[r.activeIndex],!e)return;return parseInt(e.getAttribute("data-swiper-autoplay"),10)})();!Number.isNaN(i)&&i>0&&void 0===e&&(a=i,T=i,f=i),l=a;const o=r.params.speed,p=()=>{r&&!r.destroyed&&(r.params.autoplay.reverseDirection?!r.isBeginning||r.params.loop||r.params.rewind?(r.slidePrev(o,!0,!0),s("autoplay")):r.params.autoplay.stopOnLastSlide||(r.slideTo(r.slides.length-1,o,!0,!0),s("autoplay")):!r.isEnd||r.params.loop||r.params.rewind?(r.slideNext(o,!0,!0),s("autoplay")):r.params.autoplay.stopOnLastSlide||(r.slideTo(0,o,!0,!0),s("autoplay")),r.params.cssMode&&(w=(new Date).getTime(),requestAnimationFrame((()=>{L()}))))};return a>0?(clearTimeout(t),t=setTimeout((()=>{p()}),a)):requestAnimationFrame((()=>{p()})),a},O=()=>{w=(new Date).getTime(),r.autoplay.running=!0,L(),s("autoplayStart")},S=()=>{r.autoplay.running=!1,clearTimeout(t),cancelAnimationFrame(n),s("autoplayStop")},M=(e,a)=>{if(r.destroyed||!r.autoplay.running)return;clearTimeout(t),e||(v=!0);const n=()=>{s("autoplayPause"),r.params.autoplay.waitForTransition?r.wrapperEl.addEventListener("transitionend",b):D()};if(r.autoplay.paused=!0,a)return c&&(l=r.params.autoplay.delay),c=!1,void n();const i=l||r.params.autoplay.delay;l=i-((new Date).getTime()-w),r.isEnd&&l<0&&!r.params.loop||(l<0&&(l=0),n())},D=()=>{r.isEnd&&l<0&&!r.params.loop||r.destroyed||!r.autoplay.running||(w=(new Date).getTime(),v?(v=!1,L(l)):L(),r.autoplay.paused=!1,s("autoplayResume"))},F=()=>{if(r.destroyed||!r.autoplay.running)return;const a=e();"hidden"===a.visibilityState&&(v=!0,M(!0)),"visible"===a.visibilityState&&D()},h=e=>{"mouse"===e.pointerType&&(v=!0,g=!0,r.animating||r.autoplay.paused||M(!0))},A=e=>{"mouse"===e.pointerType&&(g=!1,r.autoplay.paused&&D())};o("init",(()=>{r.params.autoplay.enabled&&(r.params.autoplay.pauseOnMouseEnter&&(r.el.addEventListener("pointerenter",h),r.el.addEventListener("pointerleave",A)),e().addEventListener("visibilitychange",F),O())})),o("destroy",(()=>{r.el&&"string"!=typeof r.el&&(r.el.removeEventListener("pointerenter",h),r.el.removeEventListener("pointerleave",A)),e().removeEventListener("visibilitychange",F),r.autoplay.running&&S()})),o("_freeModeStaticRelease",(()=>{(y||v)&&D()})),o("_freeModeNoMomentumRelease",(()=>{r.params.autoplay.disableOnInteraction?S():M(!0,!0)})),o("beforeTransitionStart",((e,a,t)=>{!r.destroyed&&r.autoplay.running&&(t||!r.params.autoplay.disableOnInteraction?M(!0,!0):S())})),o("sliderFirstMove",(()=>{!r.destroyed&&r.autoplay.running&&(r.params.autoplay.disableOnInteraction?S():(d=!0,y=!1,v=!1,m=setTimeout((()=>{v=!0,y=!0,M(!0)}),200)))})),o("touchEnd",(()=>{if(!r.destroyed&&r.autoplay.running&&d){if(clearTimeout(m),clearTimeout(t),r.params.autoplay.disableOnInteraction)return y=!1,void(d=!1);y&&r.params.cssMode&&D(),y=!1,d=!1}})),o("slideChange",(()=>{!r.destroyed&&r.autoplay.running&&(c=!0)})),Object.assign(r.autoplay,{start:O,stop:S,pause:M,resume:D})}export{a as A};
