/* Dashboard page — header, reports table, request form, and main wiring */
const { useState, useMemo, useEffect } = React;
const TYPE_FILTERS = ['Alle', 'Makro', 'Geo', 'Konflikt', 'Infra', 'Asset', 'Simulation'];
/* ---------- Helpers ---------- */
function fmtDate(iso) {
if (!iso) return '—';
const d = new Date(iso);
const months = ['Jan','Feb','Mrz','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'];
return `${String(d.getDate()).padStart(2,'0')} · ${months[d.getMonth()]} · ${d.getFullYear()}`;
}
function fmtDateTime(iso) {
if (!iso) return '—';
const d = new Date(iso);
return d.toLocaleString('de-DE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' });
}
function nextAgentRun() {
const now = new Date();
const noon = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 12, 0, 0));
const midnight = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1, 0, 0, 0));
const next = now < noon ? noon : midnight;
return next.toLocaleString('de-DE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' });
}
function simToRow(sim) {
return {
id: sim.sim_id,
title: sim.title || sim.label || sim.dominant_scenario || sim.sim_id,
type: 'Simulation',
date: fmtDate(sim.published_at || sim.last_updated),
pages: sim.pdf_pages ? `${sim.pdf_pages} S.` : null,
status: 'live', // getLiveReports gibt ausschließlich live Reports zurück
dominantPct: sim.dominant_probability ? Math.round(sim.dominant_probability * 100) : null,
};
}
function StatusPill({ status }) {
if (status === 'live') return Aktuell;
if (status === 'draft') return In Bearbeitung;
return Archiv;
}
/* ---------- Dashboard header ---------- */
function DashHeader({ agentStatus, simCount }) {
const lastRun = agentStatus?.recent_runs?.[0];
const lastRunIso = lastRun?.finished_at || lastRun?.started_at;
const timestampStr = lastRunIso
? fmtDateTime(lastRunIso) + ' UTC'
: new Date().toLocaleString('de-DE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' }) + ' UTC';
const bodyText = lastRunIso
? `Letzter Agent-Run: ${fmtDateTime(lastRunIso)} UTC. Nächstes Update: ${nextAgentRun()} UTC. Eskalationspfade werden kontinuierlich überwacht.`
: `Nächster geplanter Agent-Run: ${nextAgentRun()} UTC. Eskalationspfade werden kontinuierlich überwacht.`;
const statsData = [
['Aktive Simulationen', String(simCount || 0), 'vom Backend'],
['Letzter Agent-Run', lastRunIso ? fmtDateTime(lastRunIso) : '—', lastRun ? `${lastRun.sims_updated ?? '—'} Sims aktualisiert` : 'noch kein Run'],
];
return (
{bodyText}
{simCount} aktive Simulationen.
Starte eine Simulation über „Bericht anfordern" oder publiziere eine bestehende im Admin-Bereich.
)}Die direkte Berichtsanfrage wird in Kürze freigeschaltet. Reports können bis dahin intern über das Admin-Panel ausgelöst werden.
Admin-Panel öffnen →Das Dashboard gibt Ihnen Zugriff auf alle aktiven Engine-Reports, die geopolitische Lagekarte und die aktuelle GeoStrat-Portfolioempfehlung — in Echtzeit vom Backend.
{s.body}