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