import{useCurrentDevice as e,useFeaturedImageGlobal as r,useEditorMode as o,getResponsiveValueByScreen as t}from"@gem-sdk/core";import{useState as i,useCallback as a,useEffect as s}from"react";import{getShapeByLayout as l,checkDisplayGalleryByWidth as n}from"../common/productGallery.js";import{useFilterImagesByVariant as p}from"./useFilterImagesByVariant.js";import{handleSetSrcForProductImageList as m}from"../../../../image/common/helpers.js";let d=d=>{let{builderPropUID:y,productImages:c,activeIndexFromFeatureImage:h,children:u,isHiddenInteraction:F,...f}=d,B=e(),q=r(),[g,I]=i(0),v=o(),{filteredProductImages:b}=p({productImages:c,displayByVariant:f?.displayByVariant,variantSelect:f?.variantSelect}),C=l({shape:f.shape,shapeForBottom:f.shapeForBottom,shapeFor1Col:f.shapeFor1Col,shapeFor2Col:f.shapeFor2Col,shapeForFtOnly:f.shapeForFtOnly,shapeForInsideBottom:f.shapeForInsideBottom,shapeForInside:f.shapeForInside},f.position),O=t(f.clickOpenLightBox,B),P=n({shapeByLayout:C}),j=t(P,B),x=f?.borderActive?.border!=="none",G=a(()=>{m({builderPropUID:y,shapeByLayout:C,qualityType:f.qualityType,qualityPercent:f.qualityPercent})},[C,f.qualityPercent,f.qualityType,y]);return s(()=>{I(h||0)},[h]),s(()=>{let e=b?.findIndex(e=>e.id===q?.id);I(e&&e>0?e:0)},[q,b]),s(()=>{if("edit"===v)return;let e=document?.querySelector(".grid-gallery");if(!e)return;G();let r=new ResizeObserver(()=>{G()});return r?.observe(e,{}),()=>{r?.disconnect()}},[G,y,v]),{isDisplay:j,shapeByLayout:C,imageActiveIndex:g,enableOpenLightBox:O,isEnableBorderActive:x,filteredProductImages:b}};export{d as useProductGalleryGrid};
