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