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