import{d as y}from"./datatables-I6jthWPb.js";import{r as x,g as k}from"./api-DZ3cXm1m.js";import{i as w}from"./tooltip-manager-D9RaGGY4.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){var c,u,m,f;const o=document.getElementById("knowledgebaseTable");if(!o)return;const p=o.getAttribute("data-records-url"),s=window.knowledgebaseConfig||{permissions:{},translations:{}},h={draft:"bg-secondary",published:"bg-success",archived:"bg-warning"},n=e=>String(e??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),i=$("#knowledgebaseTable").DataTable({...y.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:p,type:"GET",data:function(e){var t,a;e.status=((t=document.getElementById("kbStatusFilter"))==null?void 0:t.value)||"",e.tag_slug=((a=document.getElementById("kbTagFilter"))==null?void 0:a.value)||""},beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${k()}`)},error:async function(e){e.status===401&&await x()&&i.ajax.reload()}},order:[[6,"desc"]],columns:[{data:"id",name:"id",width:"60px"},{data:"title",name:"title",render:e=>n(e)},{data:null,name:"helpful",orderable:!1,render:e=>{const t=Number(e.helpful_count??0),a=Number(e.not_helpful_count??0);return`<i class="fas fa-thumbs-up text-success"></i> ${t}<i class="fas fa-thumbs-down text-danger ms-2"></i> ${a}`}},{data:"status",name:"status",render:e=>{const t=h[e]||"bg-secondary",a=s.translations["status_"+e]||e;return`<span class="badge ${t}">${n(a)}</span>`}},{data:"view_count",name:"view_count"},{data:"tags",name:"tags",orderable:!1,render:e=>!Array.isArray(e)||e.length===0?'<span class="text-muted">-</span>':e.map(t=>{const a=t.icon?`<i class="fas ${n(t.icon)} me-1"></i>`:"";return`<span class="badge me-1" style="background-color: ${n(t.color)}">${a}${n(t.name)}</span>`}).join("")},{data:"published_at",name:"published_at",defaultContent:"-"},{data:null,name:"actions",orderable:!1,searchable:!1,className:"text-end",render:e=>{const t=[];return e.public_url&&t.push(`<a href="${n(e.public_url)}" target="_blank" rel="noopener" class="btn btn-sm btn-outline-secondary d-inline-flex align-items-center justify-content-center" style="width: 32px; height: 32px;" data-bs-toggle="tooltip" title="${n(s.translations.view_on_site||"View")}"><i class="fas fa-external-link-alt"></i></a>`),s.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 ms-1" style="width: 32px; height: 32px;" data-bs-toggle="tooltip" title="${n(s.translations.edit||"Edit")}"><i class="fas fa-edit"></i></a>`),s.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 kb-delete" style="width: 32px; height: 32px;" data-id="${e.id}" data-url="${n(e.delete_url)}" data-bs-toggle="tooltip" title="${n(s.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(){w()}});(c=document.getElementById("kbStatusFilter"))==null||c.addEventListener("change",()=>i.ajax.reload()),(u=document.getElementById("kbTagFilter"))==null||u.addEventListener("change",()=>i.ajax.reload()),(m=document.getElementById("knowledgebaseTableToggleFilters"))==null||m.addEventListener("click",()=>{const e=document.getElementById("knowledgebaseTableFilters");e&&(e.style.display=e.style.display==="none"?"":"none")});let d;(f=document.getElementById("knowledgebaseTableSearch"))==null||f.addEventListener("input",e=>{clearTimeout(d),d=setTimeout(()=>i.search(e.target.value).draw(),300)}),document.body.addEventListener("click",async function(e){var g;const t=e.target.closest(".kb-delete");if(!t||!window.confirm(s.translations.confirm_delete||"Are you sure?"))return;const a=t.getAttribute("data-url");try{const l=(g=document.querySelector('meta[name="csrf-token"]'))==null?void 0:g.getAttribute("content"),r=new FormData;r.append("_method","DELETE"),l&&r.append("_token",l);const b=await fetch(a,{method:"POST",headers:{Accept:"application/json","X-CSRF-TOKEN":l||""},body:r,credentials:"same-origin"});(b.ok||b.redirected)&&i.ajax.reload(null,!1)}catch(l){console.error("KB delete error:",l)}})});
