document.addEventListener("DOMContentLoaded",function(){const o=document.getElementById("whoisForm"),n=document.getElementById("whoisResult"),s=document.getElementById("whoisOutput");o&&o.addEventListener("submit",function(t){t.preventDefault(),i()});function i(){const t=document.getElementById("whois_domain").value.trim();if(!t){r("Domain name is required");return}a(),fetch("/api/v1/admin/network-tools/whois",{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?d(e.data):r(e.message||"Whois query failed")}).catch(e=>{console.error("Error:",e),r("An error occurred: "+e.message)})}function d(t){if(s.innerHTML="",t.parsed){const e=`
                <div class="row">
                    <div class="col-md-6">
                        <h6>Domain Information</h6>
                        <table class="table table-sm">
                            <tr><td><strong>Domain:</strong></td><td>${t.domain}</td></tr>
                            <tr><td><strong>Registrar:</strong></td><td>${t.parsed.registrar||"N/A"}</td></tr>
                            <tr><td><strong>Creation Date:</strong></td><td>${t.parsed.creation_date||"N/A"}</td></tr>
                            <tr><td><strong>Expiry Date:</strong></td><td>${t.parsed.expiry_date||"N/A"}</td></tr>
                            <tr><td><strong>Status:</strong></td><td>${t.parsed.status||"N/A"}</td></tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <h6>Nameservers</h6>
                        <ul class="list-unstyled">
                            ${t.parsed.nameservers?t.parsed.nameservers.map(l=>`<li>• ${l}</li>`).join(""):"<li>N/A</li>"}
                        </ul>
                    </div>
                </div>
                <hr>
                <h6>Raw Whois Output</h6>
                <pre class=" p-3 rounded">${t.raw_output||"Raw output not found"}</pre>
            `;s.innerHTML=e}else s.innerHTML=`<pre class=" p-3 rounded">${t.raw_output||"Output not found"}</pre>`;n.style.display="block"}function a(){s.innerHTML='<div class="text-center"><i class="fas fa-spinner fa-spin fa-2x"></i><p class="mt-2">Querying...</p></div>',n.style.display="block"}function r(t){s.innerHTML=`<div class="alert alert-danger">${t}</div>`,n.style.display="block"}});
