"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gem-sdk/core"),t=require("../../../helpers.js"),s=require("@gem-sdk/system"),i=require("./ProductListCarouselLayout.liquid.js"),d=require("./ProductListGridLayout.liquid.js"),a=require("./common/styles.js"),r=require("./common/classes.js"),n=require("./common/helpers.js");exports.default=o=>{let{setting:l,styles:c,pageContext:g}=o,u=g?.pageType==="GP_FUNNEL_PAGE";if(u)return"";let{hasRelatedExclude:p,relatedExcludeTrim:f,collectionID:m,isLatestProducts:P,isGrid:$,numberOfProducts:h,productListId:_,productListHandles:y,sortedBy:v,isReverse:E,productSrc:S,productNumber:k,isSorted:L,relatedTag:b,collectionHandle:x}=n.getDataLiquid(o),R=()=>e.template`
    ${e.RenderIf("RelatedProduct"===S,`
        assign relatedTag = '${b}'
        assign assignProduct = product
        assign idAssignProduct = assignProduct.id
        paginate collections.all.products by 10000
          assign allProductsPaginated = collections.all.products
        endpaginate
        assign handleAssignProduct = assignProduct.handle
        case relatedTag
          when 'collection'
            assign hasRelatedExclude = ${p}
            if hasRelatedExclude
              assign relatedExclude = '${f}'
            else
              assign relatedExclude = ''
            endif
            assign arrayRelatedExclude = relatedExclude | split: ","
            assign idSelectedList = ''
            assign relatedListProduct = null
            for collection in collections
            assign collectionId = collection.id
            assign isInCollection = false
            assign collectionsAssignProduct = assignProduct.collections
              for item in collectionsAssignProduct
                unless arrayRelatedExclude contains item.handle
                  if item.id == collectionId
                  for product in collection.products
                    assign product_ids_array = idSelectedList | split: ","
                    if product_ids_array contains product.id or product.id == idAssignProduct
                    elsif product_ids_array.size > limit
                     break
                    else
                      assign idSelectedList = idSelectedList | append: "," | append: product.id
                      assign productSelected = product | sort
                      assign relatedListProduct = relatedListProduct | concat: productSelected
                    endif
                  endfor
                  endif
                endunless
              endfor
            endfor
            assign products = relatedListProduct | uniq
          when 'vendor'
            assign vendorAssignProduct = assignProduct.vendor
            assign productFilter = allProductsPaginated | where: 'vendor', vendorAssignProduct
            for item in productFilter
              assign itemHandle = item.handle
              assign productF = item | sort
              if itemHandle != handleAssignProduct
                assign products = products | concat: productF
              endif
            endfor
          when 'production-type'
            assign typeAssignProduct = assignProduct.type
            assign productFilter = allProductsPaginated | where: 'type', typeAssignProduct
            for item in productFilter
              assign itemHandle = item.handle
              assign productF = item | sort
              if itemHandle != handleAssignProduct
                assign products = products | concat: productF
              endif
            endfor
          when 'tags'
            assign tagsAssignProduct = assignProduct.tags
            assign hasRelatedExclude = ${p}
            if hasRelatedExclude
              assign relatedExclude = '${f}'
            else
              assign relatedExclude = ''
            endif
            assign arrayRelatedExclude = relatedExclude | split: ","
              for item in allProductsPaginated
                unless unique_products contains item.handle
                  assign isExcludedProduct = false
                  for tagExclude in arrayRelatedExclude
                    if item.tags contains tagExclude
                      assign isExcludedProduct = true
                    endif
                  endfor
                  unless isExcludedProduct
                    for tag in tagsAssignProduct
                      if item.tags contains tag and assignProduct.handle != item.handle
                        assign productF = item | sort
                        assign products = products | concat: productF
                      break
                        endif
                      endfor
                  endunless
                endunless
              endfor
            assign products = products | uniq
        endcase
        paginate products by ${h||4}
          assign products = products
        endpaginate
      `)}
  `,{productListWrapStyle:A,productListContentStyle:I,productListWrapAlignStyle:q}=a.getStyle(o),{productListWrapClass:H}=r.getClass(o);return e.template`
    ${e.RenderIf(e.isLocalEnv,`
        <script ${t.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-v7-5.js' | asset_url }}" defer="defer"></script>
        ${l?.sameHeight?`<script ${t.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-same-height-v7-5.js' | asset_url }}" defer="defer"></script>`:""}
        `,`
        <script ${t.getSettingPreloadData('class="gps-link" delay',"src")}="${e.baseAssetURL}/assets-v2/gp-product-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>
        ${l?.sameHeight?`<script ${t.getSettingPreloadData('class="gps-link" delay',"src")}="${e.baseAssetURL}/assets-v2/gp-same-height-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`:""}
        `)}

    ${e.RenderIf(!!c?.preloadBgImage,`${e.RenderIf(!!c?.backgroundImage?.desktop?.image?.src,`<link rel="preload" href="${c?.backgroundImage?.desktop?.image?.src}" as="image" />`)}${e.RenderIf(!!c?.backgroundImage?.tablet?.image?.src,`<link rel="preload" href="${c?.backgroundImage?.tablet?.image?.src}" as="image" />`)}${e.RenderIf(!!c?.backgroundImage?.mobile?.image?.src,`<link rel="preload" href="${c?.backgroundImage?.mobile?.image?.src}" as="image" />`)}`)}
    <div
      class="${H}"
      style="${A}"
    >
      <div class='gp-flex gp-w-full' style="${q}">
        <div
          style="${I}"
        >
          {%- assign gpBkProduct = product -%}
          {%- assign gpBkProducts = products -%}
          ${(()=>{let t=x?`
          assign target_collection = collections['${x}']
          if target_collection == empty
            for collection in collections
              if collection.id == ${m}
                assign target_collection = collection
                break
              endif
            endfor
          endif
        `:`
          for collection in collections
            if collection.id == ${m}
              assign target_collection = collection
              break
            endif
          endfor
        `;return e.template`
      {%- liquid
        assign productHandles = '${y.toString()}'| split: ','
        assign products = null
        assign target_collection = null
        assign productSrc = '${S}'
        assign c = 0
        assign limit = ${k??4}
        assign isSettingSameHeightProductList = ${l?.sameHeight??!1}

        if request.page_type == 'collection' or preview_page_type == 'collection'
          assign target_collection = collection
          if target_collection == empty or target_collection == null
            if '${m.toLowerCase()}' == 'latest'
              assign target_collection = collections | sort: 'updated_at' ${E?"| reverse":""} | first
            else
              ${t}
            endif
          endif
          paginate target_collection.products by ${h||4}
            assign products = target_collection.products ${L?v:""} ${E?"| reverse":""}
          endpaginate
        else
          if productSrc == 'RelatedProduct'
            ${R()}
          elsif productSrc == 'PickProduct'
            unless ${P}
              assign products = null | sort
              for handle in productHandles
                assign productH = all_products[handle] | sort
                assign products = products | concat: productH
              endfor
              assign limit = products.length
            else
              if ${_.length} == 0
                paginate collections.all.products by 100000
                  assign products = collections.all.products  | sort : "created_at"  | reverse
                endpaginate
              endif
            endunless
          else
            if '${m.toLowerCase()}' == 'latest'
              assign target_collection = collections | sort: 'updated_at' ${E?"| reverse":""} | first
            else
              ${t}
            endif
            paginate target_collection.products by ${h||4}
              assign products = target_collection.products ${L?v:""} ${E?"| reverse":""}
            endpaginate
          endif
        endif
      -%}
    `})()}
          ${e.template`
    {%- if products == null -%}
    {%- if count == 0 and ${_.length} == 0 -%}
      {% if '${S}' == 'RelatedProduct' -%}
          <div>${t.getStaticLocale("ProductList","no_related_products")}</div>
        {% else %}
          <div>${t.getStaticLocale("ProductList","no_products_found")}</div>
      {%- endif -%}
    {%- endif -%}
    {%-else-%}
      ${s.If($,e.template`${d.default({...o,productListId:_,productSrc:S})}`,e.template`${i.default({...o,productListId:_,productSrc:S})}`)}
    {%- endif -%}
    `}
          {%- assign product = gpBkProduct -%}
          {%- assign products = gpBkProducts -%}
        </div>
      </div>
    </div>
  `};
