!function(e){"use strict";e.fn.shopengine__extend_var_swatch_form=function(){return this.each((function(){var t=e(this);t.addClass("swatches-support").on("click",".swatch",(function(s){s.preventDefault();var a=e(this),i=a.closest(".value").find("select"),n=a.attr("data-value");if(!a.hasClass("disabled")){if(i.trigger("focusin"),!i.find('option[value="'+n+'"]').length)return a.siblings(".swatch").removeClass("selected"),i.val("").change(),void t.trigger("shopengine__no_matching_variation",[a]);a.hasClass("selected")?(i.val(""),a.removeClass("selected")):(a.addClass("selected").siblings(".selected").removeClass("selected"),i.val(n)),i.change()}})).on("click",".reset_variations",(function(){t.find(".swatch.selected").removeClass("selected"),t.find(".swatch.disabled").removeClass("disabled")})).on("woocommerce_update_variation_values",(function(){setTimeout((function(){t.find("tbody tr").each((function(){var t=e(this),s=t.find("select").find("option"),a=s.filter(":selected"),i=[];s.each((function(e,t){""!==t.value&&i.push(t.value)})),t.find(".swatch").each((function(){var t=e(this),s=t.attr("data-value");i.indexOf(s)>-1?t.removeClass("disabled"):(t.addClass("disabled"),a.length&&s===a.val()&&t.removeClass("selected"))}))}))}),100)})).on("shopengine__no_matching_variation",(function(){window.alert(wc_add_to_cart_variation_params.i18n_no_matching_variations_text)}))}))},e((function(){setTimeout((()=>{e(".variations_form").shopengine__extend_var_swatch_form()}),500)})),e(document.body).on("click",".shopengine_loop_swatches_wrap .shopengine_swatches .swatch_color.swatch_color_loop",(function(){const t=e(".product-type-variable"),s=t.find(".woocommerce-loop-product__link").find(".attachment-woocommerce_thumbnail");t.find(".shopengine_loop_swatches_wrap").length&&s.length&&(e(s).siblings(".lds-spinner").remove(),e(s).siblings(".preloader-shadow").remove(),e(s).before('<div class="lds-spinner shopengine-swatch-preloader"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>'),e(s).before('<div class="preloader-shadow"></div>'));const a=e(this);let i=a.parents(".shopengine_loop_swatches_wrap").attr("data-product-id"),n=[[a.parent().attr("data-attribute_name"),a.attr("data-value")]];a.addClass("selected").siblings().removeClass("selected");let o=!1;if(a.parent().siblings(".shopengine-loop-swatches").each((function(t){e(this).children(".selected").length>0?n.push([e(this).children(".selected").parent().attr("data-attribute_name"),e(this).children(".selected").attr("data-value")]):o=!0})),!o){const t=e(a).parent(".shopengine-loop-swatches").parent(".shopengine_loop_swatches_wrap").siblings(".woocommerce-loop-product__link");let s=t.find(".shopengine-swatch-preloader"),o=t.find(".attachment-woocommerce_thumbnail"),c=t.find(".preloader-shadow"),r=o.innerHeight();e(c).css("height",`${r}`),e(s).css("top",r/2-40),e(window).resize((function(){e(c).css("height",`${r}`),e(s).css("top",r/2-40)})),e.ajax({url:frontendApiSettings.ajaxurl,type:"POST",data:{action:"shopengine_swatch_image_on_loop_products",nonce:frontendApiSettings.nonce,selectedData:n,productId:i},beforeSend:function(e){s.addClass("preloader-active"),c.addClass("overlay-active")},error:function(e){console.log("Error: ",e),s.removeClass("preloader-active"),c.removeClass("overlay-active")},success:function(t){!0===t.success&&function(t,s){let a=(s=e.parseHTML(s))[0].src,i=s[0].srcset;t.parents(".shopengine_loop_swatches_wrap").parents("li.product.type-product.has-post-thumbnail").find("img.attachment-woocommerce_thumbnail.size-woocommerce_thumbnail").attr({src:a,srcset:i}),t.parents(".shopengine_loop_swatches_wrap").parent().siblings(".shopengine-archive-products__left-image").children("a img").attr({src:a,srcset:i})}(a,t.data.variation_img_html)},complete:function(){s.removeClass("preloader-active"),c.removeClass("overlay-active")}})}}))}(jQuery);