import{jsx as e}from"react/jsx-runtime";import{useRef as r,useState as t,useMemo as i,useEffect as n}from"react";import{getStyleSwiperContainer as s}from"./common/styles.js";function Swiper(p){let o=r(null),{children:c,totalSlides:l,onSwiperReset:u,onSwiperReady:a,sliderClass:w,sliderOrder:d,thumbsSwiper:m,...f}=p,[y,b]=t(!1),j=i(()=>m?{"thumbs-swiper":m}:{},[m]),g=s(),h="object"==typeof p.autoplay&&null!==p.autoplay?p.autoplay.pauseOnMouseEnter:void 0,E=()=>{o.current?.swiper&&o.current.swiper.wrapperEl.style.setProperty("width",`${o.current.swiper.width}px`)};return n(()=>{let e=async()=>{let e=await import("@gem-sdk/swiper/element/bundle");e.register(),await window.customElements.whenDefined("swiper-container"),b(!0)};e()},[]),n(()=>{y&&(Object.assign(o.current,f),o.current.initialize(),a?.(o.current.swiper),E())},[y]),n(()=>{o.current?.swiper&&(o.current.swiper.destroy(!1,!1),Object.assign(o.current,f),o.current.initialize(),a(o.current.swiper),u())},[f.dir,f.loop,h,f.slidesPerView,a,u,f.spaceBetween,f.slidesOffsetBefore]),n(()=>{let e=o.current;e&&(Object.assign(e,f),e.swiper?.update(),E())},[f]),n(()=>{u()},[d,u]),n(()=>{let e=o.current;if(!e)return;let r=()=>{E()};return e.addEventListener("swiperresize",r),()=>{e.removeEventListener("swiperresize",r)}},[]),e("swiper-container",{init:!1,ref:o,class:w,style:{...g,display:y?"block":"none"},...j,children:c})}export{Swiper};
