(function(){"use strict";function formatCents(cents,format){if(!Number.isSafeInteger(cents)||!format||!/\{\{\s*amount/.test(format))return null;var whole=Math.floor(cents/100),fraction=String(cents%100).padStart(2,"0"),groups=String(whole).replace(/\B(?=(\d{3})+(?!\d))/g,","),commaGroups=groups.replace(/,/g,"."),rounded=String(whole+(cents%100>=50?1:0)).replace(/\B(?=(\d{3})+(?!\d))/g,","),replacements={amount:groups+"."+fraction,amount_with_comma_separator:commaGroups+","+fraction,amount_with_apostrophe_separator:groups.replace(/,/g,"'")+"."+fraction,amount_no_decimals:rounded,amount_no_decimals_with_comma_separator:rounded.replace(/,/g,"."),amount_no_decimals_with_apostrophe_separator:rounded.replace(/,/g,"'")},found=!1,text=format.replace(/\{\{\s*(\w+)\s*\}\}/g,function(_,name){return Object.prototype.hasOwnProperty.call(replacements,name)?(found=!0,replacements[name]):_});return found&&!/\{\{/.test(text)?text:null}function priceHost(root){return root.matches("product-card")?root:root.querySelector("product-price[data-variant-id]")}function priceContainer(host){return host&&(host.querySelector("[data-price-container]")||host.querySelector('[ref="priceContainer"]'))}function originalPrice(container){return container&&container.querySelector("[data-original-price], .product-card-simple__price-sale:not([data-auto-discount-price]), .price:not([data-auto-discount-price])")}function restore(root,host,container){var hadDiscount=root.hasAttribute("data-pf-price-applied");root.removeAttribute("data-pf-price-applied");var badge=root.querySelector("[data-pf-native-sale]");if(badge&&(badge.hidden=!1),!container)return hadDiscount&&window.CustomPriceModule&&(root.matches("product-card")?window.CustomPriceModule.recalculateForCard(root):host&&window.CustomPriceModule.recalculateForPDPHost(host,Number(host.getAttribute("data-product-price")))),!1;var original=originalPrice(container),auto=container.querySelector("[data-auto-discount-price]");original&&original.classList.remove("price--compare-auto"),auto&&(auto.hidden=!0,auto.textContent="");var compare=container.querySelector(".compare-at-price, .product-card-simple__price-compare");return compare&&compare.classList.remove("price--compare-hidden"),hadDiscount&&window.CustomPriceModule&&(root.matches("product-card")?window.CustomPriceModule.recalculateForCard(root):window.CustomPriceModule.recalculateForPDPHost(host)),!0}function update(root){if(!root||!root.isConnected)return;var host=priceHost(root),container=priceContainer(host),original=originalPrice(container),auto=container&&container.querySelector("[data-auto-discount-price]"),cents=Number(host&&host.getAttribute("data-product-price")),variantId=host&&host.getAttribute("data-variant-id"),format=root.getAttribute("data-pf-currency-format")==="with_currency"?window.__moneyWithCurrencyFormat:window.__moneyFormat,commons=window.CommonsFlagsPricing;function apply(result){if(restore(root,host,container),!result)return!0;if(!root.isConnected||!original||!auto||!container||!Number.isSafeInteger(cents)||cents<=0||Number(container.getAttribute("data-pf-base-cents"))!==cents||container.getAttribute("data-pf-base-variant-id")!==variantId)return!1;var formatted=formatCents(result.finalCents,format);if(formatted===null||result.originalCents!==cents||result.variantId!==variantId)return!1;original.classList.add("price--compare-auto"),auto.textContent=formatted,auto.hidden=!1;var compare=container.querySelector(".compare-at-price, .product-card-simple__price-compare");compare&&compare.classList.add("price--compare-hidden");var badge=root.querySelector("[data-pf-native-sale]");if(badge&&(badge.hidden=!0),root.matches("product-card"))document.dispatchEvent(new CustomEvent("custom-price:sync",{detail:{card:root,effectivePrice:result.finalCents}}));else{var custom=host.querySelector(".custom-price");try{var config=JSON.parse(custom&&custom.getAttribute("data-custom-price-config"));config&&config.accumulates===!0&&document.dispatchEvent(new CustomEvent("custom-price:sync-pdp",{detail:{host:host,effectivePrice:result.finalCents}}))}catch(_){}}return root.setAttribute("data-pf-price-applied",""),!0}if(!commons||commons.version!==1||typeof commons.evaluate!="function"){apply(null);return}commons.evaluate(root,{coverage:root.getAttribute("data-pf-coverage")==="true",priceCents:cents,variantId:variantId},apply)}function roots(node){if(!(!node||node.nodeType!==1)){var owner=node.closest("[data-pf-root]");owner&&update(owner),node.matches("[data-pf-root]")&&update(node),node.querySelectorAll("[data-pf-root]").forEach(update)}}function init(){roots(document.body),document.addEventListener("commons-flags-pricing:ready",function(){roots(document.body)}),document.addEventListener("shopify:product:select",function(event){if(!(!event.promise||!event.target||!event.target.closest)){var target=event.target;event.promise.then(function(result){var detail=result&&result.detail;if(!(!detail||!detail.resource)){var card=target.closest("product-card[data-pf-root]"),root=card||target.closest(".pdp-main-container[data-pf-root]");if(root){var host=priceHost(root);if(host){var commons=window.CommonsFlagsPricing;commons&&commons.version===1&&commons.evaluate(root,{coverage:!1,priceCents:0},function(){return restore(root,host,priceContainer(host))}),detail.resource.id!=null&&host.setAttribute("data-variant-id",String(detail.resource.id)),detail.resource.price!=null&&host.setAttribute("data-product-price",String(detail.resource.price)),host.setAttribute("data-compare-at-price",String(detail.resource.compare_at_price||0)),requestAnimationFrame(function(){update(root)})}}}},function(){})}},!0),document.addEventListener("plp:variant-changed",function(event){var card=event.detail&&event.detail.card;if(!(!card||event.target!==card||!card.matches("product-card")||!card.hasAttribute("data-pf-root"))){var commons=window.CommonsFlagsPricing;commons&&commons.version===1&&commons.evaluate(card,{coverage:!1,priceCents:0},function(){return restore(card,card,priceContainer(card))}),requestAnimationFrame(function(){update(card)})}});var observer=new MutationObserver(function(mutations){var affected=new Set;mutations.forEach(function(mutation){mutation.addedNodes.forEach(roots),mutation.removedNodes.forEach(function(node){if(node.nodeType===1){var relevant=node.matches('[data-pf-p], product-price, [ref="priceContainer"], [data-price-container]')||node.querySelector('[data-pf-p], product-price, [ref="priceContainer"], [data-price-container]');if(relevant){var target=mutation.target.nodeType===1?mutation.target:mutation.target.parentElement,owner=target&&target.closest("[data-pf-root]");owner&&owner.isConnected&&affected.add(owner)}}})}),affected.forEach(update)});observer.observe(document.body,{childList:!0,subtree:!0})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init,{once:!0}):init()})(); //# sourceMappingURL=/cdn/shop/t/35/assets/gco-automatic-discounts.js.map?v=110460901697593685311793372365