(function(o,e){"use strict";var t=function(t){var a=this;a.$form=t;a.$attributeFields=t.find(".variations select");a.variationData=t.data("product_variations");t.off(".wcboost-variation-swatches");if(t.find(".wcboost-variation-swatches__wrapper").length){t.addClass("swatches-support")}a.getChosenAttributes=a.getChosenAttributes.bind(a);t.on("click.wcboost-variation-swatches",".wcboost-variation-swatches__item",{variationSwatches:a},a.onSelect);t.on("change.wcboost-variation-swatches",".variations select",{variationSwatches:a},a.onValueChange);t.on("keydown.wcboost-variation-swatches",".wcboost-variation-swatches__item",{variationSwatches:a},a.onKeyPress);t.on("woocommerce_update_variation_values.wcboost-variation-swatches",{variationSwatches:a},a.onUpdateAttributes);if(wcboost_variation_swatches_params.show_selected_label){t.on("change.wcboost-variation-swatches",".value select",{variationSwatches:a},a.updateLabel);t.on("wc_variation_form.wcboost-variation-swatches",{variationSwatches:a},a.updateAllLabels)}o(e.body).trigger("wcboost_variation_swatches",a)};t.prototype.onSelect=function(t){t.preventDefault();var a=o(this);if(a.hasClass("disabled")||a.data("disabled")){return}var e=a.closest(".wcboost-variation-swatches").find("select"),s=!a.hasClass("selected")?a.data("value"):"";e.trigger("focusin");e.val(s);e.trigger("change")};t.prototype.onValueChange=function(){var t=o(this),a=t.closest(".wcboost-variation-swatches"),e=t.val();if(!a.length){return}a.find(".wcboost-variation-swatches__item.selected").removeClass("selected");if(e){a.find(".wcboost-variation-swatches__item").filter(function(){return this.dataset.value===e}).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();o(this).trigger("click.wcboost-variation-swatches")}};t.prototype.onUpdateAttributes=function(t){var a=t.data.variationSwatches,e=a.getChosenAttributes(),s=e.data;if(!e.chosenCount){a.$form.find(".wcboost-variation-swatches__item").removeClass("selected disabled").data("disabled",false).attr("tabindex",0)}setTimeout(function(){a.$attributeFields.each(function(){var e=o(this),t=e.siblings(".wcboost-variation-swatches__wrapper").find(".wcboost-variation-swatches__item");t.each(function(){var t=o(this),a=e.find('option[value="'+t.data("value")+'"]');if(!a.length||a.prop("disabled")){t.addClass("disabled").removeClass("selected").data("disabled",true).attr("tabindex",-1)}else{t.removeClass("disabled").data("disabled",false).attr("tabindex",0)}})})},10)};t.prototype.updateLabel=function(t){t.data.variationSwatches.appendSelectedLabel(this)};t.prototype.updateAllLabels=function(t){var a=t.data.variationSwatches;a.$form.find(".value select").each(function(){a.appendSelectedLabel(this)})};t.prototype.appendSelectedLabel=function(t){var a=o(t).closest(".value").siblings(".label").find("label"),e=a.find(".wcboost-variation-swatches__selected-label");if(!e.length){e=o('');a.append(e)}if(t.value){e.text(t.options[t.selectedIndex].text).show()}else{e.text("").hide()}};t.prototype.getChosenAttributes=function(){var e={};var s=0;var i=0;this.$attributeFields.each(function(){var t=o(this).data("attribute_name")||o(this).attr("name");var a=o(this).val()||"";if(a.length>0){i++}s++;e[t]=a});return{count:s,chosenCount:i,data:e}};o.fn.wcboost_variation_swatches=function(){new t(this);return this};function a(){o(".variations_form:not(.swatches-support)").each(function(){o(this).wcboost_variation_swatches()})}function s(){if(o(".bundle_form .bundle_data").length>0){o(".bundle_form .bundle_data").on("woocommerce-product-bundle-initialized.wcboost-variation-swatches",a)}}o(function(){a();s();o(e.body).on("init_variation_swatches.wcboost-variation-swatches, wc_variation_form.wcboost-variation-swatches",a);o(e.body).trigger("wcboost_variation_swatches_initialized")})})(jQuery,document);