jQuery(function(a){"use strict";var e={init:function(){a("#variable_product_options").on("change","input.variable_is_downloadable",this.variable_is_downloadable).on("change","input.variable_is_virtual",this.variable_is_virtual).on("change","input.variable_manage_stock",this.variable_manage_stock).on("click","button.notice-dismiss",this.notice_dismiss).on("click","h3 .sort",this.set_menu_order).on("click","button.add_price_for_variations",this.open_modal_to_set_variations_price).on("reload",this.reload).on("click","button.create-variations",this.create_variations),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").trigger("change"),a("#woocommerce-product-data").on("woocommerce_variations_loaded",this.variations_loaded),a(document.body).on("keyup",".wc_input_variations_price",this.maybe_enable_button_to_add_price_to_variations)},create_variations:function(e){if(a(this).hasClass("disabled"))e.preventDefault();else{var i=a(".woocommerce_variation_new_attribute_data");a("#variable_product_options").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o=i.find("input, select, textarea"),t={post_id:woocommerce_admin_meta_boxes.post_id,product_type:a("#product-type").val(),data:o.serialize(),action:"woocommerce_add_attributes_and_variations",security:woocommerce_admin_meta_boxes.add_attributes_and_variations};a.post(woocommerce_admin_meta_boxes.ajax_url,t,function(e){if(e.error)window.alert(e.error),a("#variable_product_options").unblock();else if(e){var i=window.location.toString();i=i.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),a.get(i,function(e){a("#variable_product_options").unblock(),a("#variable_product_options_inner").replaceWith(a(e).find("#variable_product_options_inner")),a("#variable_product_options").trigger("reload"),a("#product_attributes > .product_attributes").replaceWith(a(e).find("#product_attributes > .product_attributes"))})}})}},reload:function(){o.load_variations(1).then(o.show_hide_variation_empty_state),t.set_paginav(0)},variable_is_downloadable:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()},variable_is_virtual:function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()},maybe_enable_button_to_add_price_to_variations:function(){var e=parseInt(a(".wc_input_variations_price").val(),10);isNaN(e)?a(".add_variations_price_button").prop("disabled",!0):a(".add_variations_price_button").prop("disabled",!1)},variable_manage_stock:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).closest(".woocommerce_variation").find(".variable_stock_status").show(),a(this).is(":checked")&&(a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show(),a(this).closest(".woocommerce_variation").find(".variable_stock_status").hide()),a("input#_manage_stock:checked").length&&a(this).closest(".woocommerce_variation").find(".variable_stock_status").hide()},notice_dismiss:function(){a(this).closest("div.notice").remove()},variations_loaded:function(i,o){o=o||!1;var t=a("#woocommerce-product-data");o||(a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock",t).trigger("change"),a(".woocommerce_variation",t).each(function(e,i){var o=a(i),t=a(".sale_price_dates_from",o).val(),n=a(".sale_price_dates_to",o).val();""===t&&""===n||a("a.sale_schedule",o).trigger("click")}),a(".woocommerce_variations .variation-needs-update",t).removeClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes",t).attr("disabled","disabled")),a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".woocommerce_variations .tips, .woocommerce_variations .help_tip, .woocommerce_variations .woocommerce-help-tip, .toolbar-variations-defaults .woocommerce-help-tip",t).tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),a(".sale_price_dates_fields",t).find("input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,onSelect:function(){var e=a(this).is(".sale_price_dates_from")?"minDate":"maxDate",i=a(this).closest(".sale_price_dates_fields").find("input"),o=a(this).datepicker("getDate");i.not(this).datepicker("option",e,o),a(this).trigger("change")}}),a(".woocommerce_variations",t).sortable({items:".woocommerce_variation",cursor:"move",axis:"y",handle:".sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,stop:function(){e.variation_row_indexes()}}),a(document.body).trigger("wc-enhanced-select-init")},set_variations_price:function(){var e=a(".wc_input_variations_price").val(),i=a("select#product-type").val();a(`.wc_input_price[name^=${"variable-subscription"===i?"variable_subscription_sign_up_fee":"variable_regular_price"}]`).each(function(i,o){"0"!==a(o).val()&&""!==a(o).val()||a(o).val(e).trigger("change")}),o.save_variations()},open_modal_to_set_variations_price:function(){a(this).WCBackboneModal({template:"wc-modal-set-price-variations"}),a(".add_variations_price_button").on("click",e.set_variations_price)},set_menu_order:function(e){e.preventDefault();var i=a(this).closest(".woocommerce_variation").find(".variation_menu_order"),t=a(this).closest(".woocommerce_variation").find(".variable_post_id").val(),n=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_menu_order,i.val());null!=n&&(i.val(parseInt(n,10)).trigger("change"),a(this).closest(".woocommerce_variation").append('<input type="hidden" name="new_variation_menu_order_id" value="'+encodeURIComponent(t)+'" />'),a(this).closest(".woocommerce_variation").append('<input type="hidden" name="new_variation_menu_order_value" value="'+encodeURIComponent(parseInt(n,10))+'" />'),o.save_variations())},variation_row_indexes:function(){var e=a("#variable_product_options").find(".woocommerce_variations"),i=parseInt(e.attr("data-page"),10),o=parseInt((i-1)*woocommerce_admin_meta_boxes_variations.variations_per_page,10);a(".woocommerce_variations .woocommerce_variation").each(function(e,i){a(".variation_menu_order",i).val(parseInt(a(i).index(".woocommerce_variations .woocommerce_variation"),10)+1+o).trigger("change")})}},i={variable_image_frame:null,setting_variation_image_id:null,setting_variation_image:null,wp_media_post_id:wp.media.model.settings.post.id,init:function(){a("#variable_product_options").on("click",".upload_image_button",this.add_image),a("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(e){var o=a(this),t=o.attr("rel"),n=o.closest(".upload_image");if(i.setting_variation_image=n,i.setting_variation_image_id=t,e.preventDefault(),o.is(".remove"))a(".upload_image_id",i.setting_variation_image).val("").trigger("change"),i.setting_variation_image.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),i.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(i.variable_image_frame)return i.variable_image_frame.uploader.uploader.param("post_id",i.setting_variation_image_id),void i.variable_image_frame.open();wp.media.model.settings.post.id=i.setting_variation_image_id,i.variable_image_frame=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),i.variable_image_frame.on("select",function(){var e=i.variable_image_frame.state().get("selection").first().toJSON(),o=e.sizes&&e.sizes.thumbnail?e.sizes.thumbnail.url:e.url;a(".upload_image_id",i.setting_variation_image).val(e.id).trigger("change"),i.setting_variation_image.find(".upload_image_button").addClass("remove"),i.setting_variation_image.find("img").eq(0).attr("src",o),wp.media.model.settings.post.id=i.wp_media_post_id}),i.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=i.wp_media_post_id}},o={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).on("click","button.cancel-variation-changes",this.cancel_variations).on("click",".remove_variation",this.remove_variation).on("click",".downloadable_files a.delete",this.input_changed),a(document.body).on("change input","#variable_product_options .woocommerce_variations :input",this.input_changed).on("change",".variations-defaults select",this.defaults_changed);var e=a("form#post");e.on("submit",this.save_on_submit),a("input:submit",e).on("click keypress",function(){e.data("callerid",this.id)}),a(".wc-metaboxes-wrapper").on("change","#field_to_edit",this.do_variation_action),a(".wc-metaboxes-wrapper").on("click","button.generate_variations",this.generate_variations),a(".wc-metaboxes-wrapper").on("click","button.add_variation_manually",this.add_variation_manually)},check_for_changes:function(){var e=a("#variable_product_options").find(".woocommerce_variations .variation-needs-update");if(0<e.length){if(!window.confirm(woocommerce_admin_meta_boxes_variations.i18n_edited_variations))return e.removeClass("variation-needs-update"),!1;o.save_changes()}return!0},block:function(){a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a("#woocommerce-product-data").unblock()},initial_load:function(){0===a("#variable_product_options").find(".woocommerce_variations .woocommerce_variation").length&&t.go_to_page()},load_variations:function(e,i){return new Promise((t,n)=>{e=e||1,i=i||woocommerce_admin_meta_boxes_variations.variations_per_page;var r=a("#variable_product_options").find(".woocommerce_variations");o.block(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_load_variations",security:woocommerce_admin_meta_boxes_variations.load_variations_nonce,product_id:woocommerce_admin_meta_boxes_variations.post_id,attributes:r.data("attributes"),page:e,per_page:i},type:"POST",success:function(i){r.empty().append(i).attr("data-page",e),a("#woocommerce-product-data").trigger("woocommerce_variations_loaded"),o.unblock(),t(i)},error:function(a,e,i){o.unblock(),n({jqXHR:a,textStatus:e,errorThrown:i})}})})},get_variations_fields:function(e){var i=a(":input",e).serializeJSON();return a(".variations-defaults select").each(function(e,o){var t=a(o);i[t.attr("name")]=t.val()}),i},save_changes:function(e){var i=a("#variable_product_options").find(".woocommerce_variations"),t=a(".variation-needs-update",i),n={};0<t.length&&(o.block(),(n=o.get_variations_fields(t)).action="woocommerce_save_variations",n.security=woocommerce_admin_meta_boxes_variations.save_variations_nonce,n.product_id=woocommerce_admin_meta_boxes_variations.post_id,n["product-type"]=a("#product-type").val(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:n,type:"POST",success:function(i){t.removeClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").attr("disabled","disabled"),a("#woocommerce-product-data").trigger("woocommerce_variations_saved"),"function"==typeof e&&e(i),o.unblock()}}))},save_variations:function(){return a("#variable_product_options").trigger("woocommerce_variations_save_variations_button"),o.save_changes(function(e){var i=a("#variable_product_options").find(".woocommerce_variations"),o=i.attr("data-page");a("#variable_product_options").find("#woocommerce_errors").remove(),e&&i.before(e),a(".variations-defaults select").each(function(){a(this).attr("data-current",a(this).val())}),t.go_to_page(o)}),!1},save_on_submit:function(e){0<a("#variable_product_options").find(".woocommerce_variations .variation-needs-update").length&&(e.preventDefault(),a("#variable_product_options").trigger("woocommerce_variations_save_variations_on_submit"),o.save_changes(o.save_on_submit_done))},save_on_submit_done:function(){var e=a("form#post");"publish"===e.data("callerid")?e.append('<input type="hidden" name="publish" value="1" />').trigger("submit"):e.append('<input type="hidden" name="save-post" value="1" />').trigger("submit")},cancel_variations:function(){var e=parseInt(a("#variable_product_options").find(".woocommerce_variations").attr("data-page"),10);return a("#variable_product_options").find(".woocommerce_variations .variation-needs-update").removeClass("variation-needs-update"),a(".variations-defaults select").each(function(){a(this).val(a(this).attr("data-current"))}),t.go_to_page(e),!1},add_variation:function(){o.block();var i={action:"woocommerce_add_variation",post_id:woocommerce_admin_meta_boxes_variations.post_id,loop:a(".woocommerce_variation").length,security:woocommerce_admin_meta_boxes_variations.add_variation_nonce};return a.post(woocommerce_admin_meta_boxes_variations.ajax_url,i,function(i){var n=a(i);n.addClass("variation-needs-update"),a(".woocommerce-notice-invalid-variation").remove(),a("#variable_product_options").find(".woocommerce_variations").prepend(n),a("button.cancel-variation-changes, button.save-variation-changes").prop("disabled",!1),t.update_single_quantity(),e.variations_loaded(null,!0),o.show_hide_variation_empty_state(),a("#variable_product_options").trigger("woocommerce_variations_added",1),o.unblock()}),!1},remove_variation:function(){if(o.check_for_changes(),window.confirm(woocommerce_admin_meta_boxes_variations.i18n_remove_variation)){var e=a(this).attr("rel"),i=[],n={action:"woocommerce_remove_variations"};o.block(),0<e?(i.push(e),n.variation_ids=i,n.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,n,function(){var e=a("#variable_product_options").find(".woocommerce_variations"),i=parseInt(e.attr("data-page"),10),o=Math.ceil((parseInt(e.attr("data-total"),10)-1)/woocommerce_admin_meta_boxes_variations.variations_per_page),n=1;a("#woocommerce-product-data").trigger("woocommerce_variations_removed"),i===o||i<=o?n=i:i>o&&0!==o&&(n=o),0===o&&a(".generate_variations").text("Generate variations"),t.go_to_page(n,-1)})):o.unblock(),window.wcTracks.recordEvent("product_variations_buttons",{action:"remove_variation"})}return!1},link_all_variations:function(){if(o.check_for_changes(),window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){o.block();var e={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,e,function(e){const i=parseInt(e,10)||0,n=1===i?woocommerce_admin_meta_boxes_variations.i18n_variation_added:woocommerce_admin_meta_boxes_variations.i18n_variations_added.replace("%qty%",i);window.wp.data.dispatch("core/notices").createSuccessNotice(n,{icon:"🎉"}),o.show_hide_variation_empty_state(),i>0?(t.go_to_page(1,i),a(".generate_variations").text("Regenerate variations")):o.unblock()}),window.wcTracks.recordEvent("product_variations_buttons",{action:"generate_variations"})}return!1},input_changed:function(e){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").prop("disabled",!1),"input"===e.type&&a(this).is(":text")||a("#variable_product_options").trigger("woocommerce_variations_input_changed")},defaults_changed:function(){a(this).closest("#variable_product_options").find(".woocommerce_variation:first").addClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").prop("disabled",!1),a("#variable_product_options").trigger("woocommerce_variations_defaults_changed")},do_variation_action:function(){var e,i=a(this).val(),n={},r=0;switch(i){case"delete_all":window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations)&&window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning)&&(n.allowed=!0,r=-1*parseInt(a("#variable_product_options").find(".woocommerce_variations").attr("data-total"),10));break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":if(null==(e=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent)))return;e.indexOf("%")>=0?n.value=accounting.unformat(e.replace(/\%/,""),woocommerce_admin.mon_decimal_point)+"%":n.value=accounting.unformat(e,woocommerce_admin.mon_decimal_point);break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_low_stock_amount":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":if(null==(e=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value)))return;n.value=e;break;case"variable_sale_schedule":if(n.date_from=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),n.date_to=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),null===n.date_from&&(n.date_from=!1),null===n.date_to&&(n.date_to=!1),!1===n.date_to&&!1===n.date_from)return;break;default:if(a("select.variation_actions").trigger(i),null===(n=a("select.variation_actions").triggerHandler(i+"_ajax_data",n)))return}"delete_all"===i&&n.allowed?(a("#variable_product_options").find(".variation-needs-update").removeClass("variation-needs-update"),a(".generate_variations").text("Generate variations")):o.check_for_changes(),o.block(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_bulk_edit_variations",security:woocommerce_admin_meta_boxes_variations.bulk_edit_variations_nonce,product_id:woocommerce_admin_meta_boxes_variations.post_id,product_type:a("#product-type").val(),bulk_action:i,data:n},type:"POST",success:function(){t.go_to_page(1,r)}})},show_hide_variation_empty_state:function(){var e=a("#variable_product_options").find(".woocommerce_variations");parseInt(e.attr("data-total"))>0?(a("#variable_product_options_inner").removeClass("no-variations"),a("#field_to_edit").removeClass("hidden")):(a("#variable_product_options_inner").addClass("no-variations"),a("#field_to_edit").addClass("hidden"))},generate_variations:function(){o.link_all_variations()},add_variation_manually:function(){o.add_variation()}},t={init:function(){a(document.body).on("change",".variations-pagenav .page-selector",this.page_selector).on("click",".variations-pagenav .first-page",this.first_page).on("click",".variations-pagenav .prev-page",this.prev_page).on("click",".variations-pagenav .next-page",this.next_page).on("click",".variations-pagenav .last-page",this.last_page)},update_variations_count:function(e){var i=a("#variable_product_options").find(".woocommerce_variations"),o=parseInt(i.attr("data-total"),10)+e,t=a(".variations-pagenav .displaying-num");i.attr("data-total",o);const n=1===o?woocommerce_admin_meta_boxes_variations.i18n_variation_count_single:woocommerce_admin_meta_boxes_variations.i18n_variation_count_plural.replace("%qty%",o);return t.text(n),o},update_single_quantity:function(){t.update_variations_count(1);const e=a(".variations-pagenav");e.is(":hidden")&&(a("option, optgroup",".variation_actions").show(),a(".variation_actions").val("bulk_actions"),a("#variable_product_options").find(".toolbar").show(),e.show(),a(".pagination-links",e).hide())},set_paginav:function(e){var i=a("#variable_product_options").find(".woocommerce_variations"),o=t.update_variations_count(e),n=a("#variable_product_options").find(".toolbar"),r=a(".variation_actions"),_=a(".variations-pagenav"),s=a(".pagination-links",_),c=Math.ceil(o/woocommerce_admin_meta_boxes_variations.variations_per_page),d="";i.attr("data-total_pages",c),a(".total-pages",_).text(c);for(var l=1;l<=c;l++)d+='<option value="'+l+'">'+l+"</option>";a(".page-selector",_).empty().html(d),0===o?(n.not(".toolbar-top, .toolbar-buttons").hide(),_.hide(),a("option, optgroup",r).hide(),a(".variation_actions").val("bulk_actions"),a('option[data-global="true"]',r).show()):(n.show(),_.show(),a("option, optgroup",r).show(),a(".variation_actions").val("bulk_actions"),1===c?s.hide():s.show())},check_is_enabled:function(e){return!a(e).hasClass("disabled")},change_classes:function(e,i){var o=a(".variations-pagenav .first-page"),t=a(".variations-pagenav .prev-page"),n=a(".variations-pagenav .next-page"),r=a(".variations-pagenav .last-page");1===e?(o.addClass("disabled"),t.addClass("disabled")):(o.removeClass("disabled"),t.removeClass("disabled")),i===e?(n.addClass("disabled"),r.addClass("disabled")):(n.removeClass("disabled"),r.removeClass("disabled"))},set_page:function(e){a(".variations-pagenav .page-selector").val(e).first().trigger("change")},go_to_page:function(a,e){a=a||1,e=e||0,t.set_paginav(e),t.set_page(a)},page_selector:function(){var e=parseInt(a(this).val(),10),i=a("#variable_product_options").find(".woocommerce_variations");a(".variations-pagenav .page-selector").val(e),o.check_for_changes(),t.change_classes(e,parseInt(i.attr("data-total_pages"),10)),o.load_variations(e).then(o.show_hide_variation_empty_state())},first_page:function(){return t.check_is_enabled(this)&&t.set_page(1),!1},prev_page:function(){if(t.check_is_enabled(this)){var e=a("#variable_product_options").find(".woocommerce_variations"),i=parseInt(e.attr("data-page"),10)-1,o=0<i?i:1;t.set_page(o)}return!1},next_page:function(){if(t.check_is_enabled(this)){var e=a("#variable_product_options").find(".woocommerce_variations"),i=parseInt(e.attr("data-total_pages"),10),o=parseInt(e.attr("data-page"),10)+1,n=i>=o?o:i;t.set_page(n)}return!1},last_page:function(){if(t.check_is_enabled(this)){var e=a("#variable_product_options").find(".woocommerce_variations").attr("data-total_pages");t.set_page(e)}return!1}};e.init(),i.init(),o.init(),t.init()});