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