let frame,swatchConf=swatch_conf||{};jQuery(document).ready(function(t){"use strict";let e=window.wp,i=t("body");t("#term-color").wpColorPicker(),i.on("click",".xpro_upload_img_button",function(i){i.preventDefault();let r=t(this);frame||(frame=e.media.frames.downloadable_file=e.media({title:swatchConf.i18n.title,button:{text:swatchConf.i18n.button},multiple:!1})).on("select",function(){let t=frame.state().get("selection").first().toJSON();r.siblings("input.xpro_term_img").val(t.id),r.siblings(".xpro_remove_img_btn").show(),void 0!==t.sizes.thumbnail?r.parent().prev(".xpro_term_img_thumbnail").find("img").attr("src",t.sizes.thumbnail.url):r.parent().prev(".xpro_term_img_thumbnail").find("img").attr("src",t.url)}),frame.open()}).on("click",".xpro_remove_img_btn",function(){let e=t(this);return e.siblings("input.xpro_term_img").val(""),e.siblings(".xpro_remove_img_btn").hide(),e.parent().prev(".xpro_term_img_thumbnail").find("img").attr("src",swatchConf.dummy),!1});let r=t("#xpro_tpl_modal"),o=r.find(".spinner"),a=r.find(".message"),n=null;function s(){r.find(".xpro_term__name input, .xpro_term__slug input").val(""),o.removeClass("is-active"),a.removeClass("error success").hide(),r.hide()}i.on("click",".xpro_assign_new_attribute",function(i){i.preventDefault();let o=t(this),a=e.template("xpro__tpl_input__tax"),s={type:o.data("type"),tax:o.closest(".woocommerce_attribute").data("taxonomy")};r.find(".xpro_term__swatch").html(t("#tmpl-xpro__tpl_input__"+s.type).html()),r.find(".xpro_term__tax").html(a(s)),"color"==s.type&&r.find("input.xpro_input__color").wpColorPicker(),n=o.closest(".woocommerce_attribute.wc-metabox"),r.show()}).on("click",".xpro_modal__close, .xpro_modal__backdrop",function(t){t.preventDefault(),s()}),i.on("click",".xpro_add_attribute_submit",function(i){i.preventDefault(),t(this).data("type");let l=!1,m={};r.find(".xpro__input").each(function(){let e=t(this);"slug"===e.attr("name")||e.val()?e.removeClass("error"):(e.addClass("error"),l=!0),m[e.attr("name")]=e.val()}),l||(o.addClass("is-active"),a.hide(),e.ajax.send("xpro_add_new_attribute",{data:m,error:function(t){o.removeClass("is-active"),a.addClass("error").text(t).show()},success:function(t){o.removeClass("is-active"),a.addClass("success").text(t.msg).show(),n.find("select.attribute_values").append('<option value="'+t.id+'" selected="selected">'+t.name+"</option>"),n.find("select.attribute_values").change(),s()}}))})});