(function(){"use strict";function getMoneyFormat(){if(window.__moneyFormat)return window.__moneyFormat;var storefrontConfig=window.__storefrontApi;return storefrontConfig&&storefrontConfig.moneyFormat?storefrontConfig.moneyFormat:"${{amount}}"}function formatMoneyFromCents(amountInCents,moneyFormat){var amount=amountInCents/100,formatted=amount.toFixed(2),parts=formatted.split("."),dollars=parts[0],cents=parts[1],withComma=dollars.replace(/\B(?=(\d{3})+(?!\d))/g,".")+","+cents,withDot=dollars.replace(/\B(?=(\d{3})+(?!\d))/g,",")+"."+cents,rounded=Math.round(amount).toString(),roundedWithComma=rounded.replace(/\B(?=(\d{3})+(?!\d))/g,"."),roundedWithDot=rounded.replace(/\B(?=(\d{3})+(?!\d))/g,","),roundedWithApostrophe=rounded.replace(/\B(?=(\d{3})+(?!\d))/g,"'"),withApostrophe=dollars.replace(/\B(?=(\d{3})+(?!\d))/g,"'")+"."+cents;return moneyFormat.replace("{{amount_with_apostrophe_separator}}",withApostrophe).replace("{{amount_with_comma_separator}}",withComma).replace("{{amount_no_decimals_with_comma_separator}}",roundedWithComma).replace("{{amount_no_decimals_with_apostrophe_separator}}",roundedWithApostrophe).replace("{{amount_no_decimals}}",roundedWithDot).replace("{{ amount }}",withDot).replace("{{ amount_with_comma_separator }}",withComma).replace("{{amount}}",withDot)}function parseConfig(customPriceEl){if(!customPriceEl)return null;var configStr=customPriceEl.getAttribute("data-custom-price-config");if(!configStr)return null;try{return JSON.parse(configStr)}catch(e){return null}}function getCardPrice(card,attributeName){return parseInt(card.getAttribute(attributeName)||"0",10)||0}function syncCardVariantData(card,variantId,productPrice,compareAtPrice){if(card){variantId!=null&&card.setAttribute("data-variant-id",String(variantId)),productPrice!=null&&card.setAttribute("data-product-price",String(productPrice)),card.setAttribute("data-compare-at-price",String(compareAtPrice||0));var customPriceEl=card.querySelector(".custom-price");customPriceEl&&variantId!=null&&customPriceEl.setAttribute("data-custom-price-variant",String(variantId))}}function replaceCustomPriceMarkup(productPriceEl,htmlDocument){if(!(!productPriceEl||!htmlDocument)){var currentCustomPrice=productPriceEl.querySelector(".custom-price"),nextCustomPrice=htmlDocument.querySelector("product-price .custom-price");if(currentCustomPrice&&!nextCustomPrice){currentCustomPrice.remove();return}if(nextCustomPrice){if(currentCustomPrice){currentCustomPrice.replaceWith(nextCustomPrice);return}var currentPriceContainer=productPriceEl.querySelector('[ref="priceContainer"]');currentPriceContainer?currentPriceContainer.insertAdjacentElement("afterend",nextCustomPrice):productPriceEl.appendChild(nextCustomPrice)}}}function getEffectiveBasePrice(card,customPriceEl,config,overrideBasePriceInCents){if(typeof overrideBasePriceInCents=="number"&&!isNaN(overrideBasePriceInCents))return overrideBasePriceInCents;var productPrice=getCardPrice(card,"data-product-price"),compareAtPrice=getCardPrice(card,"data-compare-at-price");return config.accumulates===!0?productPrice:compareAtPrice>productPrice?compareAtPrice:productPrice}function paintCustomPrice(customPriceEl,basePrice,config){var percentage=parseFloat(config.percentage)||0;percentage=Math.max(0,Math.min(99,percentage));var finalPrice=Math.round(basePrice*(1-percentage/100)),priceValueEl=customPriceEl.querySelector(".custom-price__value");priceValueEl&&(priceValueEl.textContent=formatMoneyFromCents(finalPrice,getMoneyFormat())),customPriceEl.setAttribute("data-custom-price-base",String(basePrice))}function recalculateForCard(card,overrideBasePriceInCents){if(card){var customPriceEl=card.querySelector(".custom-price"),config=parseConfig(customPriceEl);if(!(!customPriceEl||!config)){var basePrice=getEffectiveBasePrice(card,customPriceEl,config,overrideBasePriceInCents);basePrice&&paintCustomPrice(customPriceEl,basePrice,config)}}}function recalculateForPDPHost(host,overrideBasePriceInCents){if(host){var customPriceEl=host.querySelector(".custom-price"),config=parseConfig(customPriceEl);if(!(!customPriceEl||!config)){var galleryContainer=document.querySelector(".gallery-main-container[data-variant-id]"),variantId=galleryContainer?galleryContainer.getAttribute("data-variant-id"):null;if(variantId){var basePrice;if(typeof overrideBasePriceInCents=="number"&&!isNaN(overrideBasePriceInCents))basePrice=overrideBasePriceInCents;else{var priceContainer=host.querySelector('[ref="priceContainer"]');if(!priceContainer)return;var priceEl=priceContainer.querySelector(".price");if(!priceEl)return;var priceText=priceEl.textContent||"";basePrice=parsePriceTextToCents(priceText)}basePrice&&(paintCustomPrice(customPriceEl,basePrice,config),customPriceEl.setAttribute("data-custom-price-variant",variantId))}}}}function parsePriceTextToCents(priceText){if(!priceText)return 0;var cleaned=priceText.replace(/[^\d.,]/g,""),parts=cleaned.split(/[.,]/),cents=0;if(parts.length===1)cents=parseInt(parts[0],10)*100;else if(parts.length===2){var lastPart=parts[1];lastPart.length===2?cents=parseInt(parts[0].replace(/[,]/g,""),10)*100+parseInt(lastPart,10):lastPart.length===3?cents=parseInt(parts[0]+lastPart,10)*100:cents=parseInt(parts[0].replace(/[,]/g,""),10)*100}else if(parts.length>=3){var mainPart=parts.slice(0,-1).join("").replace(/[,]/g,""),decimalPart=parts[parts.length-1];decimalPart.length===2?cents=parseInt(mainPart,10)*100+parseInt(decimalPart,10):cents=parseInt(mainPart+decimalPart,10)*100}return cents||0}function handleDiscountSync(event){var detail=event.detail;!detail||!detail.card||typeof detail.effectivePrice!="number"||recalculateForCard(detail.card,detail.effectivePrice)}function handlePDPSync(event){var detail=event.detail;!detail||!detail.host||typeof detail.effectivePrice!="number"||recalculateForPDPHost(detail.host,detail.effectivePrice)}function handlePLPVariantChange(event){var detail=event.detail;!detail||!detail.card||(syncCardVariantData(detail.card,detail.variantId,detail.price,detail.compareAtPrice),recalculateForCard(detail.card))}function handleThemeVariantUpdate(event){var detail=event.detail,target=event.target,card=target&&target.closest?target.closest("product-card"):null;if(detail&&detail.resource&&card){syncCardVariantData(card,detail.resource.id,detail.resource.price,detail.resource.compare_at_price);var cardProductPriceEl=card.querySelector("product-price");cardProductPriceEl&&replaceCustomPriceMarkup(cardProductPriceEl,detail.html),recalculateForCard(card);return}var productPrice=target&&target.closest?target.closest("product-price"):null;detail&&detail.resource&&productPrice&&(replaceCustomPriceMarkup(productPrice,detail.html),recalculateForPDPHost(productPrice))}function syncAllCustomPrices(){for(var customPriceNodes=document.querySelectorAll(".custom-price"),i=0;i