import{d as h}from"./datatables-I6jthWPb.js";import{r as x,g as T}from"./api-DZ3cXm1m.js";import{i as E}from"./tooltip-manager-D9RaGGY4.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){var d,u,m,f;const o=document.getElementById("announcementsTable");if(!o)return;const b=o.getAttribute("data-records-url"),s=window.announcementsConfig||{permissions:{},translations:{}},y={draft:"bg-secondary",published:"bg-success",archived:"bg-warning"},n=e=>String(e??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),i=$("#announcementsTable").DataTable({...h.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:b,type:"GET",data:function(e){var t,a;e.status=((t=document.getElementById("annStatusFilter"))==null?void 0:t.value)||"",e.tag_slug=((a=document.getElementById("annTagFilter"))==null?void 0:a.value)||""},beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${T()}`)},error:async function(e){e.status===401&&await x()&&i.ajax.reload()}},order:[[4,"desc"]],columns:[{data:"id",name:"id",width:"60px"},{data:"title",name:"title",render:e=>n(e)},{data:"subtype_badge",name:"subtype",orderable:!1,render:e=>{if(!e)return'<span class="text-muted">-</span>';const t=e.icon?`<i class="fas ${n(e.icon)} me-1"></i>`:"",a=s.translations["subtype_"+e.label_key]||e.label_key||"";return`<span class="badge bg-${n(e.color)}">${t}${n(a)}</span>`}},{data:"status",name:"status",render:e=>{const t=y[e]||"bg-secondary",a=s.translations["status_"+e]||e;return`<span class="badge ${t}">${n(a)}</span>`}},{data:"published_at",name:"published_at",defaultContent:"-"},{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: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 ann-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(){E()}});(d=document.getElementById("annStatusFilter"))==null||d.addEventListener("change",()=>i.ajax.reload()),(u=document.getElementById("annTagFilter"))==null||u.addEventListener("change",()=>i.ajax.reload()),(m=document.getElementById("announcementsTableToggleFilters"))==null||m.addEventListener("click",()=>{const e=document.getElementById("announcementsTableFilters");e&&(e.style.display=e.style.display==="none"?"":"none")});let c;(f=document.getElementById("announcementsTableSearch"))==null||f.addEventListener("input",e=>{clearTimeout(c),c=setTimeout(()=>i.search(e.target.value).draw(),300)}),document.body.addEventListener("click",async function(e){var p;const t=e.target.closest(".ann-delete");if(!t||!window.confirm(s.translations.confirm_delete||"Are you sure?"))return;const a=t.getAttribute("data-url");try{const l=(p=document.querySelector('meta[name="csrf-token"]'))==null?void 0:p.getAttribute("content"),r=new FormData;r.append("_method","DELETE"),l&&r.append("_token",l);const g=await fetch(a,{method:"POST",headers:{Accept:"application/json","X-CSRF-TOKEN":l||""},body:r,credentials:"same-origin"});(g.ok||g.redirected)&&i.ajax.reload(null,!1)}catch(l){console.error("Announcement delete error:",l)}})});
