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