// intelligence → predictions table // depends on: app.js, intel-shared.js let predictionsOffset = 0; async function loadPredictions() { const companyId = document.getElementById("i-company").value; const sort = document.getElementById("i-sort").value; const params = new URLSearchParams({ limit: PAGE, offset: predictionsOffset }); if (companyId) params.set("company_id", companyId); if (sort) params.set("sort", sort); const data = await api(`/admin/api/intelligence/predictions?${params}`); intelRows = data.rows; document.getElementById("intel-thead").innerHTML = ` IDCompanyEventTypeDirectionMagnitudeTimeframeRationaleEvent date`; document.getElementById("intel-tbody").innerHTML = data.rows.map(r => ` ${r.id} ${escapeHtml(r.company_name)} ${r.event_id} ${escapeHtml(r.type)} ${escapeHtml(r.direction || "—")} ${escapeHtml(r.magnitude || "—")} ${escapeHtml(r.timeframe || "—")} ${escapeHtml(r.rationale || "—")} ${r.event_date ? r.event_date.slice(0,10) : "—"} `).join(""); const total = data.total; document.getElementById("iPageInfo").textContent = `${predictionsOffset + 1}–${Math.min(predictionsOffset + PAGE, total)} of ${total.toLocaleString()}`; document.getElementById("iPrevBtn").disabled = predictionsOffset === 0; document.getElementById("iNextBtn").disabled = predictionsOffset + PAGE >= total; } document.addEventListener("DOMContentLoaded", async () => { document.getElementById("iPrevBtn").onclick = () => { predictionsOffset = Math.max(0, predictionsOffset - PAGE); loadPredictions(); }; document.getElementById("iNextBtn").onclick = () => { predictionsOffset += PAGE; loadPredictions(); }; document.getElementById("i-filter-btn").onclick = () => { predictionsOffset = 0; loadPredictions(); }; const ok = await loadIntelStatsRow(); if (!ok) return; await loadIntelCompanies(); loadPredictions(); });