import{getSplitStyle as t}from"./common/styles.js";import{getGPProductButtonState as e}from"./common/helpers.js";import{template as o,isLocalEnv as s,baseAssetURL as r}from"@gem-sdk/core";import{createStateOrContext as a,Liquid as i,LiquidFor as l,If as n}from"@gem-sdk/system";import{getInsertLinkData as p,getSettingPreloadData as c}from"../../../helpers.js";import{getButtonDynamicSourceLocales as u}from"./helpers/getButtonDynamicSourceLocales.js";import{SoldOutButton as d}from"./SoldOutButton.liquid.js";import{AddToCartButton as m}from"./AddToCartButton.liquid.js";let ProductButton=f=>{let{setting:g,builderProps:b,style:y,styles:$,pageContext:v}=f,{wrapStyle:_,restStyle:h}=t(y),{outOfStockButtonLabel:S,unavailableButtonLabel:j,variantSelectionRequiredMessage:k}=u({setting:g,pageContext:v,builderProps:b}),{urlData:E}=p("",g?.actionEffect==="open-cart-drawer"?{link:"/cart",target:"_self"}:g?.customURL),q=a(e($,g)),A=()=>m({...f,style:h}),B=()=>d({...f,style:h,label:S}),P=()=>n(s,`<script ${c('class="gps-link" delay',"src")}="{{ 'gp-product-button-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${c('class="gps-link" delay',"src")}="${r}/assets-v2/gp-product-button-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`);return o`
    ${i("{%- assign total_combinations = 1 -%}")}
    ${l("option in product.options_with_values","{%- assign total_combinations = total_combinations | times: option.values.size -%}")}
    {%- liquid
      assign inventory_quantity = variant.inventory_quantity | default: 0
      assign is_in_stock = variant.available
    -%}
    <gp-product-button
      style="${_}"
      gp-data-wrapper="true"
      gp-href="${E.href}"
      class="gp-product-button"
      gp-label-out-of-stock="${S}"
      gp-label-unavailable="${j}"
      gp-data='${JSON.stringify(q).replaceAll("'","&#039;")}'
      data-variant-selection-required-message="${k}"
      gp-enable-third-partycart="{{shop.metafields.GEMPAGES.enableThirdPartyCart}}"
    >
      ${A()}
      ${B()}
    </gp-product-button>
    ${P()}
  `};export{ProductButton as default};
