document.addEventListener("DOMContentLoaded",function(){const i=document.getElementById("mxForm"),r=document.getElementById("mxResult"),n=document.getElementById("mxOutput");i&&i.addEventListener("submit",function(t){t.preventDefault(),c()});function c(){const t=document.getElementById("mx_domain").value.trim();if(!t){d("Domain name is required");return}l(),fetch("/api/v1/admin/network-tools/mx",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},body:JSON.stringify({domain:t})}).then(e=>e.json()).then(e=>{e.success?a(e.data):d(e.message||"MX query failed")}).catch(e=>{console.error("Error:",e),d("An error occurred: "+e.message)})}function a(t){if(n.replaceChildren(),t.records&&t.records.length>0)t.records.forEach(e=>{const o=document.createElement("div");o.className="mb-3 p-3 border rounded";const s=document.createElement("strong");s.textContent="MX Record:",o.appendChild(s),o.appendChild(document.createElement("br")),o.appendChild(document.createTextNode(String(e))),n.appendChild(o)});else{const e=document.createElement("div");e.className="alert alert-info",e.textContent="No MX records found for this domain.",n.appendChild(e)}r.style.display="block"}function l(){n.innerHTML='<div class="text-center"><i class="fas fa-spinner fa-spin fa-2x"></i><p class="mt-2">Querying MX records...</p></div>',r.style.display="block"}function d(t){n.innerHTML=`<div class="alert alert-danger">${t}</div>`,r.style.display="block"}});
