"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),Row_liquid=require("../../../grid/components/row/Row.liquid.js"),system=require("@gem-sdk/system"),helpers$1=require("../../../helpers.js"),helpers=require("./common/helpers.js");const Product=e=>{let{children:t,setting:r,style:i,builderProps:a,rawChildren:o,advanced:d}=e,{isSyncProduct:s}=r??{},{rowSetting:n,rowStyles:c,formatVariantId:l,formatProductId:p,productStatus:u,preSelectedOptionIds:f,productHandle:g,advancedStyle:m}=helpers.getData(e),_=()=>core.template`
      {%- liquid
        if request.page_type == 'product'
          if '${u}' == '${helpers.STATIC_PRODUCT_STATUS}'
            if '${p}' == '${helpers.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['${g}']
              assign productId = '${p}' | 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 '${p}' == '${helpers.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['${g}']
            assign productId = '${p}' | 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
      -%}
    `,y=()=>core.template`
      {%- liquid
        if request.page_type != 'product'
          assign product = all_products['${g}']
          assign productId = '${p}' | 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
      -%}
    `,v=()=>core.template`
      {%- assign gpBkProduct = product -%}
      ${system.If(u==helpers.DYNAMIC_PRODUCT_STATUS,y(),_())}
    `,$=()=>core.template`
      {%- assign initVariantId = ${l} -%}
      {%- assign product_form_id = 'product-form-' | append: "${a?.uid}" -%}
      ${l?"{%- assign variant = product.variants | where: 'id', initVariantId | first -%}":"{%- assign variant = product.selected_or_first_available_variant -%}"}
      ${l?"{%- 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 -%}
    `,S=()=>core.template`
      <div class="gp-text-center">${helpers$1.getStaticLocale("Product","product_not_found")}</div>
    `,I=()=>core.template`
      ${$()}
      <gp-product
        data-uid="${a?.uid}"
        data-id="${a?.uid}"
        style="${m}"
        class="${d?.cssClass}"
        gp-context='{"productId": {{ product.id }}, "preSelectedOptionIds": [${f}], "isSyncProduct": "${s}", "variantSelected": {{ variant | json | escape }},  "inventory_management": {{ variant.inventory_management | json | escape  }}, "inventory_policy": {{ variant.inventory_policy | json | escape }}, "inventoryQuantity": {{ variant.inventory_quantity }}, "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>
            ${Row_liquid.default({builderProps:{...a,uid:a?.uid,uidInteraction:`${a?.uid}-row`},style:i,styles:c,setting:n,children:t,rawChildren:o})}
          {%- endform -%}
        </product-form>
      </gp-product>
      {%- assign product = gpBkProduct -%}
    `;return core.template`
    ${v()}
    ${system.LiquidIf("product != empty and product != null",I(),S())}
    ${core.RenderIf(core.isLocalEnv,`<script ${helpers$1.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-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>`)}
  `};exports.default=Product;
