!function(t,a,e){if("undefined"==typeof yith_wapo_color_label_attr)return!1;var o=function(t,a){this.$form=t,this.$attr=JSON.parse(yith_wapo_color_label_attr.attributes),this.$select=this.$form.find(".variations select"),this.$use_ajax=!1===this.$form.data("product_variations"),this.$xhr=null,this.variations_gallery=[],void 0===this.$attr&&(this.$attr=[]),t.on("yith_wccl_form_initialized",{obj:this},this.init),this.$select.each(function(){this.setAttribute("data-default_value",this.value)}),this.resetForm(this),this.$form.hasClass("initialized")||this.$form.addClass("initialized").fadeIn().trigger("yith_wccl_form_initialized")};o.prototype.styleOption=function(a,e,o,i){"colorpicker"===o?1===(i=i.split(",")).length?e.append(t("<span/>",{class:"yith_wccl_value",css:{background:i}})):(e.append(t('<span class="yith_wccl_value"><span class="yith-wccl-bicolor"/></span>')),e.find(".yith-wccl-bicolor").css({"border-bottom-color":i[0],"border-left-color":i[1]})):"image"===o?e.append(t("<img/>",{class:"yith_wccl_value",src:i,alt:o})):"label"===o&&e.append(t("<span/>",{class:"yith_wccl_value",text:i}))},o.prototype.addTooltip=function(a,e,o,i,l){if(yith_wapo_color_label_attr.tooltip&&void 0!==e&&e&&!o.find(".yith_wccl_tooltip").length){var r=t('<span class="yith_wccl_tooltip"></span>'),n=yith_wapo_color_label_attr.tooltip_pos+" "+yith_wapo_color_label_attr.tooltip_ani;"image"===i&&(e=e.toString().replace("{show_image}",'<img src="'+l+'" />')),r.addClass(n),o.append(r.html("<span>"+e+"</span>"))}},o.prototype.handleSelect=function(a){var e=a.data.obj;e.$select.each(function(){var a,o=t(this),i=e.$attr[this.name],l=decodeURIComponent(this.name),r=o.parent().find(".select_box"),n=[];(a=o.closest(".select-wrapper")).length||(a=o.closest("td")).length||(a=o.parent()),void 0===i&&(i=e.$attr[l]),yith_wapo_color_label_attr.description&&!e.$form.find(".description_"+l).length&&void 0!==i&&i.descr&&(o.closest("tr").length?o.closest("tr").after('<tr class="description_'+l+'"><td colspan="2">'+i.descr+"</td></tr>"):a.append('<p class="description_'+l+'">'+i.descr+"</p>"));var s=void 0!==i?i.type:o.data("type"),c=void 0!==i&&i.terms;void 0!==i&&i.terms&&void 0!==s&&s&&(o.addClass("yith_wccl_custom").hide(),a.addClass("yith_wccl_is_custom"),r.length&&yith_wapo_color_label_attr.grey_out||(r.remove(),r=t("<div />",{class:"select_box_"+s+" select_box "+o.attr("name")}).insertAfter(o)),o.find("option").each(function(){var a=t(this).val();if(c&&void 0!==c[a]||void 0!==t(this).data("value")&&""!==t(this).data("value")){n.push(a);var i=t(this),l="select_option_"+s+" select_option",d=c&&void 0!==c[a]?c[a].value:t(this).data("value"),_=c&&void 0!==c[a]?c[a].tooltip:t(this).data("tooltip"),h=r.find('[data-value="'+a+'"]');h.length||(a!==o.val()&&a!==o.attr("data-default_value")||(l+=" selected"),(h=t("<div/>",{class:l,"data-value":a}).appendTo(r)).off("click").on("click",function(a){var l=t(this).hasClass("inactive"),r=t(this).hasClass("selected");if(l){var n=o.data("attribute_name")||o.attr("name");!function(a,e,o){var i=!1,l=a.data("product_variations"),r=a.find(".variations select"),n=[];t.each(r,function(){var a=t(this).data("attribute_name")||t(this).attr("name");n[a]=o===a?e:t(this).val()});for(var s=0;s<l.length;s++){var c=l[s];if(i)break;for(var d in i=c,c.attributes)if(c.attributes.hasOwnProperty(d)){var _=c.attributes[d];_!==n[d]&&""!==_&&(i=!1)}}return i}(e.$form,t(this).data("value"),n)?e.resetForm(e):o.val("").change()}r?o.val("").change():o.val(i.val()).change(),t(this).toggleClass("selected"),t(this).siblings().removeClass("selected")}),e.styleOption(e,h,s,d),e.addTooltip(e,_,h,s,d))}}),r.children().each(function(){var a=t(this).data("value")+"";-1===t.inArray(a,n)?t(this).addClass("inactive"):t(this).removeClass("inactive")}),e.$form.trigger("yith_wccl_select_initialized",[o,i]))})},o.prototype.setDefaultValue=function(a){var e=a.data.obj;e.$select.each(function(){t(this).val(t(this).attr("data-default_value"))}),e.$select.first().change()},o.prototype.handleCheckVariations=function(t,a,e){var o=t.data.obj;if(!e){if(o.$found&&(t.data.obj.$found=!1,!o.$use_ajax))return;o.$changed&&(t.data.obj.$changed=!1)}},o.prototype.handleFoundVariation=function(t,a){var e=t.data.obj;e.$use_ajax?e.handleSelect(t):e.$select.last().trigger("focusin")},o.prototype.handleVariationGallery=function(a,e){var o,i=a.data.obj,l=t(yith_wapo_color_label_attr.single_gallery_selector);l.length&&(null!==i.$xhr&&i.$xhr.abort(),(o=void 0!==e?e.variation_id:i.$form.find('input[name="product_id"]').val())&&void 0!==o&&(void 0!==i.variations_gallery[o]?i.loadVariationGallery(i.variations_gallery[o],l,e):i.$xhr=t.ajax({url:yith_wapo_color_label_attr.ajaxurl.toString().replace("%%endpoint%%",yith_wapo_color_label_attr.actionVariationGallery),data:{action:yith_wapo_color_label_attr.actionVariationGallery,id:o,context:"frontend"},type:"POST",dataType:"html",beforeSend:function(){l.addClass("loading-gallery")},success:function(t){l.removeClass("loading-gallery"),i.$xhr=null,t&&(i.variations_gallery[o]=t,i.loadVariationGallery(t,l,e))}})))},o.prototype.loadVariationGallery=function(a,o,i){o.replaceWith(a).fadeIn(),"undefined"!=typeof wc_single_product_params&&t(yith_wapo_color_label_attr.single_gallery_selector).wc_product_gallery(wc_single_product_params),this.$form.wc_variations_image_update(i),t(e).trigger("yith_wccl_product_gallery_loaded")},o.prototype.resetForm=function(t){t.$form.find("div.select_option").removeClass("selected inactive"),t.$select.val("").change(),t.$form.trigger("reset_data")},o.prototype.onReset=function(t){t.data.obj.$form.find(".select_option.selected").removeClass("selected inactive")},o.prototype.init=function(a){var e=a.data.obj;e.$form.on("click.wc-variation-form",".reset_variations",{obj:e},e.onReset),e.$form.on("woocommerce_update_variation_values",{obj:e},e.handleSelect),e.$form.on("check_variations",{obj:e},e.handleCheckVariations),e.$form.on("found_variation",{obj:e},e.handleFoundVariation),yith_wapo_color_label_attr.enable_handle_variation_gallery&&(e.$form.on("found_variation",{obj:e},e.handleVariationGallery),e.$form.on("reset_image",{obj:e},e.handleVariationGallery)),e.handleSelect(a),e.$select.each(function(){var a=t(this).attr("data-default_value");t(this).removeAttr("data-default_value"),t(this).val(a)})},t.yith_wccl=function(a){forms=t(".variations_form.cart:not(.initialized), .owl-item.cloned .variations_form, form.cart.ywcp_form_loaded"),void 0===a&&(a=[]),forms.each(function(){new o(t(this),a)})},t(e).on("yith_wccl_product_gallery_loaded",function(){if("undefined"!=typeof mkdf&&"function"==typeof mkdf.modules.common.mkdfPrettyPhoto){var a=t(".mkdf-woo-single-page.mkdf-woo-single-has-pretty-photo .images .woocommerce-product-gallery__image");a.length&&(a.children("a").attr("data-rel","prettyPhoto[woo_single_pretty_photo]"),mkdf.modules.common.mkdfPrettyPhoto())}"undefined"!=typeof Flatsome&&(Flatsome.attach(t(".product-gallery")),t(".zoom-button").click(function(a){a.preventDefault(),t(".product-gallery-slider").find(".is-selected a").click()}))}),t(e).ready(function(){t.yith_wccl()})}(jQuery,window,document);