"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@gem-sdk/core"),e=require("../../../grid/components/row/Row.liquid.js"),i=require("@gem-sdk/system"),r=require("../../../helpers.js"),a=require("./common/helpers.js");exports.default=d=>{let{children:o,setting:n,style:s,builderProps:c,rawChildren:l,advanced:p}=d,{isSyncProduct:u,productSetting:f}=n??{},g=f?.hasPreSelected??!1,{rowSetting:m,rowStyles:_,formatVariantId:v,formatProductId:y,productStatus:$,preSelectedOptionIds:S,productHandle:I,advancedStyle:q}=a.getData(d);return t.template`
    ${t.template`
      {%- assign gpBkProduct = product -%}
      ${i.If($==a.DYNAMIC_PRODUCT_STATUS,t.template`
      {%- liquid
        if request.page_type != 'product'
          assign product = all_products['${I}']
          assign productId = '${y}' | times: 1
          if product == empty or product == null
            paginate collections.all.products by 100000
              for item in collections.all.products
                if item.id == productId
                  assign product = item
                endif
              endfor
            endpaginate
          endif
        endif
      -%}
    `,t.template`
      {%- liquid
        if request.page_type == 'product'
          if '${$}' == '${a.STATIC_PRODUCT_STATUS}'
            if '${y}' == '${a.PRODUCT_ID_LATEST}'
              paginate collections.all.products by 100000
                assign product = collections.all.products | sort: 'created_at' | reverse | first
              endpaginate
            else
              assign product = all_products['${I}']
              assign productId = '${y}' | times: 1
              if product == empty or product == null
                paginate collections.all.products by 100000
                  for item in collections.all.products
                    if item.id == productId
                      assign product = item
                    endif
                  endfor
                endpaginate
              endif
            endif
          endif
        else
          if '${y}' == '${a.PRODUCT_ID_LATEST}'
            paginate collections.all.products by 100000
              assign product = collections.all.products | sort: 'created_at'| reverse | first
            endpaginate
          else
            assign product = all_products['${I}']
            assign productId = '${y}' | times: 1
            if product == empty or product == null
              paginate collections.all.products by 100000
                for item in collections.all.products
                  if item.id == productId
                    assign product = item
                  endif
                endfor
              endpaginate
            endif
          endif
        endif
      -%}
    `)}
    `}
    ${i.LiquidIf("product != empty and product != null",t.template`
      ${t.template`
      {%- assign initVariantId = ${v} -%}
      {%- assign product_form_id = 'product-form-' | append: "${c?.uid}" -%}
      ${v?"{%- assign variant = product.variants | where: 'id', initVariantId | first -%}":"{%- assign variant = product.selected_or_first_available_variant -%}"}
      ${v?"{%- assign productSelectedVariant = product.variants | where: 'id', initVariantId | first -%}":"{%- assign productSelectedVariant = product.selected_or_first_available_variant -%}"}
      {%-if productSelectedVariant == empty or productSelectedVariant == null -%}
        {%- assign productSelectedVariant = product.selected_or_first_available_variant -%}
      {%- endif -%}
      {%-if variant == empty or variant == null -%}
        {%- assign variant = product.selected_or_first_available_variant -%}
      {%- endif -%}
    `}
      <gp-product
        data-uid="${c?.uid}"
        data-id="${c?.uid}"
        style="${q}"
        class="${p?.cssClass}"
        gp-context='{"productId": {{ product.id }}, "preSelectedOptionIds": [${S}], "isSyncProduct": "${u}", "hasPreSelected": ${g}, "variantSelected": {{ variant | json | escape }},  "inventory_management": {{ variant.inventory_management | json | escape  }}, "inventory_policy": {{ variant.inventory_policy | json | escape }}, "inventoryQuantity": {{ variant.inventory_quantity | default: 0 }}, "quantity": 1, "formId": "{{ product_form_id }}" }'
        gp-data='{"variantSelected": {{ variant | json | escape }}, "quantity": 1, "productUrl":{{ product.url | json | escape }}, "productHandle":{{ product.handle | json | escape }}, "collectionUrl": {{ collection.url | json | escape }}, "collectionHandle": {{ collection.handle | json | escape }}}'
      >
        <product-form class="product-form">
          {%- form 'product', product, id: product_form_id, class: 'form contents', data-type: 'add-to-cart-form', autocomplete: 'off'  -%}
            <input type="hidden" name="id" value="{{ variant.id }}" />
            <input type="hidden" name="quantity" value="{{ quantity }}" />
            <button type="submit" onclick="return false;" style="display:none;"></button>
            ${e.default({builderProps:{...c,uid:c?.uid,uidInteraction:`${c?.uid}-row`},style:s,styles:_,setting:m,children:o,rawChildren:l})}
          {%- endform -%}
        </product-form>
      </gp-product>
      {%- assign product = gpBkProduct -%}
    `,t.template`
      <div class="gp-text-center">${r.getStaticLocale("Product","product_not_found")}</div>
    `)}
    ${t.RenderIf(t.isLocalEnv,`<script ${r.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${r.getSettingPreloadData('class="gps-link" delay',"src")}="${t.baseAssetURL}/assets-v2/gp-product-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
  `};
