const form = document.querySelector("#incident-form"); const list = document.querySelector("#incidents"); const openCount = document.querySelector("#open-count"); const highCount = document.querySelector("#high-count"); const resolvedCount = document.querySelector("#resolved-count"); const workerState = document.querySelector("#worker-state"); async function requestJson(url, options = {}) { const response = await fetch(url, { headers: { "Content-Type": "application/json" }, ...options, }); if (!response.ok) { const body = await response.json().catch(() => ({})); throw new Error(body.error || `Request failed with ${response.status}`); } return response.json(); } function formatDate(value) { return new Intl.DateTimeFormat("de-CH", { dateStyle: "short", timeStyle: "short", }).format(new Date(value)); } function escapeHtml(value) { return value.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", "\"": """, "'": "'", }[char])); } function render(data) { const metrics = data.metrics || {}; openCount.textContent = metrics.open_count ?? 0; highCount.textContent = metrics.high_count ?? 0; resolvedCount.textContent = metrics.resolved_count ?? 0; workerState.textContent = metrics.updated_at ? `Worker zuletzt aktiv: ${formatDate(metrics.updated_at)}` : "Worker wartet auf Events"; if (!data.incidents.length) { list.innerHTML = `