'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 n,useMemo as s,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 k}from"./common/styles.js";import{getAttr as y}from"./common/attrs.js";import C 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:$,builderAttrs:O,builderProps:P,styles:A,isHiddenArrowWhenDisabled:D=!0,hiddenDotWhenOnlyOne:I,elmRef:x,isEnableCheckHasScrollableContent:z,onSwiperReady:T}=t,B=S(t.setting),N={...t,setting:B},R=i.count(c($))??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=n({prevOrder:"",prevContent:"",version:0}),V=s(()=>{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:en,handleNextAndPrevSlide:es,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:ek}=f(N),{rootStyleRender:ey,wrapperStyleRender:eC,wrapperInnerStyle:eg}=k(N),{rootAttrRender:ej,sliderAttr:eb}=y(N),e$=u(),eO=B?.sneakPeak?.[e$],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(C,{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(),es(r)},left:!o,disabled:z?l:i,vertical:B?.vertical,isHiddenWhenDisabled:D,rootId:t?.parentClass})},eA=a(e=>{E(e),T?.(e)},[]),eD=a(()=>{t?.isDisableResetSlide||(em(0),ec(!0),eu(!1))},[t?.isDisableResetSlide,em,eu,ec]),eI=i.toArray(c($)).filter(d),ex=ep(R),ez=ex?2*R:R,eT=s(()=>{if(!ex)return eI;let e=eI.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[...eI,...e]},[ex,eI]),eB=s(()=>{let e=i.toArray($),r=e[0];return d(r)?r.key:""},[$]),eN=s(()=>`${R}-${V}-${eT.length}-${Z?.direction}-${eB}`,[R,V,eT.length,Z?.direction,eB]);return e("div",{ref:x,...ej,className:ev,style:ey,children:r("div",{ref:Y,...O,className:ew,style:eC,children:[r("div",{className:ef,style:eg,children:[eo&&eP("prev"),p(j,{...eb,...Z,sliderClass:ek,thumbsSwiper:t?.thumbsSwiper,onSwiperReady:eA,totalSlides:_,key:eN,sliderOrder:V,onSwiperReset:eD},h($)?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:A,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:en(),enabledSneakPeak:eO,dotColor:B?.dotColor,dotActiveColor:B?.dotActiveColor,dotSize:B?.dotSize,sneakPeakType:B?.sneakPeakType,totalSlideItem:ez,hiddenWhenOnlyOne:I,currentSlide:ee,loop:eh,numberOfFullWidthShow:ed(e$),onHandleClick:el,slideDuplicated:ex}),c($,!0)]})})});export{Carousel as default};
