(()=>{var t={};// The module cache
var e={};// The require function
function a(r){// Check if module is in cache
var o=e[r];if(o!==undefined){return o.exports}// Create a new module (and put it into the cache)
var i=e[r]={exports:{}};// Execute the module function
t[r](i,i.exports,a);// Return the exports of the module
return i.exports}// webpack/runtime/rspack_version
(()=>{a.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{a.ruid="bundler=rspack@1.6.5"})();window.jQuery(document).ready(function(t){var e=function t(t,e){t.prop("disabled",!e);!e?t.addClass("is-loading"):t.removeClass("is-loading")};/* Credential Upload Manager */var a=function a(){this.upload_area=t("#tutor_gc_dashboard .tutor-upload-area");this.input_field=this.upload_area.find('[type="file"]');this.load_button=t("#tutor_gc_credential_upload>button");this.uploaded_file=null;this.is_file_valid=null;this.init=function(){this.on_click();this.on_change();this.on_drop();this.on_save()};this.load_file=function(t){if(t&&t[0]){var e=t[0];this.is_file_valid=this.is_valid_file(e);this.load_button.prop("disabled",!this.is_file_valid);if(this.is_file_valid){this.uploaded_file=e;this.upload_area.find("span.file_name").remove();this.upload_area.append('<span class="file_name">'+this.uploaded_file.name+"</span>")}else{alert("Invalid File.")}}};this.is_valid_file=function(t){var e=t.type||"";e=e.toLowerCase();var a=e=="application/json";return a};this.on_click=function(){var t=this;this.upload_area.find("button").click(function(e){e.preventDefault();t.input_field.trigger("click")})};this.on_change=function(){var e=this;this.input_field.change(function(a){e.load_file(a.currentTarget.files);t(this).val("")})};this.on_drop=function(){var e=this;// Process drag and drop file
this.upload_area.on("drag dragstart dragend dragover dragenter dragleave drop",function(t){t.preventDefault();t.stopPropagation()}).on("dragover dragenter",function(){t(this).addClass("dragover")}).on("dragleave dragend drop",function(){t(this).removeClass("dragover")}).on("drop",function(t){e.load_file(t.originalEvent.dataTransfer.files)})};this.on_save=function(){var a=this;this.load_button.click(function(){if(!a.is_file_valid){// Make sure file is selected and valid
return}var r=t(this);var o=new FormData;o.append("credential",a.uploaded_file,a.uploaded_file.name);o.append("action","tutor_gc_credential_save");// Append nonce to the object manually, ajaxSetup doen't as it is formadata
var i=tutor_get_nonce_data(true);o.append(i.key,i.value);e(r,false);t.ajax({url:window._tutorobject.ajaxurl,type:"POST",processData:false,contentType:false,data:o,success:function t(){window.location.reload()},error:function t(){e(r,true);alert("Request Failed.")}})})}};new a().init();/* ---------Credential JSON Upload manager--------- */var r=t("#tutor_gc_dashboard .google-classroom-class-list");/* -----------------Google class actions like import, delete, publish etc.----------------- */var o="no";var i=[];var n=function e(e){var a=t("#tutor_gc_bulk_action_button").data("process_running")==true;!e?i=[]:0;t("#tutor_gc_bulk_action_button").text(e?"Abort":"Apply").data("process_running",e);return a};var s=function e(e){var{__}=window.wp.i18n;var a;var r={title:__("Do you want to import students from this Classroom?","tutor-pro"),description:__("This is not recommended for paid courses as importing will skip the payment procedure.","tutor-pro"),buttons:{cancel:{title:__("Cancel","tutor-pro"),id:"cancel",class:"tutor-btn tutor-btn-outline-primary",callback:function e(){a.remove();t("body").removeClass("tutor-modal-open")}},reset:{title:__("Yes, Import Student","tutor-pro"),id:"reset",class:"tutor-btn tutor-btn-primary tutor-ml-20",callback:function r(){a.remove();t("body").removeClass("tutor-modal-open");o="import";e()}}}};a=new window.tutor_popup(t,"import-icon").popup(r)};var l=function e(e){var{__}=window.wp.i18n;var a;var r={title:__("Do you want to remove this course from the system?","tutor-pro"),description:__("This will not delete it from Google Classroom, it will only remove the connection.","tutor-pro"),buttons:{cancel:{title:__("Cancel","tutor-pro"),id:"cancel",class:"tutor-btn tutor-btn-outline-primary",callback:function e(){a.remove();t("body").removeClass("tutor-modal-open")}},reset:{title:__("Yes, Delete Course","tutor-pro"),id:"reset",class:"tutor-btn tutor-btn-primary tutor-ml-20",callback:function r(){a.remove();t("body").removeClass("tutor-modal-open");e()}}}};a=new window.tutor_popup(t,"icon-trash").popup(r)};r.find("[data-action]").not("a").click(function(a){var r=t(this);var c="primary";var u=r.data("classroom_id");var d=r.data("class_post_id");var _=r.data("action");var p=function t(t){alert("Something Went Wrong!");e(r,true)};function f(){e(r,false);t.ajax({url:window._tutorobject.ajaxurl,data:{class_id:u,action:"tutor_gc_class_action",action_name:_,post_id:d,enroll_student:o},type:"POST",success:function t(t){try{t=JSON.parse(t)}catch(t){}// Show error message if invalid response
if(typeof t!=="object"){p();return}switch(t.class_status){case"publish":c="success";break;case"draft":c="warning";break;case"trash":c="danger";break;default:c="primary";break}// Change row state
var a=r.parent().attr("class","class-status-"+t.class_status);t.edit_link?a.find(".class-edit-link").attr("href",t.edit_link):0;t.preview_link?a.find(".class-preview-link").attr("href",t.preview_link):0;t.post_id?a.find("[data-action]").attr("data-class_post_id",t.post_id):0;a.parent().find("[data-gc-status]").attr("class","tutor-badge-label label-"+c).text(t.status_text);e(r,true);if(i.length>0){var o=i.shift();o.trigger("click")}else{n(false)}},error:p})}if(_=="delete"&&a.originalEvent){l(f);return}else if(_!=="import"||!a.originalEvent){f()}else{s(f)}});/* -------------Save who can see classroom code------------- */t("#tutor_gc_classroom_code_privilege").change(function(){var e=t(this).prop("checked")?"yes":"no";t.ajax({url:window._tutorobject.ajaxurl,data:{action:"tutor_gc_classroom_code_privilege",enabled:e},type:"POST",error:function t(){alert("Action Failed.")}})});/* -------------------Execute bulk action------------------- */t("#tutor_gc_bulk_action_button").click(function(){// Abort if previous process is running
if(n(false)==true){return}var e=t(this).prev().val();var a=[];t(".google-classroom-class-list .tutor-bulk-checkbox:checked").each(function(){var r=t(this).closest("tr").find('[data-action="'+e+'"]:visible');r.length>0?a.push(r.eq(0)):0});if(!a.length){alert("Please select the correct option to take an action.");return}function r(){i=a.slice(1);n(true);a[0].trigger("click")}if(e=="import"){s(r)}else if(e=="delete"){l(r)}else{r()}});/* Search Google Class */t("#tutor_gc_dashboard").on("input","#tutor-gc-search-class",function(){var e=t(".google-classroom-class-list>tbody");var a=t(this).val()||"";a=a.trim();if(a==""){e.children().show();return}e.children().each(function(){var e=t(this).children();var r=e.filter(".tutor-gc-title").text().toLowerCase().trim();var o=e.filter(".tutor-gc-code").text().toLowerCase().trim();var i=r.indexOf(a.toLowerCase())>-1||o==a;t(this)[i?"show":"hide"]()})});/* Credential upgrade */var c=function t(){window.location.reload()};t("#tutor_gc_credential_upgrade").click(function(a){a.preventDefault();var r=t(this).data("message");if(r&&!confirm(r)){// Take confirmation if prompt message defined
return}e(t(this),false);t.ajax({url:window._tutorobject.ajaxurl,data:{action:"tutor_gc_credential_upgrade"},type:"POST",success:c,error:c})})})})();