import{makeStyleResponsive as e,cls as a,template as i}from"@gem-sdk/core";import{getAspectRatio as t,getPaddingBottomByShapeSetting as r,getSrcImage as s}from"../../common/common.js";import{checkRenderFeaturedCarousel as d,getZoomImageClass as o,getZoomLenClass as u,getVideoHeight as m}from"../../common/productFeaturedImage.js";import{FEATURE_MEDIA_CENTER_CLASSES as l}from"../../common/classes.js";import p from"../../../../../video/components/HTML5Embed.liquid.js";import g from"../../../../../image/components/Modal3d.liquid.js";import n from"../../../../../image/components/NextImage.liquid.js";import c from"../../../../../image/components/Video.liquid.js";import{getStyleOfObject as f}from"../../../../helpers/function.js";import{getProductImagesStyles as h}from"../../composables/getProductImagesStyles.js";import{getProductImagesClassName as y}from"../../composables/getProductImagesClassName.js";import{getProductImagesAttr as M}from"../../composables/getProductImagesAttr.js";import{If as _,LiquidIf as w,LiquidFor as v,Liquid as b,createStyle as $}from"@gem-sdk/system";import I from"../../../../../carousel-v3/components/root/Carousel.liquid.js";import x from"../../../../../carousel-v3/components/item/CarouselItem.liquid.js";let q=({builderPropUID:q,children:S,pageContext:z,...j})=>{let{featuredImageCarouselClasses:L,galleryItemClasses:P,featuredCarouselItemClasses:R}=y({...j,builderProps:{uid:q}}),{featuredImageCarouselStyle:T,featureImageStyle:W,featureImageCarouselOnlyOneImageStyle:C,featureImageOnlyOneImageStyle:N,featureImageCarouselItemStyle:k}=h(j),{featuredImageCarouselSettingAttrs:E}=M(j),O=t(j.ftShape),A=_("other"==j.hoverEffect,w("product.media.size > 1","group-hover:gp-opacity-0")),D=()=>`
    {% case featureMedia.media_type %}
      {% when 'image' %}
        ${B()}
      {% when 'external_video' %}
        {% assign mediaSourceVideo = featureMedia | external_video_url %}
        ${H()}
      {% when 'video' %}
        {% assign mediaSourceVideo = featureMedia.sources.last.url %}
        ${F()}
      {% when 'model' %}
        ${V()}
      {% else %}
        ${J()}
    {% endcase %}
    `,V=()=>g({src:w("featureMedia.sources.first.url contains '.glb'","{{ featureMedia.sources.first.url }}","{{featureMedia.sources.last.url}}"),alt:"{{featureMedia.preview_image.alt}}",poster:"{{featureMedia.preview_image.src | product_img_url: '1024x1024'}}",cameraControls:!0,arStatus:"not-presenting",style:{width:"100%"},aspectRatio:O}),H=()=>c({src:"{{mediaSourceVideo}}",alt:"{{featureMedia.alt | escape}}",autoplay:!1,allowfullscreen:!0,controls:!0,style:{width:"100%",height:"100%"},aspectRatio:O}),F=()=>{let a=$({...m({ftLayout:j?.ftLayout,ftShape:j?.ftShape}),...e("objf",j?.ftLayout)}),i=$({...m({ftLayout:j?.ftLayout,ftShape:j?.ftShape})});return p({src:"{{mediaSourceVideo}}",title:"{{featureMedia.alt | escape}}",autoplay:!1,controls:!0,thumbnail:"{{featureMedia.preview_image.src | product_img_url: '1024x1024'}}",isCheckLoaded:!0,wrapperStyles:i,poster:{altText:"{{featureMedia.alt | escape}}"},style:{width:"100%","max-height":"100%",...a},className:"gp-invisible",pageContext:z})},B=()=>i`
      ${G(a("gp-w-full gp-transition-opacity",A,"{{shouldHidden}}"))}
      ${_(j?.hoverEffect!=="none",`<div class="${a("zoom-element !gp-max-w-none",o())}">
            ${G("image-zoom",!0)}
          </div>`," ")}
      ${_(j?.hoverEffect=="zoom"&&j?.zoomType=="glasses",`<div class="${a("zoom-lens-element",u())}" style="opacity: 0; background-image: url('{{ featureMedia.src | img_url: "1024x1024"}}')"></div>`," ")}
    `,G=(e,a)=>i`
    {% assign src = featureMedia.src %}
    ${_(a&&"other"==j.hoverEffect,`{% assign media_length = product.media | size %}
      {% assign other_image_index = ${j.otherImage} | plus: 0 %}
      {% if other_image_index >= media_length %}
        {% assign other_image_index = media_length | minus: 1 %}
      {% endif %}
      {% assign otherImage = product.media[other_image_index] %}
      ${w("otherImage.media_type != 'image'","{% assign src = otherImage.preview_image.src %}","{% assign src = otherImage.src %}")}
    `)}
    ${n({srcIsLiquidCode:!0,src:w("src != null",s("src"),"https://cdn.shopify.com/s/assets/no-image-2048-5e88c1b20e087fb7bbe9a3771824e743c244f437e4f8ba93bbf7b11b53f7824c_large.gif"),id:w("featureMedia != null","{{featureMedia.id}}"),width:"{{featureMedia.width}}",height:"{{featureMedia.height}}",alt:"{{featureMedia.alt | escape}}",srcset:`${s("src")}`,baseSrc:"{{src | image_url}}",sizes:"(max-width: 768px) 50vw, 100vw",setting:{layout:j?.ftLayout,aspectRatio:O,qualityType:j?.qualityType,qualityPercent:j?.qualityPercent},priority:j?.preload,className:`gp-w-full gp-h-full gp-absolute gp-top-0 gp-left-0 featured-image-only gp-cursor-pointer !gp-rounded-none ${e??""}`,pageContext:z})}`,J=()=>i`
    ${n({srcIsLiquidCode:!0,src:"https://cdn.shopify.com/s/assets/no-image-2048-5e88c1b20e087fb7bbe9a3771824e743c244f437e4f8ba93bbf7b11b53f7824c_large.gif",alt:"No Image",sizes:"(max-width: 768px) 50vw, 100vw",setting:{layout:j?.ftLayout,aspectRatio:O,qualityType:j?.qualityType,qualityPercent:j?.qualityPercent},priority:j?.preload,className:"gp-w-full gp-h-full gp-absolute gp-top-0 gp-left-0 featured-image-only gp-cursor-pointer !gp-rounded-none",pageContext:z})}`,K=r(j.ftShape),Q=d(j),U="gp-featured-image-wrapper",X=w("product.media.size > 0",`{% assign largestRatio = 0 %}
      ${v("featureMedia in product.media",`
          ${w("featureMedia.media_type == 'video' and featureMedia.preview_image",`{% assign height = featureMedia.preview_image.height | times: 1.0 %}
            {% assign width = featureMedia.preview_image.width | times: 1.0 %}`,`{% assign height = featureMedia.height | times: 1.0 %}
            {% assign width = featureMedia.width | times: 1.0 %}`)}
          {% assign ratio = height | divided_by: width %}
          ${w("ratio > largestRatio","{% assign largestRatio = ratio %}")}
        `)}
      ${v("featureMedia in product.media",`${w("featureMedia.media_type == 'image'",`${v("image in product.images",w("image.src == featureMedia.src","{% assign imageID = image.id %}{% break %}"))}`,"{% assign imageID = '' %}")}
        
    ${b(`{% assign productImageWidth = 0 %}
    {% case featureMedia.media_type %}
      {% when 'image' %}
        {% assign productImageWidth = featureMedia.width %}
      {% else %}
        {% assign productImageWidth = featureMedia.preview_image.width %}
    {% endcase %}`)}
    ${x({id:"{{section.id}}-{{imageID}}",contentType:"productImage",className:`${P("gp-ft-image-item !gp-min-w-full !gp-max-w-full ")}`,parentId:`ft-${q}-{{section.id}}-{{product.id}}`,style:k,customStyle:{width:"{{productImageWidth}}px"},children:`
      <div
        class="gp-w-full gp-relative ${w("featureMedia == null or featureMedia.media_type == 'image'","{{ 'gp-h-0' }}","{{ 'gp-h-full !gp-pb-0' }}")} ${w("featureMedia.media_type == 'video' or featureMedia.media_type == 'external_video'",`{{ '${l}' }}`)}"
        style="${f(e("pb",K))}"
      >
        ${D()}
      </div>
      `})}`)}
    `,n({src:"https://cdn.shopify.com/s/assets/no-image-2048-5e88c1b20e087fb7bbe9a3771824e743c244f437e4f8ba93bbf7b11b53f7824c_large.gif",id:"noImageError",width:"480",height:"480",alt:"no image",priority:j?.preload,setting:{layout:j?.ftLayout,aspectRatio:O,qualityType:j?.qualityType,qualityPercent:j?.qualityPercent},style:{height:"100%"},className:"gp-w-full featured-image-only !gp-rounded-none",customLazyload:!0,pageContext:z}));return b(`
    {% capture featureImageOnlyOne %}
      ${b(`
        {% assign featureMedia = variant.featured_media %}
        {% unless featureMedia %}
        {% assign featureMedia = product.featured_media %}
        {% endunless %}
        ${w("product.media.size > 1",(()=>{switch(j?.preDisplay){case"1st-images":return`
          {% assign featureMedia = product.media.first %}
        `;case"1st-3d-mode":return v("media in product.media",w("media.media_type == 'model'","{% assign featureMedia = media %}{% break %}"));case"1st-video":return v("media in product.media",w("media.media_type == 'video' or media.media_type == 'external_video'","{% assign featureMedia = media %}{% break %}"));default:return`
          {% assign featureMedia = variant.featured_media %}
          {% unless featureMedia %}
          {% assign featureMedia = product.featured_media %}
          {% endunless %}
        `}})())}
        {% assign largestRatio = 0 %}
        {% assign height = featureMedia.height | times: 1.0 %}
        {% assign width = featureMedia.width | times: 1.0 %}
        {% assign ratio = height | divided_by: width %}
        ${w("ratio > largestRatio","{% assign largestRatio = ratio %}")}
        {% assign productImageWidth = 0 %}
        {% case featureMedia.media_type %}
          {% when 'image' %}
            {% assign productImageWidth = featureMedia.width %}
          {% else %}
            {% assign productImageWidth = featureMedia.preview_image.width %}
        {% endcase %}
        ${w("featureMedia == null","{% assign productImageWidth = 1600 %}")}
        <div
          class='gp-feature-image-carousel gp-feature-image-only'
          style="${f(W)}"
        >
          <div
            class="gp-relative"
            style="${f(N)}"
          >
            ${S}
            <div
              type="gp-feature-image-only"
              product-id="{{product.id}}"
              product-media="{{product.media.size}}"
              class="${R(U)}"
              style="${f(C)}"
            >
              <div
                class="gp-w-full gp-relative ${w("featureMedia == null or featureMedia.media_type == 'image'","{{ 'gp-h-0' }}","{{ 'gp-h-full !gp-pb-0' }}")}"
                style="${f(e("pb",K))} ${w("featureMedia.media_type == 'video' or featureMedia.media_type == 'external_video'","{{ 'display: flex; align-items: center; justify-content: center' }}")}"
              >
                ${D()}
              </div>
            </div>
          </div>
        </div>
      `)}
    {% endcapture %}
    ${w("product.media.size > 1",`
        ${_(Q,`
      ${I({builderProps:{uid:q},rootId:`ft-${q}-{{section.id}}-{{product.id}}`,conditionAppendJs:"product.media.size > 1",wrapperClass:U,rootClass:`${L}`,rootAttrs:{type:"gp-feature-image-carousel","product-id":"{{product.id}}","product-media":"{{product.media.size}}"},isHiddenArrowWhenDisabled:!0,setting:E,rootStyles:W,styles:T,style:{playSpeed:600},disableMarginAuto:!0,children:X,productBadgeLiquid:S||"",carouselType:"feature_image"})}
    `," ")}
        ${_(!Q,"{{ featureImageOnlyOne }}"," ")}
      `,"{{ featureImageOnlyOne }}")}
  `)};export{q as default};
