import{$ as a}from"./datatables-Bo82YvhT.js";import{T as p}from"./bootstrap.esm-Bb7dPm-H.js";import{d as f}from"./datatables-I6jthWPb.js";import{s as r}from"./toastr-helper-Wdj0mZjX.js";/* empty css                                  */function g(){[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(e=>new p(e,{boundary:document.body}))}function b(){a(document).on("click",".delete-server",async function(){const n=a(this).data("id"),e=window.routes.servers.delete.replace(":id",n);await window.showConfirm(window.translations.servers.delete_confirm,{confirmClass:"btn-danger",icon:"warning"})&&fetch(e,{method:"DELETE",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content"),"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"}}).then(t=>t.json()).then(t=>{t.success?(l.ajax.reload(),r("success",t.message)):r("danger",t.message||"An error occurred.")}).catch(t=>{console.error("Error:",t),r("danger","An error occurred.")})})}let l;document.addEventListener("DOMContentLoaded",function(){const n=document.querySelector("#serversTable").dataset.recordsUrl;l=a("#serversTable").DataTable({...f.getDefaultConfig(),serverSide:!0,ajax:{url:n,type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}},columns:[{data:"name",name:"name"},{data:"hostname",name:"hostname"},{data:"ip_address",name:"ip_address"},{data:"status",name:"status",render:function(e){return e==="active"?`<span class="badge bg-success">${window.translations.servers.status.active}</span>`:`<span class="badge bg-danger">${window.translations.servers.status.inactive}</span>`}},{data:"maximum_hosts",name:"maximum_hosts",render:function(e){return e||"-"}},{data:"stock",name:"stock",render:function(e){return e==null?'<span class="text-muted">∞</span>':e===0?`<span class="badge bg-danger">${e}</span>`:e<=1?`<span class="badge bg-warning text-dark">${e}</span>`:e}},{data:"current_hosts",name:"current_hosts"},{data:"groups_count",name:"groups_count",render:function(e){return`<span class="badge bg-info">${e}</span>`}},{data:"created_at",name:"created_at"},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,u,t){var o,i,d,c;const s=[];if((o=window.permissions.servers)!=null&&o.update){const m=window.routes.servers.edit.replace(":id",e);s.push(`
                            <a href="${m}"
                               class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center"
                               style="width: 32px; height: 32px;"
                               data-bs-toggle="tooltip"
                               title="${((i=window.translations.buttons)==null?void 0:i.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(d=window.permissions.servers)!=null&&d.delete&&s.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-server"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-bs-toggle="tooltip"
                                    title="${((c=window.translations.buttons)==null?void 0:c.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),s.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${s.join("")}</div>`}}],drawCallback:function(){g()}}),b()});
