(()=>{"use strict";let e={},t={};function n(n,s=!0,o=!1,i="default"){const c=document.getElementById("notice-container");for(;c.firstChild;)c.removeChild(c.firstChild);e[i]?e[i]++:e[i]=1,t[i]&&clearTimeout(t[i]);const r=document.createElement("div");r.className=`notice ${s?"notice-success":"notice-error"} is-dismissible`;let a="";o&&(a='<a href="#" onclick="location.reload(); return false;" style="margin-left: 10px; text-decoration: underline;">Refresh</a>'),r.innerHTML=`<p>${n} (${e[i]})${a}</p>`,c.appendChild(r),t[i]=setTimeout((()=>{e[i]=0}),3e4),setTimeout((()=>{r.parentNode&&r.parentNode.removeChild(r)}),3e4)}var s;s=function(){if(document.getElementById("rtm-mail-smtp-settings")){const e=document.querySelector("#rtm-mail input[type=radio][name=smtp_provider]:checked");e&&(document.getElementById(`${e.value}-smtp-settings`).style.display="block")}document.getElementById("rtm-mail-smtp-settings").addEventListener("submit",(function(e){e.preventDefault();let t=new FormData(this);t.append("action","savesmtp_settings"),t.append("_wpnonce",e.target.elements._wpnonce.value),function({action:e,formData:t,submitButtonId:s,modalToHide:o,successMessage:i,errorMessagePrefix:c,onSuccess:r,onError:a}){const d=document.getElementById(s);d.disabled=!0,fetch(ajaxurl,{method:"POST",credentials:"same-origin",body:t}).then((e=>e.ok?e.json():Promise.reject(""))).then((t=>{if(!t.success)throw new Error(t.message||"Unknown error occurred.");n(i,!0,!0,e),r&&"function"==typeof r&&r(t)})).catch((t=>{a&&"function"==typeof a?a(t):n(c+t.toString(),!1,!0,e)})).finally((()=>{d.disabled=!1,o&&(document.getElementById(o).style.display="none")}))}({action:"savesmtp_settings",formData:t,submitButtonId:"save-settings",modalToHide:"",successMessage:"SMTP settings saved successfully.",errorMessagePrefix:"Error saving SMTP settings: ",onSuccess:function(e){}})}));const e=document.querySelectorAll("#rtm-mail input[type=radio][name=smtp_provider]");e.length>0&&e.forEach((e=>{e.addEventListener("change",(function(){document.querySelectorAll(".smtp__settings-container").forEach((e=>{e.style.display="none"})),document.getElementById(`${this.value}-smtp-settings`).style.display="block"}))}));const t=document.getElementById("enable__smtp");t&&t.addEventListener("change",(function(){const e=document.querySelectorAll(".smtp__option");this.checked?e.forEach((e=>{e.style.opacity="1.0",e.style.pointerEvents="auto"})):e.forEach((e=>{e.style.opacity="0.4",e.style.pointerEvents="none"}))}))},"loading"!==document.readyState?s():document.addEventListener("DOMContentLoaded",s)})();