import{jsx as e}from"react/jsx-runtime";import{useRef as r,useMemo as t,useCallback as n,useEffect as i}from"react";import{getStyleSwiperContainer as s}from"./common/styles.js";import{register as l}from"@gem-sdk/swiper/element/bundle";function c(l){let c=r(null),u=r(null),{children:o,totalSlides:p,onSwiperReset:m,onSwiperReady:w,sliderClass:a,sliderOrder:d,thumbsSwiper:f,...y}=l,b=t(()=>f?{"thumbs-swiper":f}:{},[f]),h=s(),z=(e,r)=>{if(!e?.wrapperEl)return!1;let t=e.el,n=r||e.width||t?.clientWidth||t?.parentElement?.clientWidth||0;return!(n<=0)&&(e.wrapperEl.style.setProperty("width",`${n}px`),!0)},O=n(({width:e}={})=>{!z(c.current?.swiper,e)&&"undefined"!=typeof window&&c.current&&(u.current&&cancelAnimationFrame(u.current),u.current=window.requestAnimationFrame(()=>{u.current=null,z(c.current?.swiper,e)}))},[]);return i(()=>{let e;let r=c.current;if(!r)return;let t="function"==typeof r.closest&&!!r.closest("swiper-slide");Object.assign(r,{...y,...t&&{nested:!0}}),r.initialize?.(),w?.(r.swiper),O(),r.swiper?.on?.("resize",O);let n=r.parentElement;return n&&"undefined"!=typeof ResizeObserver&&(e=new ResizeObserver(()=>{let e=c.current?.swiper;e&&!(e.width>0)&&(O(),e.update?.())})).observe(n),()=>{r.swiper?.off?.("resize",O),e?.disconnect(),m(),u.current&&(cancelAnimationFrame(u.current),u.current=null)}},[]),i(()=>{let e=c.current,r=e?.swiper;e&&r&&!r.destroyed&&(Object.assign(e,y),r.update(),O())},[JSON.stringify(y)]),i(()=>{m()},[d,m]),e("swiper-container",{init:!1,ref:c,class:a,style:{...h},...b,children:o})}l();export{c as Swiper};
