import{d as c}from"./datatables-I6jthWPb.js";import{r as o,g as l}from"./api-DZ3cXm1m.js";import{i as f}from"./tooltip-manager-D9RaGGY4.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const s=document.getElementById("workflowsTable");if(!s)return;const d=s.getAttribute("data-records-url"),n=window.workflowsConfig,r=$("#workflowsTable").DataTable({...c.getDefaultConfig(),serverSide:!0,searching:!1,dom:'<"d-flex align-items-center mb-3"<"d-flex align-items-center"l>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',ajax:{url:d,type:"GET",beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${l()}`)},error:async function(e){e.status===401&&await o()&&r.ajax.reload()}},columns:[{data:"id"},{data:"name"},{data:"trigger_event"},{data:"is_active",render:e=>e?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'},{data:"execution_count"},{data:"last_executed_at"},{data:"id",orderable:!1,render:function(e){var i;const a=((i=window.permissions)==null?void 0:i.workflows)||{};let t=[];return a.update&&t.push(`<a href="${n.routes.edit.replace(":id",e)}" class="btn btn-sm btn-outline-primary" style="width:32px;height:32px;"><i class="fas fa-edit"></i></a>`),a.delete&&t.push(`<button class="btn btn-sm btn-outline-danger ms-1 delete-workflow" data-url="${n.routes.destroy.replace(":id",e)}" style="width:32px;height:32px;"><i class="fas fa-trash"></i></button>`),t.length?`<div class="d-inline-flex">${t.join("")}</div>`:"-"}}],drawCallback:function(){f()}});document.body.addEventListener("click",async function(e){const a=e.target.closest(".delete-workflow");if(!(!a||!confirm(n.translations.confirm_delete)))try{const t=await fetch(a.dataset.url,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l()}`}});if(t.status===401){await o()&&a.click();return}t.ok&&r.ajax.reload(null,!1)}catch(t){console.error(t)}})});
