import{g as p,r as h}from"./api-DZ3cXm1m.js";const t=window.emailSettingsConfig||{};function u(){var o;const s=document.getElementById("mailProviderSelect"),e=document.getElementById("mailProviderEditLink");if(!s||!e||!((o=t.routes)!=null&&o.moduleEdit))return;const n=s.options[s.selectedIndex],i=n==null?void 0:n.dataset.moduleId;i&&(e.href=t.routes.moduleEdit.replace(":id",i))}document.addEventListener("DOMContentLoaded",function(){const s=document.getElementById("mailProviderSelect");s&&(s.addEventListener("change",u),u());const e=document.getElementById("sendTestEmailBtn");e&&e.addEventListener("click",async function(){var o,a,l,c,m,w,f;const n=document.getElementById("testEmailAddress"),i=(o=n==null?void 0:n.value)==null?void 0:o.trim();if(!i){window.showAlert&&window.showAlert("error",((a=t.translations)==null?void 0:a.error)||"Error");return}e.disabled=!0,e.innerHTML='<i class="fas fa-spinner fa-spin me-1"></i>'+(((l=t.translations)==null?void 0:l.testSending)||"Sending...");try{const r=await fetch(t.routes.sendTest,{method:"POST",headers:{Authorization:`Bearer ${p()}`,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({email:i})});if(r.status===401&&await h()){e.click();return}const d=await r.json();d.success?window.showAlert&&window.showAlert("success",d.message||((c=t.translations)==null?void 0:c.testSuccess)||"Test email sent!"):window.showAlert&&window.showAlert("error",d.error||((m=t.translations)==null?void 0:m.testFailed)||"Failed to send test email.")}catch{window.showAlert&&window.showAlert("error",((w=t.translations)==null?void 0:w.testError)||"An error occurred.")}finally{e.disabled=!1,e.innerHTML='<i class="fas fa-paper-plane me-1"></i>'+(((f=t.translations)==null?void 0:f.sendTest)||"Send Test")}})});
