Joomla=window.Joomla||{};((e,S)=>{S.addEventListener("DOMContentLoaded",function(){const l=1;let c,s,m,p,d,y;u();S.addEventListener("input",function(t){if(t.target.classList.contains("product-quantity")){const r=t.target;if(!r.value||r.value<l){r.value=l}let e=r.value;const o=r?.parentElement?.nextElementSibling?.querySelector(".quantity-price");o.value=Number(o.dataset.value)*Number(e);u()}if(t.target.id.includes("jform_discount_type")){u()}if(t.target.id.includes("jform_discount_value")){u()}});S.addEventListener("change",function(e){if(e.target.parentNode.parentNode.parentNode.classList.contains("easystore-shipping-method")){const t=e.target.value;if(t){const r=t.split(":");S.querySelector(".shipping-amount").value=r[0]}u()}});function b(){let e=S.querySelectorAll(".product-item .quantity-price");let t=0;e.forEach(e=>{t+=Number(e.value)});t=parseFloat(t).toFixed(2);c=t;t=f(t);return t}function f(e){let t=e.toString().split(".");e=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,",")+(t[1]?"."+t[1]:"");return e}function u(){let e=S.querySelector(".currency-symbol").value;let t=b();let r=e+t;S.querySelector(".sub-total-amount").value=c;S.querySelector(".payment-table .sub-total").innerHTML=r;let o=S.querySelector("#jform_discount_type").value;let l=Number(S.querySelector("#jform_discount_value").value);if(l>0){s=v(c,o,l)}else{s=parseFloat(0).toFixed(2)}let u=e+f(s);let n="";if(s>0){n="- "}S.querySelector(".payment-table .discount").innerHTML=n+u;m=Number(S.querySelector(".shipping-amount").value);S.querySelector(".payment-table .shipping").innerHTML=e+f(parseFloat(m).toFixed(2));q();p=Number(S.querySelector(".tax-amount").value);S.querySelector(".payment-table .tax").innerHTML=e+f(parseFloat(p).toFixed(2));d=Number(S.querySelector(".coupon-amount").value);let a="";if(d>0){a="- "}S.querySelector(".payment-table .coupon").innerHTML=a+e+f(parseFloat(d).toFixed(2));y=Number(c)-Number(s)+Number(m)+Number(p)-Number(d);y=parseFloat(y).toFixed(2);let i=e+f(y);S.querySelector(".payment-table .total").innerHTML=i}function q(){let e=S.querySelectorAll(".product-item");let o=0;e.forEach(e=>{let t=Number(e.querySelector(".product-quantity").value);let r=Number(e.querySelector(".easystore-product-tax-amount").value);o=parseFloat(Number(o)+t*r).toFixed(2)});S.querySelector(".tax-amount").value=o}function v(e,t,r){let o;if(t==="percent"){o=Number(e)*Number(r)/100}else{o=Number(r)}return parseFloat(o).toFixed(2)}function e(){S.body.scrollTop=0;S.documentElement.scrollTop=0}})})(Joomla,document);