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 m}from"../../common/productFeaturedImage.js";import l from"../../../../../video/components/HTML5Embed.liquid.js";import p from"../../../../../image/components/Modal3d.liquid.js";import g 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 _,Liquid as w,If as v,createStyle as $}from"@gem-sdk/system";import b 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:S,...j})=>{let{featuredImageCarouselClasses:z,galleryItemClasses:L,featuredCarouselItemClasses:P}=h({...j,builderProps:{uid:x}}),{featuredImageCarouselStyle:R,featureImageStyle:W,featureImageCarouselOnlyOneImageStyle:T,featureImageOnlyOneImageStyle:C,featureImageCarouselItemStyle:N}=f(j),{featuredImageCarouselSettingAttrs:k}=y(j),E=t(j.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=()=>p({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=$({...o({ftLayout:j?.ftLayout,ftShape:j?.ftShape}),...e("objf",j?.ftLayout)}),i=$({...o({ftLayout:j?.ftLayout,ftShape:j?.ftShape})});return l({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"})},F=()=>a`
      ${H(i("gp-w-full gp-transition-opacity",{"group-hover:gp-opacity-0":"other"==j.hoverEffect},"{{shouldHidden}}"))}
      ${v(j?.hoverEffect!=="none",`<div class="${i("zoom-element !gp-max-w-none",u())}">
            ${H("image-zoom",!0)}
          </div>`," ")}
      ${v(j?.hoverEffect=="zoom"&&j?.zoomType=="glasses",`<div class="${i("zoom-lens-element",m())}" style="opacity: 0; background-image: url('{{ featureMedia.src | img_url: "1024x1024"}}')"></div>`," ")}
    `,H=(e,i)=>a`
    {% assign src = featureMedia.src %}
    ${v(i&&"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] %}
      ${M("otherImage.media_type != 'image'","{% assign src = otherImage.preview_image.src %}","{% assign src = otherImage.src %}")}
    `)}
    ${g({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:j?.ftLayout,aspectRatio:E,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??""}`,enableLazyLoadImage:S})}`,G=()=>a`
    ${g({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:E,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",enableLazyLoadImage:S})}`,B=r(j.ftShape),J=a=>`
    ${w(`{% 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(j),Q="gp-featured-image-wrapper",U=M("product.media.size > 0",`{% assign largestRatio = 0 %}
      ${_("featureMedia in product.media",`
          ${M("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 %}
          ${M("ratio > largestRatio","{% assign largestRatio = ratio %}")}
        `)}
      ${_("featureMedia in product.media",`${M("featureMedia.media_type == 'image'",`${_("image in product.images",M("image.src == featureMedia.src","{% assign imageID = image.id %}{% break %}"))}`,"{% assign imageID = '' %}")}
        ${J()}`)}
    `,g({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:E,qualityType:j?.qualityType,qualityPercent:j?.qualityPercent},style:{height:"100%"},className:"gp-w-full featured-image-only !gp-rounded-none",customLazyload:!0,enableLazyLoadImage:S})),X=()=>`
      ${b({builderProps:{uid:x},rootId:`ft-${x}-{{section.id}}-{{product.id}}`,conditionAppendJs:"product.media.size > 1",wrapperClass:Q,rootClass:`${z}`,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(j?.preDisplay){case"1st-images":return`
          {% assign featureMedia = product.media.first %}
        `;case"1st-3d-mode":return _("media in product.media",M("media.media_type == 'model'","{% assign featureMedia = media %}{% break %}"));case"1st-video":return _("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=()=>w(`
        {% 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(C)}"
          >
            ${q}
            <div
              type="gp-feature-image-only"
              product-id="{{product.id}}"
              product-media="{{product.media.size}}"
              class="${P(Q)}"
              style="${c(T)}"
            >
              <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 w(`
    {% capture featureImageOnlyOne %}
      ${Z()}
    {% endcapture %}
    ${M("product.media.size > 1",`
        ${v(K,X()," ")}
        ${v(!K,"{{ featureImageOnlyOne }}"," ")}
      `,"{{ featureImageOnlyOne }}")}
  `)};export{FeatureImageWithGallery as default};
