jQuery(document).ready(function(t){t(document).on("click","#download_analytics",function(n){n.preventDefault();var e=t(this);e.hasClass("is-loading")||t.ajax({url:window._tutorobject.ajaxurl,type:"POST",data:{action:"export_analytics"},beforeSend:function(){e.addClass("is-loading")},success:function(n){if(n.success){var t,o,i,a,e=(n=n.data).students,c=n.earnings,s=n.discounts.length,n=n.refunds,r=new JSZip;e.length&&(t=Object.keys(e[0]),e=[t.join(","),e.map(function(e){return t.map(function(n){return e[n]}).join(",")}).join("\n")].join("\n"),e=new Blob([e]),r.file("students.csv",e)),c.length&&(o=Object.keys(c[0]),e=[o.join(","),c.map(function(e){return o.map(function(n){return e[n]}).join(",")}).join("\n")].join("\n"),c=new Blob([e]),r.file("earnings.csv",c)),s.length&&(i=Object.keys(s[0]),e=[i.join(","),s.map(function(e){return i.map(function(n){return e[n]}).join(",")}).join("\n")].join("\n"),c=new Blob([e]),r.file("discounts.csv",c)),n.length&&(a=Object.keys(n[0]),s=[a.join(","),n.map(function(e){return a.map(function(n){return e[n]}).join(",")}).join("\n")].join("\n"),e=new Blob([s]),r.file("refunds.csv",e));try{r.generateAsync({type:"blob"}).then(function(n){var n=new Blob([n],{type:"application/zip"}),e=document.createElement("a");document.body.appendChild(e),e.download="analytics-data.zip",e.href=URL.createObjectURL(n),e.click(),URL.revokeObjectURL(e.href)})}catch(n){alert(n)}}},complete:function(){e.removeClass("is-loading")}})})});