(function(n,a){var t=function(t){var e=this;e.$form=t;t.off(".wcboost-variation-swatches");if(t.find(".wcboost-variation-swatches__wrapper").length){t.addClass("swatches-support")}t.on("click.wcboost-variation-swatches",".wcboost-variation-swatches__item",{variationSwatches:e},e.onSelect);t.on("change.wcboost-variation-swatches",".variations select",{variationSwatches:e},e.onValueChange);t.on("keydown.wcboost-variation-swatches",".wcboost-variation-swatches__item",{variationSwatches:e},e.onKeyPress);t.on("click.wcboost-variation-swatches",".reset_variations",{variationSwatches:e},e.onReset);t.on("woocommerce_update_variation_values.wcboost-variation-swatches",{variationSwatches:e},e.onUpdateAttributes);if(wcboost_variation_swatches_params.show_selected_label){t.on("change.wcboost-variation-swatches",".value select",{variationSwatches:e},e.updateLabel);t.on("wc_variation_form.wcboost-variation-swatches",{variationSwatches:e},e.updateAllLabels)}n(a.body).trigger("wcboost_variation_swatches",e)};t.prototype.onSelect=function(t){t.preventDefault();var e=n(this);if(e.hasClass("disabled")||e.data("disabled")){return}var a=e.closest(".wcboost-variation-swatches").find("select"),o=!e.hasClass("selected")?e.data("value"):"";a.trigger("focusin");a.val(o);a.trigger("change")};t.prototype.onValueChange=function(){var t=n(this),e=t.closest(".wcboost-variation-swatches"),a=t.val();if(!e.length){return}e.find(".wcboost-variation-swatches__item.selected").removeClass("selected");if(a){e.find(".wcboost-variation-swatches__item").filter(function(){return this.dataset.value===a}).addClass("selected")}};t.prototype.onKeyPress=function(t){if(t.keyCode&&32===t.keyCode||t.key&&" "===t.key||t.keyCode&&13===t.keyCode||t.key&&"enter"===t.key.toLowerCase()){t.preventDefault();n(this).trigger("click.wcboost-variation-swatches")}};t.prototype.onReset=function(t){t.preventDefault();t.data.variationSwatches.$form.find(".wcboost-variation-swatches__item.selected").removeClass("selected");t.data.variationSwatches.$form.find(".wcboost-variation-swatches__item.disabled").removeClass("disabled").data("disabled",false)};t.prototype.onUpdateAttributes=function(t){var e=t.data.variationSwatches;setTimeout(function(){e.$form.find(".wcboost-variation-swatches").each(function(t,e){var a=n(e),o=a.find("select").find("option"),s=o.filter(":selected"),i=[];o.each(function(t,e){if(e.value!==""){i.push(e.value)}});a.find(".wcboost-variation-swatches__item").each(function(t,e){var a=n(e),o=a.attr("data-value");if(i.indexOf(o)>-1){a.removeClass("disabled").data("disabled",false)}else{a.addClass("disabled").data("disabled",true);if(s.length&&o===s.val()){a.removeClass("selected")}}})})},100)};t.prototype.updateLabel=function(t){t.data.variationSwatches.appendSelectedLabel(this)};t.prototype.updateAllLabels=function(t){t.data.variationSwatches.$form.find(".value select").each(function(){t.data.variationSwatches.appendSelectedLabel(this)})};t.prototype.appendSelectedLabel=function(t){var e=n(t).closest(".value").siblings(".label").find("label"),a=e.find(".wcboost-variation-swatches__selected-label");if(!a.length){a=n('');e.append(a)}if(t.value){a.text(t.options[t.selectedIndex].text).show()}else{a.text("").hide()}};n.fn.wcboost_variation_swatches=function(){new t(this);return this};function e(){n(".variations_form:not(.swatches-support)").each(function(){n(this).wcboost_variation_swatches()})}function o(){if(n(".bundle_form .bundle_data").length>0){n(".bundle_form .bundle_data").on("woocommerce-product-bundle-initialized.wcboost-variation-swatches",e)}}n(function(){e();o();n(a.body).on("init_variation_swatches.wcboost-variation-swatches",e);n(a.body).trigger("wcboost_variation_swatches_initialized")})})(jQuery,document);