{ "version": 3, "sources": ["/cdn/shop/t/3/assets/product.js"], "sourcesContent": ["const formContainer = document.querySelector(\".product-form[data-product]\");\nconst productData = JSON.parse(formContainer.dataset.product);\nconst productForm = document.querySelector(\"form[data-type=\\\"add-to-cart-form\\\"]\");\n\nfunction updateDiscounts() {\n const selectedVariant = findSelectedVariant();\n const sellingPlanId = document.querySelector('input[name=\"selling_plan\"]:checked').value;\n const availableSellingPlanAllocations = selectedVariant.selling_plan_allocations;\n let price = selectedVariant.price;\n let qty = 1;\n if(availableSellingPlanAllocations && availableSellingPlanAllocations.length > 0 && sellingPlanId) {\n const selectedPlan = availableSellingPlanAllocations.find(plan => plan.selling_plan_id === parseInt(sellingPlanId));\n if(selectedPlan) {\n price = selectedPlan.price;\n qty = selectedPlan.compare_at_price / selectedVariant.price;\n }\n }\n if(price) {\n const discount = ((selectedVariant.compare_at_price * qty) - price) / 100;\n document.querySelector(\".discount-box\").innerText = 'SAVE ' + new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'GBP',\n minimumFractionDigits: 2,\n }).format(discount);\n document.querySelector(\".final-price-item\").innerText = new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'GBP',\n minimumFractionDigits: 2,\n }).format(price / 100);\n document.querySelector(\".compare-price\").innerText = new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'GBP',\n minimumFractionDigits: 2,\n }).format((selectedVariant.compare_at_price * qty) / 100);\n }\n console.log(sellingPlanId);\n if (sellingPlanId) {\n document.querySelector(\".appstle_subscribe_save_text span.font-light\").innerText = 'free shipping';\n }\n}\n\nconst findSelectedVariant = function () {\n const selectedVariantId = parseInt(productForm.querySelector('[name=\"id\"]').value);\n let selectedVariant;\n for (let i = 0; i < productData.variants.length; i++) {\n if (productData.variants[i].id === selectedVariantId) {\n selectedVariant = productData.variants[i];\n break;\n }\n }\n return selectedVariant;\n};\n\nproductForm.addEventListener('change', function() {\n updateDiscounts();\n});\n\nconst observer = new MutationObserver(function(mutationsList) {\n for(const mutation of mutationsList) {\n if (mutation.type === 'childList') {\n if(mutation.addedNodes && mutation.addedNodes.length > 0) {\n mutation.addedNodes.forEach(node => {\n if(node.id && node.id.indexOf(\"appstle\") > -1) {\n //selling plans inserted into page\n updateDiscounts();\n }\n });\n }\n }\n }\n});\nobserver.observe(productForm, { childList: true, subtree: true });\nsetTimeout(function () {\n observer.disconnect();\n}, 5000);\n"], "mappings": "AAAA,MAAM,cAAgB,SAAS,cAAc,6BAA6B,EACpE,YAAc,KAAK,MAAM,cAAc,QAAQ,OAAO,EACtD,YAAc,SAAS,cAAc,oCAAsC,EAEjF,SAAS,iBAAkB,CACzB,MAAM,gBAAkB,oBAAoB,EACtC,cAAgB,SAAS,cAAc,oCAAoC,EAAE,MAC7E,gCAAkC,gBAAgB,yBACxD,IAAI,MAAQ,gBAAgB,MACxB,IAAM,EACV,GAAG,iCAAmC,gCAAgC,OAAS,GAAK,cAAe,CACjG,MAAM,aAAe,gCAAgC,KAAK,MAAQ,KAAK,kBAAoB,SAAS,aAAa,CAAC,EAC/G,eACD,MAAQ,aAAa,MACrB,IAAM,aAAa,iBAAmB,gBAAgB,MAE1D,CACA,GAAG,MAAO,CACR,MAAM,UAAa,gBAAgB,iBAAmB,IAAO,OAAS,IACtE,SAAS,cAAc,eAAe,EAAE,UAAY,QAAU,IAAI,KAAK,aAAa,QAAS,CAC3F,MAAO,WACP,SAAU,MACV,sBAAuB,CACzB,CAAC,EAAE,OAAO,QAAQ,EAClB,SAAS,cAAc,mBAAmB,EAAE,UAAY,IAAI,KAAK,aAAa,QAAS,CACrF,MAAO,WACP,SAAU,MACV,sBAAuB,CACzB,CAAC,EAAE,OAAO,MAAQ,GAAG,EACrB,SAAS,cAAc,gBAAgB,EAAE,UAAY,IAAI,KAAK,aAAa,QAAS,CAClF,MAAO,WACP,SAAU,MACV,sBAAuB,CACzB,CAAC,EAAE,OAAQ,gBAAgB,iBAAmB,IAAO,GAAG,CAC1D,CACA,QAAQ,IAAI,aAAa,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