import{d as g}from"./datatables-I6jthWPb.js";import{r as p,g as b}from"./api-DZ3cXm1m.js";import{i as h}from"./tooltip-manager-D9RaGGY4.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){var d;const o=document.getElementById("tagsTable");if(!o)return;const m=o.getAttribute("data-records-url"),a=window.tagsConfig||{permissions:{},translations:{}},n=e=>String(e??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),i=$("#tagsTable").DataTable({...g.getDefaultConfig(),serverSide:!0,searching:!0,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>>',ajax:{url:m,type:"GET",beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${b()}`)},error:async function(e){e.status===401&&await p()&&i.ajax.reload()}},order:[[2,"asc"]],columns:[{data:"id",name:"id",width:"60px"},{data:null,name:"name",render:e=>{const t=e.icon?`<i class="fas ${n(e.icon)} me-1"></i>`:"";return`<span class="badge" style="background-color: ${n(e.color)}">${t}${n(e.name)}</span>`}},{data:"slug",name:"slug",render:e=>`<code>${n(e)}</code>`},{data:"color",name:"color"},{data:"posts_count",name:"posts_count"},{data:null,name:"actions",orderable:!1,searchable:!1,className:"text-end",render:e=>{const t=[];return a.permissions.update&&t.push(`<a href="${n(e.edit_url)}" 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="${n(a.translations.edit||"Edit")}"><i class="fas fa-edit"></i></a>`),a.permissions.delete&&t.push(`<button type="button" class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 tag-delete" style="width: 32px; height: 32px;" data-id="${e.id}" data-url="${n(e.delete_url)}" data-bs-toggle="tooltip" title="${n(a.translations.delete||"Delete")}"><i class="fas fa-trash"></i></button>`),t.length?`<div class="d-inline-flex">${t.join("")}</div>`:'<span class="text-muted">-</span>'}}],drawCallback:function(){h()}});let l;(d=document.getElementById("tagsTableSearch"))==null||d.addEventListener("input",e=>{clearTimeout(l),l=setTimeout(()=>i.search(e.target.value).draw(),300)}),document.body.addEventListener("click",async function(e){var c;const t=e.target.closest(".tag-delete");if(!t||!window.confirm(a.translations.confirm_delete||"Are you sure?"))return;const f=t.getAttribute("data-url");try{const s=(c=document.querySelector('meta[name="csrf-token"]'))==null?void 0:c.getAttribute("content"),r=new FormData;r.append("_method","DELETE"),s&&r.append("_token",s);const u=await fetch(f,{method:"POST",headers:{Accept:"application/json","X-CSRF-TOKEN":s||""},body:r,credentials:"same-origin"});(u.ok||u.redirected)&&i.ajax.reload(null,!1)}catch(s){console.error("Tag delete error:",s)}})});
