window.addEventListener("DOMContentLoaded",()=>(new EasystoreVariants).run());class EasystoreVariants{constructor(){this.variants=Joomla.getOptions("easystore.variants")??[];this.options=Joomla.getOptions("easystore.options")??[]}generateCombination(...t){t.sort();return t.join(";")}findByCombination(e){return this.variants.find(t=>t.combination.toLowerCase()===e)??{}}listenChanges(){const t=document.querySelector(".easystore-product-price-current");const e=document.querySelectorAll(".easystore-product-variant input[type=radio]:checked");const n=document.querySelectorAll(".easystore-gallery-image");const o=[...e].reduce((t,e)=>{const n=e.name;const o=e.value;t[n]=o;return t},{});const s=Object.values(o).length>0?this.generateCombination(...Object.values(o)):"";const i=this.findByCombination(s);if(!!t&&!!i){t.innerText=i.price_with_currency}if(!!n&&i){const r=[...n].find(t=>{const{dataset:e}=t;return e&&i?.image?.id&&e.id==i.image.id});if(!!r){const a=new Event("click");r.dispatchEvent(a)}}}run(){this.listenChanges(null);const t=document.querySelectorAll(".easystore-product-variant input[type=radio]");for(const e of[...t]){e.addEventListener("change",this.listenChanges.bind(this))}}}