(()=>{"use strict";var a,e,t;a=jQuery,e={form:{beforeSubmit:function(e){var t=e.find('.pum-field-submit input[type="submit"]'),s=e.find(".pum-upgrade-messages"),r=e.find(".pum-batch-progress"),n=e.data("ays");return!(t.hasClass("button-disabled")||void 0!==n&&!confirm(n)||(r.removeClass("pum-batch-progress--active"),r.find("progress").prop("value",null),s.html(""),t.addClass("button-disabled"),a('<span class="spinner is-active"></span>').insertAfter(t),0))}},complete:function(e){var t=e.parents(".pum-alert");e.find(".pum-field-submit, progress").hide(),a("p.pum-upgrade-notice").hide(),t.removeClass("pum-alert__warning").addClass("pum-alert__success"),t.prepend("<h2>"+pum_batch_vars.complete+"</h2>")},action:"pum_process_batch_request",process_step:function(e,t){var s=this;a.ajax({type:"POST",url:ajaxurl,data:{batch_id:t.batch_id,action:s.action,nonce:t.nonce,form:t.form,step:parseInt(e),data:t},dataType:"json",success:function(e){if(e.data.done||e.data.error){var r=e.data.mapping?".pum-batch-import-form":".pum-batch-form",n=a(r),d=n.find(".spinner"),o=n.find(".notice-wrap");n.find(".button-disabled").removeClass("button-disabled"),e.data.error?(d.remove(),o.html('<div class="updated error"><p>'+e.data.error+"</p></div>")):e.data.done?(d.remove(),o.html('<div id="pum-batch-success" class="updated notice"><p class="pum-batch-success">'+e.data.message+"</p></div>"),e.data.url&&(window.location=e.data.url)):o.remove()}else a(".pum-batch-progress div").animate({width:e.data.percentage+"%"},50),s.process_step(e.data.step,t)}}).fail(function(a){window.console&&window.console.log&&console.log(a)})}},t=a.extend(!0,{},e,{action:"pum_process_upgrade_request",process_step:function(t,s){var r=this;a.ajax({type:"POST",url:ajaxurl,data:{upgrade_id:s.upgrade_id,action:r.action,nonce:s.nonce,form:s.form,step:parseInt(t),data:s},dataType:"json",success:function(t){var n=a(".pum-upgrade-form"),d=n.find(".spinner"),o=n.find(".button-disabled"),i=n.find(".pum-upgrade-messages");t.data.done||t.data.error?(o.removeClass("button-disabled"),t.data.error?(d.remove(),i.prepend('<div class="notice notice-error notice-alt"><p>'+t.data.error+"</p></div>")):t.data.done?(i.prepend('<div class="notice notice-success"><p><strong>'+t.data.message+"</strong></p></div>"),t.data.next?(n.data("upgrade_id",t.data.next).data("step",1).data("ays",!1),r.process_step(1,{upgrade_id:t.data.next,nonce:s.nonce,form:s.form})):(o.parent().hide(),d.remove(),e.complete(n)),t.data.url&&(window.location=t.data.url)):""!==t.data.message&&i.prepend('<div class="notice"><p class="">'+t.data.message+"</p></div>")):(""!==t.data.message&&i.prepend('<div class="notice"><p class="">'+t.data.message+"</p></div>"),a(".pum-batch-progress").addClass("pum-batch-progress--active"),a(".pum-batch-progress progress.pum-task-progress").addClass("active").val(t.data.percentage),r.process_step(t.data.step,s))}}).fail(function(a){window.console&&window.console.log&&console.log(a)})}}),window.PUM_Admin=window.PUM_Admin||{},window.PUM_Admin.batch=e,window.PUM_Admin.batch_upgrades=t,a(document).on("submit",".pum-batch-form[data-batch_id]",function(t){var s=a(this),r=s.find('input[type="submit"]'),n=s.data("ays"),d={batch_id:s.data("batch_id"),nonce:s.data("nonce"),form:s.serializeAssoc(),test:s.pumSerializeObject()};if(t.preventDefault(),!r.hasClass("button-disabled")){if(void 0!==n&&!confirm(n))return;s.find(".notice-wrap").remove(),s.append(a('<div class="notice-wrap"><div class="pum-batch-progress"><div></div>')),r.addClass("button-disabled"),r.parent().append('<span class="spinner is-active"></span>'),e.process_step(1,d)}}).on("submit",".pum-batch-form.pum-upgrade-form[data-upgrade_id]",function(e){var s=a(this),r={upgrade_id:s.data("upgrade_id"),nonce:s.data("nonce"),form:s.serializeAssoc(),test:s.pumSerializeObject()};e.preventDefault(),t.form.beforeSubmit(s)&&t.process_step(s.data("step")||1,r)}),jQuery(function(a){a.extend({arrayMerge:function(){for(var e={},t=0,s=a.arrayMerge.arguments,r=0;r<s.length;r++)if(Array.isArray(s[r])){for(var n=0;n<s[r].length;n++)e[t++]=s[r][n];e=a.makeArray(e)}else for(var d in s[r])if(s[r].hasOwnProperty(d))if(isNaN(d)){var o=s[r][d];"object"==typeof o&&e[d]&&(o=a.arrayMerge(e[d],o)),e[d]=o}else e[t++]=s[r][d];return e},count:function(a){return Array.isArray(a)?a.length:"object"==typeof a&&Object.keys(a).length}}),a.fn.extend({serializeAssoc:function(){for(var e={aa:{},add:function(e,t){var s=e.match(/^(.*)\[([^\]]*)]$/),r={};s?(s[2]?r[s[2]]=t:r[a.count(r)]=t,this.add(s[1],r)):"object"==typeof t?("object"!=typeof this.aa[e]&&(this.aa[e]={}),this.aa[e]=a.arrayMerge(this.aa[e],t)):this.aa[e]=t}},t=a(this).serializeArray(),s=0;s<t.length;s++)e.add(t[s].name,t[s].value);return e.aa}})})})();