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