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