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