import{d as g}from"./datatables-I6jthWPb.js";import{r as h,g as b}from"./api-DZ3cXm1m.js";import{c as _,g as y}from"./datatable-filters-CecjJm_7.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */import"./vendor-zLyX4B24.js";import"./tr-CHCA6xOE.js";const a=window.translations||{},s=window.routes||{},c=_(null,{search:!0,searchPlaceholder:a.search_placeholder||"Search..."}),l=$("#clientGroupsTable").DataTable({...g.getDefaultConfig(),serverSide:!0,dom:y(),ajax:{url:$("#clientGroupsTable").data("records-url"),type:"POST",data:function(e){const r=c.getValues();e.search={value:r.search||""}},beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${b()}`)},error:async function(e){e.status===401&&await h()&&l.ajax.reload()}},columns:[{data:"id",name:"id",width:"60px"},{data:"group_name",name:"group_name",render:function(e,r,t){return t.text_color?`<span style="color: ${t.text_color}">${e}</span>`:e}},{data:"text_color",name:"text_color",width:"80px",orderable:!1,render:function(e){return e?`<span class="badge" style="background-color: ${e}; color: #fff;">${e}</span>`:"-"}},{data:"clients_count",name:"clients_count",width:"100px",render:function(e){return`<span class="badge bg-info">${e}</span>`}},{data:"created_at",name:"created_at",width:"150px"},{data:null,orderable:!1,searchable:!1,width:"120px",render:function(e,r,t){var d,u,p,f,m,w;const o=s.clientGroups_show.replace(":id",t.id),i=s.clientGroups_edit.replace(":id",t.id);let n="";return(u=(d=window.permissions)==null?void 0:d.clientGroups)!=null&&u.view&&(n+=`<a href="${o}" class="btn btn-outline-primary" title="${a.clientGroups_button_show}"><i class="fas fa-eye"></i></a>`),(f=(p=window.permissions)==null?void 0:p.clientGroups)!=null&&f.update&&(n+=`<a href="${i}" class="btn btn-outline-secondary" title="${a.clientGroups_button_edit}"><i class="fas fa-edit"></i></a>`),(w=(m=window.permissions)==null?void 0:m.clientGroups)!=null&&w.delete&&(n+=`<button type="button" class="btn btn-outline-danger delete-item" data-id="${t.id}" title="${a.clientGroups_button_delete}"><i class="fas fa-trash"></i></button>`),`<div class="btn-group btn-group-sm" role="group">${n}</div>`}}],order:[[0,"desc"]],initComplete:function(){c.init()}});c.setDataTable(l);$(document).on("click",".delete-item",async function(){const e=$(this).data("id");if(await window.showConfirm(a.clientGroups_confirm_delete,{title:"Onay",confirmText:"Onayla",confirmClass:"btn-danger"}))try{const t=s.clientGroups_destroy.replace(":id",e),o=await fetch(t,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${b()}`}});if(o.status===401&&await h())return $(this).trigger("click");const i=await o.json();o.ok?(l.ajax.reload(),window.showSuccess(i.message||"Group deleted successfully")):window.showError(i.message||"An error occurred")}catch(t){console.error("Error:",t),window.showError("An error occurred while deleting the group")}});
