'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),React=require("react"),core=require("@gem-sdk/core"),helpers=require("../arrow/common/helpers.js"),useCarousel=require("../../hooks/useCarousel.js"),helpers$1=require("./common/helpers.js"),classes=require("./common/classes.js"),styles=require("./common/styles.js"),attrs=require("./common/attrs.js"),Arrow=require("../arrow/Arrow.js"),Dots=require("../dot/Dots.js"),Swiper=require("../swiper/Swiper.js");require("@gem-sdk/system");const Carousel=React.forwardRef((e,r)=>{let{children:t,builderAttrs:s,builderProps:o,styles:i,isHiddenArrowWhenDisabled:l=!0,hiddenDotWhenOnlyOne:a,elmRef:n,isEnableCheckHasScrollableContent:u,onSwiperReady:d}=e,c=helpers.mappingNavigationCarousel(e.setting),p={...e,setting:c},m=React.Children.count(core.filterToolbarPreview(t))??0,[h,C]=React.useState(null),{arrowButtonSize:w,arrowBackgroundColor:R,arrowGapToEachSide:v="16",roundedArrow:S,arrowIconSize:j,arrowCustomColor:y,arrowBorder:k,arrowShadow:g,showWhenHover:x}=c??{},f=React.useRef({prevOrder:"",prevContent:"",version:0}),b=React.useMemo(()=>{let e=c?.childItem||[],r=e.join("|"),t=[...e].sort().join("|"),s=f.current;return s.prevOrder&&s.prevContent&&t===s.prevContent&&r!==s.prevOrder&&s.version++,s.prevOrder=r,s.prevContent=t,`reorder-${s.version}`},[c?.childItem]),{isInfinity:q,localRef:P,sliderSettings:D,totalSlideItem:E,currentSlide:$,isRenderDots:O,showNavigation:A,isScrollToStart:T,isScrollToEnd:I,handleDotClick:z,getItemsPerPage:N,handleNextAndPrevSlide:B,dispatchEventSelectSlide:M,getNumberOfFullWidthShow:W,setCurrentSlide:H,shouldDuplicateSlides:V,setIsScrollToStart:F,setIsScrollToEnd:G}=useCarousel.useCarousel(p,r,h,m),{loopConfig:_,arrowShowConfig:K}=helpers$1.getData(p),{rootClassRender:U,wrapperClassRender:J,wrapperInnerClass:L,sliderClass:Q}=classes.getClass(p),{rootStyleRender:X,wrapperStyleRender:Y,wrapperInnerStyle:Z}=styles.getStyle(p),{rootAttrRender:ee,sliderAttr:er}=attrs.getAttr(p),et=core.useCurrentDevice(),es=c?.sneakPeak?.[et],eo=r=>{let t="next"===r;if(m<=1)return null;let s=t?!q&&h?.isEnd:!q&&h?.isBeginning,i=t?!q&&I:!q&&T;return jsxRuntime.jsx(Arrow.default,{uid:o?.uid,custom:c?.arrowCustom??"",showArrow:K,arrowButtonSize:w||{},arrowIconSize:j||{},arrowBackgroundColor:R||"",arrowCustomColor:y,gapToEachSize:v,showWhenHover:x,arrowBorder:k||{},arrowCorner:S||{},arrowShadow:g||{},onClick:e=>{e.stopPropagation(),B(r)},left:!t,disabled:u?i:s,vertical:c?.vertical,isHiddenWhenDisabled:l,rootId:e?.parentClass})},ei=React.useCallback(e=>{C(e),d?.(e)},[]),el=React.useCallback(()=>{e?.isDisableResetSlide||(H(0),F(!0),G(!1))},[e?.isDisableResetSlide,H,G,F]),ea=React.Children.toArray(core.filterToolbarPreview(t)).filter(React.isValidElement),en=V(m),eu=en?2*m:m,ed=React.useMemo(()=>{if(!en)return ea;let e=ea.map((e,r)=>{if(!React.isValidElement(e))return e;let t=e.key,s=t?`${t}-duplicate-${r}`:`duplicate-${r}`;return React.cloneElement(e,{...e.props||{},key:s})});return[...ea,...e]},[en,ea]),ec=React.useMemo(()=>`${m}-${b}-${ed.length}-${D?.direction}`,[m,b,ed.length,D?.direction]);return jsxRuntime.jsx("div",{ref:n,...ee,className:U,style:X,children:jsxRuntime.jsxs("div",{ref:P,...s,className:J,style:Y,children:[jsxRuntime.jsxs("div",{className:L,style:Z,children:[A&&eo("prev"),React.createElement(Swiper.Swiper,{...er,...D,sliderClass:Q,thumbsSwiper:e?.thumbsSwiper,onSwiperReady:ei,totalSlides:E,key:ec,sliderOrder:b,onSwiperReset:el},core.isEmptyChildren(t)?jsxRuntime.jsx("div",{children:"No Slider"}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:ed.map((e,r)=>{if(!React.isValidElement(e))return null;let t=e.props??{};return React.createElement(e.type,{...t,key:e.key,indexKey:r.toString(),parentSettings:c,parentStyle:i,background:c?.background,parentUid:o?.uid,dispatchEventSelectSlide:M})})})),A&&eo("next")]}),O&&jsxRuntime.jsx(Dots.default,{dotStyle:c?.dotStyle,dotGapToCarousel:c?.dotGapToCarousel,vertical:c?.vertical,showDots:c?.dot,slideItemsPerPage:N(),enabledSneakPeak:es,dotColor:c?.dotColor,dotActiveColor:c?.dotActiveColor,dotSize:c?.dotSize,sneakPeakType:c?.sneakPeakType,totalSlideItem:eu,hiddenWhenOnlyOne:a,currentSlide:$,loop:_,numberOfFullWidthShow:W(et),onHandleClick:z,slideDuplicated:en}),core.filterToolbarPreview(t,!0)]})})});exports.default=Carousel;
