"use strict";var e=require("@gem-sdk/core"),t=require("react"),r=require("./useFilterImagesByVariant.js"),s=require("../../../../image/common/helpers.js"),o=require("../common/productGallery.js");exports.useGalleryCarousel=a=>{let{builderPropUID:i,productImages:u,onHandleClick:l,activeIndexFormFeatureImage:n,onClickFeatureArrow:c,builderPropsClass:p,arrow:d,priorityFeatureImage:h,...y}=a,m=e.useCurrentDevice(),F=e.useFeaturedImageGlobal(),[f,B]=t.useState(c||""),g=e.useEditorMode(),[I,S]=t.useState(0),q=t.useRef(),[v,C]=t.useState(I),[b,E]=t.useState(!1),{filteredProductImages:T}=r.useFilterImagesByVariant({productImages:u,displayByVariant:y?.displayByVariant,variantSelect:y?.variantSelect});t.useEffect(()=>{B(c||"")},[c]),t.useEffect(()=>{q.current&&clearTimeout(q.current),f&&(q.current=setTimeout(()=>{S(n||0),B("")}))},[n]),t.useEffect(()=>{if(h){let e=T?.findIndex(e=>e.id===h.id)||0;S(e),B("")}},[h,T]),t.useEffect(()=>{let e=T?.findIndex(e=>e.id===F?.id);S(e||0),B("")},[F,T]);let V=t.useMemo(()=>o.getShapeByLayout({shape:y.shape,shapeForBottom:y.shapeForBottom,shapeFor1Col:y.shapeFor1Col,shapeFor2Col:y.shapeFor2Col,shapeForFtOnly:y.shapeForFtOnly,shapeForInsideBottom:y.shapeForInsideBottom,shapeForInside:y.shapeForInside},y.position),[y.shape,y.shapeForBottom,y.shapeFor1Col,y.shapeFor2Col,y.shapeForFtOnly,y.position,y.shapeForInsideBottom,y.shapeForInside]),k=t.useCallback(()=>{s.handleSetSrcForProductImageList({builderPropUID:i,shapeByLayout:V,qualityType:y.qualityType,qualityPercent:y.qualityPercent})},[V,y.qualityPercent,y.qualityType,i]);t.useEffect(()=>{if("edit"===g)return;let e=document?.querySelector(`.gem-slider-item-${i} .product-list-image`);if(!e)return;k();let t=new ResizeObserver(()=>{k()});return t?.observe(e,{}),()=>{t?.disconnect()}},[k,i,g]);let O=e.getResponsiveValueByScreen(y.clickOpenLightBox,m),x=t.useMemo(()=>{let t=o.checkDisplayGalleryByWidth({shapeByLayout:V});return e.getResponsiveValueByScreen(t,m)},[V,m]),R=t.useMemo(()=>y?.borderActive?.border!=="none",[y?.borderActive?.border]),G=e.getResponsiveValueByScreen(y?.clickOpenLightBox,m);return t.useEffect(()=>{let e;return T&&T.length>0&&b&&(e=setTimeout(()=>{C(I)},80)),()=>{e&&clearTimeout(e)}},[I,T,b]),{moveToIdx:I,isDisplay:x,shapeByLayout:V,isEnableBorderActive:R,isShowButtonLightbox:G,filteredProductImages:T,handleClickCarouselItem:e=>{l&&l(e||"",O)},setSliderReady:E,safeMoveToIdx:v}};
