(function(e){e.fn.synchronous_request=function(s){var r=e.extend({url:"",number_requests:0,offset:0,action:"",nonce:"",ids:"",wait:5e3,stop_on_error:0,progress_count:"#progress-number",log:"#log",cancel_button:".cancel",type:"post",cache:false,dataType:"json",onRequestSuccess:function(s,r){this.maybeResetLog();if(s.success){e("ul",e(this.log)).append('<li class="success">'+(r+1)+"/"+this.number_requests+": "+s.data+"</li>")}else{var t=r+1+"/"+this.number_requests+": Response Error: "+s.data;switch(this.stop_on_error){case 1:break;case 0:t=t+". Waiting "+this.stop_on_error_pause/1e3+" seconds before reattempting this request.";break;case-1:t=t+". Waiting "+this.stop_on_error_pause/1e3+" seconds before attempting next request.";break}e("ul",e(this.log)).append('<li class="error">'+t+"</li>")}if(this.cancelled==true){return false}return true},onRequestError:function(s,r,t,n){if(e("#log ul li").length>=100){e("#log ul").html("")}e("#log ul").append('<li class="error">'+(n+1)+"/"+ckwc_sync_past_orders.number_requests+": Request Error: "+s.status+" "+s.statusText+"</li>");if(this.cancelled==true){return false}return true},updateSettings:function(e){return e},onFinished:function(){if(this.cancelled){e("ul",e(this.log)).append('<li class="success">Process cancelled by user.</li>')}else{e("ul",e(this.log)).append('<li class="success">Finished.</li>');e(r.cancel_button).attr("disabled","disabled")}},maybeResetLog:function(){if(e("ul li",e(this.log)).length>=100){e("ul",e(this.log)).html("")}}},s);progressbar=e(this).progressbar({value:0});if(r.cancel_button){e(r.cancel_button).on("click",function(s){s.preventDefault();r.cancelled=true;e(r.cancel_button).attr("disabled","disabled")})}synchronousAjaxRequest(r,-1+Number(r.offset),progressbar,r.progress_count)};function synchronousAjaxRequest(s,r,t,n){r++;if(r>Number(s.offset)+Number(s.number_requests)-1){s.onFinished();return true}var o={action:s.action,nonce:s.nonce,id:s.ids[r],current_index:r,number_requests:s.number_requests};var u={...o,...s.data};e.ajax({url:s.url,type:s.type,async:true,cache:s.cache,dataType:s.dataType,data:u,success:function(o){var u=s.onRequestSuccess(o,r);if(o.success){t.progressbar("value",Number((r+1)/s.number_requests*100));e(n).text(r+1)}else{if(s.stop_on_error==1){s.onFinished();return}if(s.stop_on_error==-1){t.progressbar("value",Number((r+1)/s.number_requests*100));e(n).text(r+1)}if(s.stop_on_error==0){r--}}if(!u){s.onFinished();return}if(!o.success&&s.stop_on_error!==-1){setTimeout(function(){synchronousAjaxRequest(s,r,t,n);return},s.wait)}else{s=s.updateSettings(s);synchronousAjaxRequest(s,r,t,n);return}},error:function(e,o,u){var i=s.onRequestError(e,o,u,r);if(s.stop_on_error==1){s.onFinished();return}if(s.stop_on_error==0){r--}if(!i){s.onFinished();return}setTimeout(function(){synchronousAjaxRequest(s,r,t,n);return},s.wait)}})}})(jQuery);