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