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