(()=>{"use strict";function t(){const t=document.querySelectorAll(".variations_form");if(t.length>0)for(let a=0;a<t.length;a++)e(t[a]),n(t[a]),c(t[a])}function e(t,e=""){if(!t)return;const n=""===e?a(t):e;!function(t){if(!t)return;t.querySelectorAll("ul.sp-vswatches-wrapper li").forEach(t=>{t.classList.remove("enabled")})}(t);const r=function(t){const e=JSON.parse(t.dataset.product_variations),a=[];return e.forEach(t=>{a.push(t.attributes)}),a}(t);t.querySelectorAll(".variations select").forEach(e=>{const a=e.dataset.attribute_name,i={...n.data};i[a]="";const s=function(t,e){const a=[];return e.forEach(e=>{let n=!0;for(const a in e){if(""===e[a]){n=!0;break}if(""!==t[a]&&t[a]!==e[a]){n=!1;break}}n&&a.push(e)}),a}(i,r);n.count>0&&s.forEach(e=>{for(const n in e)if(a===n){const a=e[n];if(""===a&&t.querySelectorAll('ul.sp-vswatches-wrapper li[data-attribute_name="'+n+'"]').forEach(t=>{t.classList.add("enabled")}),""!==a){const e=t.querySelector('ul.sp-vswatches-wrapper li[data-value="'+a+'"][data-attribute_name="'+n+'"]');e&&e.classList.add("enabled")}}})}),0===n.count&&r.forEach(e=>{for(const a in e){const n=e[a];if(""!==n&&void 0!==n){const e=t.querySelector('ul.sp-vswatches-wrapper li[data-value="'+n+'"][data-attribute_name="'+a+'"]');e&&e.classList.add("enabled")}""===n&&t.querySelectorAll('ul.sp-vswatches-wrapper.has-custom-variation li[data-attribute_name="'+a+'"]').forEach(t=>{t.classList.add("enabled")})}})}function a(t){const e={data:{},count:0};return t.querySelectorAll(".variations select").forEach(t=>{e.data[t.dataset.attribute_name]=t.value,""!==t.value&&e.count++}),e}function n(t){if(!(JSON.parse(t.dataset.product_variations).length>0))return;const n=t.querySelectorAll(".sp-vswatch-item");if(n)for(let t=0;t<n.length;t++)n[t].classList.remove("sp-vswatches-active"),n[t].addEventListener("click",s);const c=t.querySelectorAll(".variations select");if(c.length>0&&c.forEach(function(a){a.addEventListener("change",function(){e(t)})}),t.classList.contains("sp-catalog-variation")){const e=t.parentNode,n=e.parentNode,s=e.querySelector(".price").cloneNode(!0),c=n.querySelector(".sp-product-image img")?n.querySelector(".sp-product-image img").cloneNode(!0):"",o=e.querySelector(".add_to_cart_button");jQuery(t).on("found_variation",function(s,c){c.price_html&&""!==c.price_html&&r(e,c.price_html),c.image&&c.image.thumb_src&&c.image.thumb_srcset&&i(n,c);const l=this.parentNode.querySelector(".nv_add_to_cart_button");l.setAttribute("aria-label",l.dataset.addToCartAriaLabel),l.innerHTML=l.dataset.addToCart,l.classList.remove("added");let u="?add-to-cart="+t.dataset.product_id+"&variation_id="+c.variation_id;const d=a(this);for(const[t,e]of Object.entries(d.data))u+="&"+t+"="+e;o.setAttribute("href",u)}),jQuery(t).on("woocommerce_variation_has_changed",function(){const t=e.querySelector(".added_to_cart");t&&e.removeChild(t);const l=a(this);var u;l.count!==Object.keys(l.data).length&&(s&&r(e,s.innerHTML),c&&i(n,function(t){const e={image:{}},a=["src","width","height","srcset","thumb_sizes","title","alt"];for(let n=0;n<a.length;n++)if(t.hasAttribute(a[n])){const r="title"!==a[n]&&"alt"!==a[n]&&"thumb_sizes"!==a[n]?"thumb_"+a[n]:a[n];e.image[r]=t.getAttribute(a[n])}return e}(c)),o&&((u=o).setAttribute("aria-label",u.dataset.selectOptionAriaLabel),u.innerHTML=u.dataset.selectOptions,u.classList.remove("added")),o.setAttribute("href",o.dataset.product_permalink))})}}function r(t,e){const a=t.querySelector(".price");if(null===a)return;const n=document.createElement("div");n.innerHTML=e,a.innerHTML=n.innerHTML}function i(t,e){const a=t.querySelector(".sp-product-image img");if(null===a)return;if(!e.image)return;const n={src:"thumb_src",height:"thumb_src_h",width:"thumb_src_w",srcset:"thumb_srcset",sizes:"thumb_sizes",title:"title",alt:"alt"};Object.keys(n).forEach(t=>{e.image[n[t]]&&a.setAttribute(t,e.image[n[t]])})}function s(){if(!0!==this.classList.contains("enabled"))return;const t=this.parentNode.previousSibling,e=this.getAttribute("data-value"),a=document.createEvent("HTMLEvents");t.value=e,a.initEvent("change",!0,!1),t.dispatchEvent(a),o(this.parentNode),this.classList.add("sp-vswatch-active")}function c(t){const a=t.querySelector(".reset_variations");a&&a.addEventListener("click",function(){e(t,{data:{},count:0}),o(t)})}function o(t){const e=t.querySelectorAll(".sp-vswatch-item");if(null!==e)for(let t=0;t<e.length;t++)e[t].classList.remove("sp-vswatch-active")}window.addEventListener("load",function(){t(),document.addEventListener("sparksVSInitNeeded",t=>{l("body")})}),document.addEventListener("productModalLoaded",function(t){const e=t.detail.modalContainer;l(e)}),document.addEventListener("sparksVSNeedsInit",t=>{l(t.detail.container)});const l=e=>{const a=jQuery(e).find(".variations_form");a.length>0&&(a.each(function(){jQuery(this).wc_variation_form()}),t())}})();