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 p(p){let c=r(null),{children:u,totalSlides:l,onSwiperReset:o,onSwiperReady:a,sliderClass:w,sliderOrder:d,thumbsSwiper:m,...f}=p,[y,b]=t(!1),j=r(f);j.current=f;let g=i(()=>m?{"thumbs-swiper":m}:{},[m]),h=s(),E="object"==typeof p.autoplay&&null!==p.autoplay?p.autoplay.pauseOnMouseEnter:void 0,O=()=>{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),O())},[y]),n(()=>{c.current?.swiper&&(c.current.swiper.destroy(!1,!1),Object.assign(c.current,j.current),c.current.initialize?.(),a(c.current.swiper),o())},[f.dir,f.loop,E,f.slidesPerView,a,o,f.spaceBetween]),n(()=>{let e=c.current;e?.swiper&&(Object.assign(e,j.current),e.swiper.update(),O())},[f.speed,f.spaceBetween,f.slidesPerView,f.direction,f.slidesOffsetBefore,f.isSneakPeekCenter]),n(()=>{o()},[d,o]),n(()=>{let e=c.current;if(!e)return;let r=()=>{O()};return e.addEventListener("swiperresize",r),()=>{e.removeEventListener("swiperresize",r)}},[]),e("swiper-container",{init:!1,ref:c,class:w,style:{...h,display:y?"block":"none"},...g,children:u})}export{p as Swiper};
