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