Self-Heal Events Admin

function getCookie(n){for(var c=document.cookie.split(";"),i=0;i${e||"\u2014"}`}function evtTag(e){return`${e}`}function ctxCell(e){if(!e)return"\u2014";try{const t=typeof e=="string"?JSON.parse(e):e;return`
${JSON.stringify(t,null,1).slice(0,300)}
`}catch{return String(e).slice(0,200)}}async function loadData(){if(!token){showAuthGate();return}const e=document.getElementById("since-sel")?.value||"7d",t=document.getElementById("type-sel")?.value||"",o=new URLSearchParams({since:e,limit:300});t&&o.set("event_type",t);const s=document.getElementById("status");s.textContent="Loading\u2026";try{const i=await fetch(`${API}/admin/health-events?${o}`,{headers:{Authorization:`Bearer ${token}`}});if(i.status===401||i.status===403){showAuthGate();return}const a=await i.json();if(!a.success){s.textContent=a.message;return}document.getElementById("main").style.display="block",document.getElementById("auth-gate").style.display="none",a.migrationPending&&(document.getElementById("migration-warn").style.display="block");const d=a.totals||{};document.getElementById("s-24h").textContent=d.last_24h??0,document.getElementById("s-7d").textContent=d.last_7d??0,document.getElementById("s-failed").textContent=d.total_failed??0,document.getElementById("s-failed-24h").textContent=d.failed_24h??0;const l=document.getElementById("freq-body");l.innerHTML="",a.summary.length===0?l.innerHTML='No events in this window':a.summary.forEach(n=>{l.innerHTML+=` ${evtTag(n.event_type)} ${resTag(n.resolution)} ${n.count} `});const c=document.getElementById("events-body"),r=document.getElementById("empty-msg");c.innerHTML="",a.events.length===0?r.style.display="block":(r.style.display="none",a.events.forEach(n=>{c.innerHTML+=` ${fmtTime(n.created_at)} ${evtTag(n.event_type)} ${resTag(n.resolution)} ${n.user_id||"\u2014"} ${ctxCell(n.context)} `})),s.textContent=`Updated ${new Date().toLocaleTimeString()}`}catch(i){s.textContent="Load failed: "+i.message}}function reload(){loadData()}token?loadData():showAuthGate();