jQuery(document).ready(function(t){function a(t,a){let e;return function(){const n=arguments;clearTimeout(e),e=setTimeout(function(){t.apply(null,n)},a)}}function e(t){return String(t||"").replace(/^attribute_/,"").trim()}function n(t){return null!=t&&("boolean"==typeof t.is_in_stock?t.is_in_stock:"boolean"==typeof t.variation_is_active?t.variation_is_active:"boolean"!=typeof t.is_purchasable||t.is_purchasable)}function i(a){return new Promise(function(e){if(!a)return e([]);if("undefined"!=typeof wc_add_to_cart_params&&wc_add_to_cart_params.wc_ajax_url){const n=String(wc_add_to_cart_params.wc_ajax_url).replace("%%endpoint%%","get_variations");return void t.post(n,{product_id:a}).done(function(t){return Array.isArray(t)?e(t):t&&Array.isArray(t.data)?e(t.data):t&&Array.isArray(t.variations)?e(t.variations):void e([])}).fail(function(){e([])})}const n=window.location.origin+window.location.pathname+"?wc-ajax=get_variations";t.post(n,{product_id:a}).done(function(t){return Array.isArray(t)?e(t):t&&Array.isArray(t.data)?e(t.data):void e([])}).fail(function(){e([])})})}function r(t){return new Promise(function(a){const e=t.data("product_variations");if(Array.isArray(e)&&e.length)return s&&console.debug("variations from data()",e),a(e);const n=t.find('script[type="application/json"]').first().html();if(n)try{const t=JSON.parse(n);if(Array.isArray(t)&&t.length)return s&&console.debug("variations from script JSON",t),a(t)}catch(t){}const r=t.find('input[name="product_id"]').val()||t.data("product_id")||t.find('input[name="product_id"]').attr("value");i(r).then(function(t){s&&console.debug("variations from ajax",t),a(Array.isArray(t)?t:[])})})}function o(a){r(a).then(function(i){if(!Array.isArray(i)||!i.length)return void(s&&console.debug("no variations available — skipping update"));const r={};a.find(".variable-items-wrapper .variable-item.selected").each(function(){const a=t(this),n=e(a.data("attribute_name")),i=a.data("value");void 0!==i&&String(i).length&&(r[n]=String(i))}),s&&console.debug("selectedMap",r),a.find(".variable-items-wrapper").each(function(){const o=t(this),s=e(o.data("attribute_name"));o.find(".variable-item").each(function(){const e=t(this),c=String(e.data("value")),d=Object.assign({},r);d[s]=c;const u=i.some(function(t){if(!t||!t.attributes)return!1;const a=Object.entries(d).every(function([a,e]){const n=String(t.attributes["attribute_"+a]||"").trim();return""===n||n===String(e)});return a&&n(t)});if(u)e.removeClass("disabled").css("pointer-events","").removeAttr("data-wvstooltip-out-of-stock").attr("aria-disabled","false");else if(e.addClass("disabled").css("pointer-events","none").attr("data-wvstooltip-out-of-stock","").attr("aria-disabled","true"),e.hasClass("selected")){e.removeClass("selected");try{const t=o.attr("data-attribute_name");if(t){const e=a.find('select[name="'+t+'"]');e.length&&e.val("").trigger("change")}}catch(t){}}})})})}const s=!1;t(".variations_form").each(function(){const e=t(this),n=a(function(){o(e)},80);n(),t(document).on("click",".variable-item",function(a){const e=t(this);if(e.hasClass("disabled"))return s&&console.debug("click on disabled item prevented"),void a.preventDefault();e.siblings().removeClass("selected"),e.addClass("selected"),n()});const i=new MutationObserver(function(t){n()});try{i.observe(e[0],{childList:!0,subtree:!0,attributes:!0})}catch(t){}e.on("woocommerce_variation_select_change change_variations found_variation change",function(){n()}),t(document).on("click",".reset_variations",function(){e.find(".variable-item").removeClass("selected disabled").css("pointer-events","").removeAttr("data-wvstooltip-out-of-stock aria-disabled"),e.find("select").val("").trigger("change"),n()});let c=0;const d=setInterval(function(){r(e).then(function(t){Array.isArray(t)&&t.length?(n(),clearInterval(d)):++c>20&&clearInterval(d)})},500)})});