{
  "version": 3,
  "sources": ["/cdn/shop/t/124/assets/bfcm-cart-gift.js?nocache=1794840960883"],
  "sourcesContent": ["/**\n * Adds the BFCM free gift to an add-to-cart request that qualifies for it, so the gift\n * reaches the cart in the same request as its pack instead of the cart adding it after.\n * The rules come from the campaign JSON that snippets/bfcm-cart-gift.liquid prints for\n * the hybrid cart; the cart still checks them and stays the safety net for every other\n * way into the cart.\n *\n * The gift goes first: Shopify lists each added item above the previous one, so the pack\n * ends up on top and the gift below it, in the cart and at checkout.\n */\n(() => {\n  const readCampaign = () => {\n    try {\n      return JSON.parse(\n        document.getElementById(\"ns-hybrid-cart-gwp-campaign\")?.textContent ||\n          \"null\",\n      );\n    } catch (error) {\n      return null;\n    }\n  };\n\n  // Leading number of a pack label, e.g. 30 for \"30 bottles\", as the cart reads it.\n  const packSize = (label) => {\n    const match = /^\\s*(\\d+)\\b/.exec(String(label ?? \"\"));\n    return match ? Number(match[1]) : null;\n  };\n\n  /**\n   * @param {Array<{id: number, quantity: number, selling_plan?: number}>} items - The request's items, pack first\n   * @param {string} packLabel - The chosen pack option, e.g. \"30 bottles\"\n   * @returns {Array} The items, with the gift in front when the pack qualifies\n   */\n  window.bfcmWithGift = (items, packLabel) => {\n    const campaign = readCampaign();\n    const pack = items[0];\n    const giftId = campaign?.gift_variant_id;\n    if (!pack || typeof giftId !== \"number\") return items;\n    // Rules the cart can only judge itself are left to it.\n    if (campaign.new_subscribers_only || campaign.exclude_tag) return items;\n    if (\n      campaign.us_only &&\n      String(window.Shopify?.country || \"US\").toUpperCase() !== \"US\"\n    )\n      return items;\n    if (campaign.only_if_subscription && !pack.selling_plan) return items;\n    if (\n      campaign.pack_sizes?.length &&\n      !campaign.pack_sizes.includes(packSize(packLabel))\n    )\n      return items;\n    if (items.some((item) => item.id === giftId)) return items;\n\n    return [\n      { id: giftId, quantity: 1, properties: { _NSHC_GWP: true } },\n      ...items,\n    ];\n  };\n})();\n"],
  "mappings": "CAUC,IAAM,CACL,MAAM,aAAe,IAAM,CACzB,GAAI,CACF,OAAO,KAAK,MACV,SAAS,eAAe,6BAA6B,GAAG,aACtD,MACJ,CACF,MAAgB,CACd,OAAO,IACT,CACF,EAGM,SAAY,OAAU,CAC1B,MAAM,MAAQ,cAAc,KAAK,OAAO,OAAS,EAAE,CAAC,EACpD,OAAO,MAAQ,OAAO,MAAM,CAAC,CAAC,EAAI,IACpC,EAOA,OAAO,aAAe,CAAC,MAAO,YAAc,CAC1C,MAAM,SAAW,aAAa,EACxB,KAAO,MAAM,CAAC,EACd,OAAS,UAAU,gBAezB,MAdI,CAAC,MAAQ,OAAO,QAAW,UAE3B,SAAS,sBAAwB,SAAS,aAE5C,SAAS,SACT,OAAO,OAAO,SAAS,SAAW,IAAI,EAAE,YAAY,IAAM,MAGxD,SAAS,sBAAwB,CAAC,KAAK,cAEzC,SAAS,YAAY,QACrB,CAAC,SAAS,WAAW,SAAS,SAAS,SAAS,CAAC,GAG/C,MAAM,KAAM,MAAS,KAAK,KAAO,MAAM,EAAU,MAE9C,CACL,CAAE,GAAI,OAAQ,SAAU,EAAG,WAAY,CAAE,UAAW,EAAK,CAAE,EAC3D,GAAG,KACL,CACF,CACF,GAAG",
  "names": []
}
