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