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 c=r(null),{children:o,totalSlides:u,onSwiperReset:l,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=()=>{c.current?.swiper&&c.current.swiper.wrapperEl.style.setProperty("width",`${c.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&&c.current&&(Object.assign(c.current,f),c.current.initialize?.(),a?.(c.current.swiper),E())},[y]),n(()=>{c.current?.swiper&&(c.current.swiper.destroy(!1,!1),Object.assign(c.current,f),c.current.initialize?.(),a(c.current.swiper),l())},[f.dir,f.loop,h,f.slidesPerView,a,l,f.spaceBetween,f.slidesOffsetBefore]),n(()=>{let e=c.current;e&&(Object.assign(e,f),e.swiper?.update(),E())},[f]),n(()=>{l()},[d,l]),n(()=>{let e=c.current;if(!e)return;let r=()=>{E()};return e.addEventListener("swiperresize",r),()=>{e.removeEventListener("swiperresize",r)}},[]),e("swiper-container",{init:!1,ref:c,class:w,style:{...g,display:y?"block":"none"},...j,children:o})}export{Swiper};
