import o from"jquery";import"./datatables-bbQliV7G.js";import{T as f}from"./bootstrap.esm-Bb7dPm-H.js";import{d as p}from"./datatables-CdFC5o1t.js";import{s as r}from"./toastr-helper-Wdj0mZjX.js";/* empty css                                  */function b(){[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(e=>new f(e,{boundary:document.body}))}function g(){o(document).on("click",".delete-datacenter",async function(){const n=o(this).data("id"),e=window.routes.datacenters.delete.replace(":id",n);await window.showConfirm(window.translations.datacenters.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("#datacentersTable").dataset.recordsUrl;l=o("#datacentersTable").DataTable({...p.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:"code",name:"code",render:function(e){return`<code>${e}</code>`}},{data:"city",name:"city",render:function(e){return e||"-"}},{data:"racks_count",name:"racks_count",render:function(e){return`<span class="badge bg-info">${e}</span>`}},{data:"servers_count",name:"servers_count",render:function(e){return`<span class="badge bg-secondary">${e}</span>`}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,u,t){var i,s,d,c;const a=[];if((i=window.permissions.datacenters)!=null&&i.update){const m=window.routes.datacenters.edit.replace(":id",e);a.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="${((s=window.translations.buttons)==null?void 0:s.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(d=window.permissions.datacenters)!=null&&d.delete&&a.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-datacenter"
                                    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>`),a.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${a.join("")}</div>`}}],drawCallback:function(){b()}}),g()});
