(()=>{var e=wp.i18n,n=e.__,t=(e._x,e._n,e._nx,document.querySelector(".loading-spinner")),o=(document.addEventListener("readystatechange",function(e){"complete"===e.target.readyState&&(t&&t.remove(),"undefined"!=typeof tinymce)&&tinymce.activeEditor&&tinymce.activeEditor.on("change",function(e){var t,e=document.querySelector(".email-manage-page [data-source=".concat(e.target.id,"]"));e&&((t=tinymce.activeEditor.getContent()).replace("/<[/]{0,1}div[^>]*>/i",""),e.innerHTML=t),tinymce.triggerSave()})}),document.getElementById("tutor-btn-test-mail")),r=document.querySelector(".template-preview"),c=document.querySelector(".email_template_title"),a=(o&&(o.onclick=function(e){e.preventDefault();var a=new FormData;r&&a.append("email_template",r.dataset.email_template),a.append("action","send_test_email_ajax"),a.append("email_to",document.getElementsByName("to")[0].value),a.append("email_key",document.getElementsByName("key")[0].value),a.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce),o.classList.add("is-loading"),o.disabled=!0,d().then(function(){var t=new XMLHttpRequest;t.open("POST",_tutorobject.ajaxurl,!0),t.send(a),t.onreadystatechange=function(e){4===t.readyState&&tutor_toast(n("Success","tutor"),n('A test email for "'.concat(c.innerText,'" has been sent to admin!'),"tutor"),"success")}}).catch(function(e){tutor_toast(n("Error","tutor"),n(e,"tutor"),"error")}).finally(function(){o.classList.remove("is-loading"),o.disabled=!1})}),document.querySelector("[action-tutor-email-template-save]")),i=document.querySelector("#tutor-email-template-form"),u=document.querySelector("#email_option_data");function d(){return new Promise(function(t,e){var a,n=i.elements,o=n["email-subject"],n=n["email-heading"];o.value&&n.value?((o=new FormData(i)).append(u.name,u.value),o.append("action","save_email_template"),o.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce),(a=new XMLHttpRequest).open("POST",_tutorobject.ajaxurl,!0),a.send(o),a.onreadystatechange=function(e){4===a.readyState&&t("success")}):(i.reportValidity(),e("Email subject and heading are required!"))})}a&&(a.onclick=function(e){a.classList.add("is-loading"),a.disabled=!0,e.detail&&1!=e.detail||(e.preventDefault(),d().then(function(){tutor_toast(n("Success","tutor"),n('"'.concat(c.innerText,'" email template updated!'),"tutor"),"success")}).catch(function(e){tutor_toast(n("Error","tutor"),n(e,"tutor"),"error")}).finally(function(){a.classList.remove("is-loading"),a.disabled=!1}))});e=document.querySelectorAll('.email-manage-page input[type="hidden"]:not(#email_option_data), .email-manage-page input[type="text"], .email-manage-page textarea');e&&e.forEach(function(e){var t=e.name,a=e.value;window.addEventListener("DOMContentLoaded",function(){var e=document.querySelector(".email-manage-page [data-source=".concat(t,"]"));void 0!==e&&e&&(e.src?e.src=a:e.innerHTML=a)}),e.addEventListener("input",function(e){var e=e.target,t=e.name,e=e.value,t=document.querySelector(".email-manage-page [data-source=".concat(t,"]"));void 0!==t&&t&&(t.src?t.src=e:t.innerHTML=e)})})})();