"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("@gem-sdk/core"),t=require("react"),i=require("../gallery-carousel/GalleryCarousel.js"),s=require("../child/ProductGalleryGrid.js"),l=require("../child/ProductFeaturedImageCarousel.js"),u=require("../../composables/getProductImagesStyles.js"),a=require("../../composables/getProductImagesClassName.js"),d=require("../../hooks/useFeatureImageWithGallery.js"),n=require("../../common/common.js");exports.default=o=>{let{setting:c,styles:m,builderProps:g,gallery:p,featureGallery:f,onHandleClickImage:I,priorityFeatureImage:h,children:b,noDataChildren:v,isFilterByVariantEnabled:C}=o,{isEditMode:y}=r.useRenderMode(),x=t.useRef(null),j=r.useCurrentDevice(),P=r.useUniqProductID(),q=n.getProductImagesCarouselInstanceId(g?.uid,P),F=t.useRef(p);F.current=p;let k=t.useRef(f??p);k.current=f??p;let R=t.useRef(null);t.useEffect(()=>()=>{R.current?.(),R.current=null},[]);let w=t.useCallback((e,r)=>{if(e.destroyed||r.destroyed)return;let t=k.current[e.realIndex]?.id;if(void 0===t)return;let i=F.current.findIndex(e=>e?.id===t);if(r.slides?.forEach(e=>e.classList.remove("gem-slider-item-active")),i<0)return;let s=r.slides?.[i];s?.classList.add("gem-slider-item-active");let l=s?.getBoundingClientRect(),u=r.el?.getBoundingClientRect();if(!l||!u){r.slideTo(i);return}let a=r.params?.direction==="vertical"?l.top>=u.top-1&&l.bottom<=u.bottom+1:l.left>=u.left-1&&l.right<=u.right+1;a||r.slideTo(i)},[]),D=t.useCallback(e=>{if(!x.current)return;let r=x.current.getSwiper();if(r&&e){if(R.current?.(),R.current=null,C){let t=()=>w(r,e);r.on("slideChange",t),R.current=()=>{r.destroyed||r.off("slideChange",t)},t();return}r.thumbs&&r.thumbs.swiper&&r.thumbs.swiper?.realIndex===void 0&&(r.thumbs.swiper=e,r.thumbs.init(),r.thumbs.update(!0),r.update())}},[C,w]),U={...c,...m},{isShowCarousel:G,featureImageHeight:H,featureWrapperImage:N,onClickFeatureArrow:L,activeIndexFromFeatureImage:S,setOnClickFeatureArrow:$,onHandleLoadedFeatureImage:A,setActiveIndexFromFeatureImage:E}=d.useFeatureImageWithGallery(o),M=t.useMemo(()=>{if(void 0===S)return;let e=(f??p)[S]?.id;if(void 0===e)return;let r=p.findIndex(r=>r?.id===e);return r>-1?r:void 0},[S,f,p]);if(p?.[0]?.id==="noImageError"&&y)return e.jsx(e.Fragment,{children:v});let{ftImageGalleryClasses:T,imageGalleryWrapperClasses:B}=a.getProductImagesClassName(o),{wrapperFeaturedImageStyle:W,featureImageStyle:_,galleryImageStyle:K}=u.getProductImagesStyles(U,{gallery:p,featureImageHeight:H}),O=`${n.getFeatureGalleryComponentKey(U,j,G)}|${C?"variant-filtered":"all-media"}`;return e.jsxs("div",{className:r.cls("gp-grid gp-w-full gp-relative"),style:W,children:[e.jsxs("div",{className:T,style:_,children:[b,e.jsx(l.default,{ref:x,imgRef:N,productImages:f??p,enableThumbsLink:!C,...U,onHandleClick:(e,r)=>I(e||"",r,!0),onHandleLoaded:A,onHandleUpdateActiveIndex:E,onClickArrow:e=>$(e),builderPropUID:g?.uid,carouselInstanceUID:q,builderPropsClass:`gp-product-images-feature-${g?.uid}`})]}),p.length>(C?0:1)&&e.jsx("div",{className:B,style:K,children:G?e.jsx(i.default,{productImages:p,position:U?.position,...U,builderPropUID:g?.uid,carouselInstanceUID:q,onHandleClick:(e,r)=>I(e||"",r),onSwiperReady:D,activeIndexFormFeatureImage:M,priorityFeatureImage:h,onClickFeatureArrow:L,builderPropsClass:`gp-product-images-gallery-${g?.uid}`}):e.jsx(s.default,{productImages:p,...U,builderPropUID:g?.uid,onHandleClick:(e,r)=>I(e||"",r),activeIndexFromFeatureImage:M,isHiddenInteraction:!0})})]},O)};
