"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),helpers$1=require("../../../helpers.js"),system=require("@gem-sdk/system"),ProductListCarouselLayout_liquid=require("./ProductListCarouselLayout.liquid.js"),ProductListGridLayout_liquid=require("./ProductListGridLayout.liquid.js"),styles=require("./common/styles.js"),classes=require("./common/classes.js"),helpers=require("./common/helpers.js");const ProductList=e=>{let{setting:s,styles:t,pageContext:i}=e,r=i?.pageType==="GP_FUNNEL_PAGE";if(r)return"";let{hasRelatedExclude:d,relatedExcludeTrim:a,collectionID:o,isLatestProducts:c,isGrid:l,numberOfProducts:n,productListId:u,productListHandles:g,sortedBy:p,isReverse:f,productSrc:m,productNumber:P,isSorted:$,relatedTag:h,collectionHandle:y}=helpers.getDataLiquid(e),_=()=>core.template`
    ${core.RenderIf("RelatedProduct"===m,`
        assign relatedTag = '${h}'
        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 = ${d}
            if hasRelatedExclude
              assign relatedExclude = '${a}'
            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 = ${d}
            if hasRelatedExclude
              assign relatedExclude = '${a}'
            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 ${n||4}
          assign products = products
        endpaginate
      `)}
  `,L=()=>{let e=y?`
          assign target_collection = collections['${y}']
          if target_collection == empty
            for collection in collections
              if collection.id == ${o}
                assign target_collection = collection
                break
              endif
            endfor
          endif
        `:`
          for collection in collections
            if collection.id == ${o}
              assign target_collection = collection
              break
            endif
          endfor
        `;return core.template`
      {%- liquid
        assign productHandles = '${g.toString()}'| split: ','
        assign products = null
        assign target_collection = null
        assign productSrc = '${m}'
        assign c = 0
        assign limit = ${P??4}

        if request.page_type == 'collection' or preview_page_type == 'collection'
          assign target_collection = collection
          if target_collection == empty or target_collection == null
            if '${o.toLowerCase()}' == 'latest'
              assign target_collection = collections | sort: 'updated_at' ${f?"| reverse":""} | first
            else
              ${e}
            endif
          endif
          paginate target_collection.products by ${n||4}
            assign products = target_collection.products ${$?p:""} ${f?"| reverse":""}
          endpaginate
        else
          if productSrc == 'RelatedProduct'
            ${_()}
          elsif productSrc == 'PickProduct'
            unless ${c}
              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 ${u.length} == 0
                paginate collections.all.products by 100000
                  assign products = collections.all.products  | sort : "created_at"  | reverse
                endpaginate
              endif
            endunless
          else
            if '${o.toLowerCase()}' == 'latest'
              assign target_collection = collections | sort: 'updated_at' ${f?"| reverse":""} | first
            else
              ${e}
            endif
            paginate target_collection.products by ${n||4}
              assign products = target_collection.products ${$?p:""} ${f?"| reverse":""}
            endpaginate
          endif
        endif
      -%}
    `},{productListWrapStyle:v,productListContentStyle:E,productListWrapAlignStyle:S}=styles.getStyle(e),{productListWrapClass:k}=classes.getClass(e),b=()=>core.template`
    {%- if products == null -%}
    {%- if count == 0 and ${u.length} == 0 -%}
      {% if '${m}' == 'RelatedProduct' -%}
          <div>${helpers$1.getStaticLocale("ProductList","no_related_products")}</div>
        {% else %}
          <div>${helpers$1.getStaticLocale("ProductList","no_products_found")}</div>
      {%- endif -%}
    {%- endif -%}
    {%-else-%}
      ${system.If(l,core.template`${ProductListGridLayout_liquid.default({...e,productListId:u,productSrc:m})}`,core.template`${ProductListCarouselLayout_liquid.default({...e,productListId:u,productSrc:m})}`)}
    {%- endif -%}
    `;return core.template`
    ${core.RenderIf(core.isLocalEnv,`
        <script ${helpers$1.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-v7-5.js' | asset_url }}" defer="defer"></script>
        ${s?.sameHeight?`<script ${helpers$1.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-same-height-v7-5.js' | asset_url }}" defer="defer"></script>`:""}
        `,`
        <script ${helpers$1.getSettingPreloadData('class="gps-link" delay',"src")}="${core.baseAssetURL}/assets-v2/gp-product-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>
        ${s?.sameHeight?`<script ${helpers$1.getSettingPreloadData('class="gps-link" delay',"src")}="${core.baseAssetURL}/assets-v2/gp-same-height-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`:""}
        `)}

    ${core.RenderIf(!!t?.preloadBgImage,`${core.RenderIf(!!t?.backgroundImage?.desktop?.image?.src,`<link rel="preload" href="${t?.backgroundImage?.desktop?.image?.src}" as="image" />`)}${core.RenderIf(!!t?.backgroundImage?.tablet?.image?.src,`<link rel="preload" href="${t?.backgroundImage?.tablet?.image?.src}" as="image" />`)}${core.RenderIf(!!t?.backgroundImage?.mobile?.image?.src,`<link rel="preload" href="${t?.backgroundImage?.mobile?.image?.src}" as="image" />`)}`)}
    <div
      class="${k}"
      style="${v}"
    >
      <div class='gp-flex gp-w-full' style="${S}">
        <div
          style="${E}"
        >
          {%- assign gpBkProduct = product -%}
          {%- assign gpBkProducts = products -%}
          ${L()}
          ${b()}
          {%- assign product = gpBkProduct -%}
          {%- assign products = gpBkProducts -%}
        </div>
      </div>
    </div>
  `};exports.default=ProductList;
