import{$ as a}from"./datatables-Bo82YvhT.js";import{r as c,g as o}from"./api-DZ3cXm1m.js";a(function(){const t=window.pageConfig;if(!t)return;const r=a("#customReportsTable").DataTable({processing:!0,serverSide:!0,ajax:{url:t.routes.records,beforeSend:e=>e.setRequestHeader("Authorization",`Bearer ${o()}`),error:async function(e){e.status===401&&await c()&&r.ajax.reload()},data:e=>{e.scope=a("select[name=scope]").val()||"all"}},columns:[{data:"name"},{data:"owner"},{data:"is_public",render:e=>e?'<span class="badge bg-success">public</span>':'<span class="badge bg-secondary">private</span>'},{data:"last_executed_at",render:e=>e||"—"},{data:"updated_at"},{data:"id",orderable:!1,render:function(e,i,s){let n=`<a href="${t.routes.show.replace(":id",e)}" class="btn btn-sm btn-outline-info"><i class="fas fa-eye"></i></a> `;return(s.is_owner||t.permissions.manage)&&(n+=`<a href="${t.routes.edit.replace(":id",e)}" class="btn btn-sm btn-outline-primary"><i class="fas fa-edit"></i></a> `),t.permissions.export&&(n+=`<a href="${t.routes.export.replace(":id",e)}" class="btn btn-sm btn-outline-success"><i class="fas fa-file-csv"></i></a> `),(s.is_owner||t.permissions.manage)&&(n+=`<button class="btn btn-sm btn-outline-danger js-delete" data-id="${e}"><i class="fas fa-trash"></i></button>`),n}}],dom:'<"d-flex justify-content-between align-items-center mb-3"<"d-flex align-items-center"l><"d-flex align-items-center"f>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>'});a("select[name=scope]").on("change",()=>r.ajax.reload()),a(document).on("click",".js-delete",async function(){var s;if(!confirm(t.translations.confirm_delete))return;const e=a(this).data("id"),i=((s=document.querySelector("meta[name=csrf-token]"))==null?void 0:s.content)||"";await fetch(t.routes.delete.replace(":id",e),{method:"DELETE",headers:{Authorization:`Bearer ${o()}`,"X-CSRF-TOKEN":i,Accept:"application/json"}}),r.ajax.reload()})});
