(()=>{"use strict";const r=(t,e)=>{const a=wp.i18n["__"];var{data:t={}}=t||{},{message:t=e||a("Something Went Wrong!","tutor")}=t;return t};jQuery(document).ready(function(c){wp.i18n.__;c(document).on("click",".btn-csv-download",function(t){t.preventDefault();var e=c(this);c.ajax({url:ajaxurl,type:"POST",data:{quiz_id:c(this).data("id"),action:"quiz_export_data"},beforeSend:function(){e.addClass("is-loading")},success:function(t){var e,a,n;t.success?(e="data:text/csv;charset=utf-8,",t.data.output_quiz_data.forEach(function(t){t=t.join(",");e+=t+"\r\n"}),a=encodeURI(e),(n=document.createElement("a")).setAttribute("href",a),n.setAttribute("download","tutor-quiz-"+t.data.title+".csv"),document.body.appendChild(n),n.click()):tutor_toast("Error!",r(t),"error")},complete:function(){e.removeClass("is-loading")}})}),c(document).on("change",'#tutor-course-content-builder-root input[name="csv_file"]',function(t){var e,a,n=c(this).prop("files"),o=c(this),i=c(this).parent().find("button");n[0]?0<n[0].size?(e=tutor_get_nonce_data(!0),(a=new FormData).append("action","quiz_import_data"),a.append("csv_file",n[0]),a.append("topic_id",c(this).parent().find("input[name='csv_file']").data("topic")),a.append(e.key,e.value),c.ajax({url:ajaxurl,type:"POST",data:a,cache:!1,contentType:!1,processData:!1,beforeSend:function(){i.addClass("is-loading")},success:function(t){t.success?(o.val(""),o.closest(".tutor-topics-wrap").find(".tutor-lessons").append(t.data.html)):tutor_toast("Error",r(t),"error")},complete:function(){i.removeClass("is-loading")}})):alert("File is Empty."):alert("No File Selected."),c(this).val("")}),c(document).on("click",".tutor-import-quiz-button button",function(t){t.preventDefault(),c(this).parent().find(".tutor-csv-file").click()})})})();