'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@gem-sdk/core"),i=require("react"),r=require("./product-images/ProductFeaturedImage.js"),s=require("../helpers/product-image.js"),o=require("./product-images/common/helpers.js"),l=require("./product-images/ProductGalleryCarousel.js"),a=require("./product-images/ProductGalleryGrid.js"),u=require("./product-images/ProductImagesLightBox.js"),n=require("./product-images/common/productGallery.js");const g=["mobile","tablet","desktop"],c=e=>e?.medias?.edges.map(e=>e?.node);exports.default=p=>{let{setting:d,styles:m,builderProps:f,builderAttrs:b,style:h,children:y}=p,I={...p.styles,...p.setting},V={...p.styles,...p.setting},v=t.useProduct(),j=t.useCurrentDevice(),x=t.useCurrentVariant(),S=t.useProductStore(e=>e.setProductFeaturedImage),[w,R]=i.useState(!1),[P,k]=i.useState(100),B=i.useRef(null),q=t.getResponsiveValueByScreen(d?.galleryVisible,j),H=t.getResponsiveValueByScreen(d?.featureImageVisible,j),M=i.useMemo(()=>t.getResponsiveValueByScreen(m?.position,j),[j,m?.position]),C=i.useMemo(()=>n.getStyleWidthForGallery({galleryVisible:d?.galleryVisible,featureImageVisible:d?.featureImageVisible,position:m?.position,width:m?.width,widthHorizontalLayout:m?.widthHorizontalLayout}),[m?.position,m?.width,m?.widthHorizontalLayout,d?.galleryVisible,d?.featureImageVisible]),D=i.useMemo(()=>{let e=c(v);return e?.length?e:[{id:v?.featuredImage?.id??"noImageError",baseID:v?.featuredImage?.baseID??"noImageError",src:v?.featuredImage?.src??"https://cdn.shopify.com/s/assets/no-image-2048-5e88c1b20e087fb7bbe9a3771824e743c244f437e4f8ba93bbf7b11b53f7824c_large.gif",width:v?.featuredImage?.width??480,height:v?.featuredImage?.height??480}]},[v]),E=i.useMemo(()=>o.getStyleAlignment(m?.align,m?.position),[m?.position,m?.align]),G=i.useMemo(()=>D.reduce((e,t,i)=>t?{...e,[t.id]:i}:e,{}),[D]),F=i.useMemo(()=>n.getStyleGallerySpacing(m?.position,m?.gallerySpacing),[m?.position,m?.gallerySpacing]),L=i.useMemo(()=>o.checkAddOverFlowClass(h),[h]),N=i.useMemo(()=>{let e={};return g.forEach(i=>{let r=o.convertUnitToNumber(m?.height?.[i],0),s=t.getResponsiveValueByScreen(d?.galleryVisible,i),l=t.getResponsiveValueByScreen(d?.featureImageVisible,i),a=t.getResponsiveValueByScreen(m?.position,i);e=r?"number"==typeof m?.height?.[i]?{...e,[i]:m?.height?.[i]+"px"}:m?.height?.[i]?.includes("%")?{...e,[i]:o.convertUnitToNumber(m?.height?.[i],P)*P/100+"px"}:{...e,[i]:m?.height?.[i]}:{...e,[i]:("left"===a||"right"===a)&&s&&l?P+"px":"auto"}}),e},[P,m?.height,m?.position,d?.featureImageVisible,d?.galleryVisible]),U=i.useCallback(()=>t.makeStyleResponsive("h",t.makeHeight(N)),[N]);i.useEffect(()=>{if(x){let e=G[x?.mediaId]??0,t=D[e]??v?.featuredImage;t&&S(t)}},[x,G,D,v?.featuredImage,S]),i.useEffect(()=>{let e=null;return B?.current&&(e=new ResizeObserver(()=>{k(B?.current?.offsetHeight??0)})).observe(B.current,{}),()=>{e?.disconnect()}},[d?.featureImageVisible,j]),i.useEffect(()=>{d?.featureImageVisible&&setTimeout(()=>{k(B?.current?.offsetHeight??0)},100)},[d?.featureImageVisible,j]);let z=e=>{if(!e)return;let t=G[e];if(void 0!==t){let e=D[t];e&&S(e)}},O=e=>{let i=d?.clickEffect=="popup"||t.getResponsiveValueByScreen(d?.largeViewInPopup,j);i&&R(!0),z(e)},T=e=>{let i=t.getResponsiveValueByScreen(d?.largeViewInPopup,j);i&&O(e),z(e)};return e.jsxs("div",{...b,className:t.cls(f?.uid,{"gp-overflow-hidden":L}),style:{...h},children:[e.jsxs("div",{className:t.cls("gp-flex gp-w-full",{...s.getFlexDirection(p)}),style:{...E},children:[H&&e.jsx(r.default,{imgRef:B,productImages:D,...I,onOpenLightBox:()=>R(!0)}),q&&D.length>1&&e.jsx("div",{className:t.cls("gp-product-images-gallery gp-inline-flex gp-h-fit gp-max-w-full",{"gp-justify-start":m?.position?.desktop=="bottom-left","tablet:gp-justify-start":m?.position?.tablet=="bottom-left","mobile:gp-justify-start":m?.position?.mobile=="bottom-left","gp-justify-center":m?.position?.desktop=="bottom-center","tablet:gp-justify-center":m?.position?.tablet=="bottom-center","mobile:gp-justify-center":m?.position?.mobile=="bottom-center","gp-mx-auto":"bottom-center"==M}),style:{...t.makeStyle({fs:"1.23"}),...C,...F,...U()},children:"slider"===o.getTypeWidthDevice(d?.type)[j]||"left"===M||"right"===M?e.jsx(l.default,{productImages:D,...V,builderPropUID:f?.uid,onHandleClick:e=>T(e||"")}):e.jsx(a.default,{productImages:D,...V,builderPropUID:f?.uid,onHandleClick:e=>T(e||"")})})]}),(d?.clickEffect=="popup"||t.getResponsiveValueByScreen(d?.largeViewInPopup,j))&&e.jsx(u.default,{productImages:D,builderPropUID:f?.uid,open:w,onHandleClose:()=>R(!1),imageRatio:m?.ftAspectRatio}),y]})};
