<?php $h=static fn($v):string=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');$r=is_array($report??null)?$report:[];$f=$r['filters']??[];$k=$r['kpis']??[]; ?>
<style>.sa{display:grid;gap:16px}.sa-card{background:#fff;border:1px solid #dce4ef;border-radius:16px;padding:18px}.sa-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:12px}.sa-kpi strong{font-size:28px;display:block}.sa-table{width:100%;border-collapse:collapse}.sa-table th,.sa-table td{padding:9px;border-bottom:1px solid #e8edf4;text-align:left;white-space:nowrap}.sa-scroll{overflow:auto}.sa-btn{display:inline-block;border:0;border-radius:9px;padding:9px 12px;background:#eaf1f9;color:#15385d;font-weight:750;text-decoration:none}.sa-btn.primary{background:#1d5f9f;color:#fff}.sa input,.sa select{padding:9px;border:1px solid #cfd9e6;border-radius:8px;width:100%;box-sizing:border-box}.sa label{display:grid;gap:5px}.sa-bar{height:8px;border-radius:9px;background:#dbe7f3;overflow:hidden}.sa-bar i{display:block;height:100%;background:#4a76a8}</style>
<div class="sa"><div><a class="sa-btn" href="/public/administration/securite/soc">← SOC</a></div><section class="sa-card"><small>ENTERPRISE-008.7 · AXIOM 9.9.3</small><h1>SIEM Analytics Engine</h1><p>Analyse temporelle et multicritère des événements, incidents et détections du SOC.</p></section>
<form class="sa-card sa-grid" method="get"><label>Du<input type="date" name="from" value="<?= $h($f['from']??'') ?>"></label><label>Au<input type="date" name="to" value="<?= $h($f['to']??'') ?>"></label><label>Gravité<select name="severity"><option value="">Toutes</option><?php foreach(['info','warning','critical'] as $v):?><option value="<?=$v?>" <?=($f['severity']??'')===$v?'selected':''?>><?=$v?></option><?php endforeach?></select></label><label>Module<input name="module" value="<?= $h($f['module']??'') ?>"></label><label>Catégorie<input name="category" value="<?= $h($f['category']??'') ?>"></label><label>Recherche<input name="q" value="<?= $h($f['q']??'') ?>"></label><div><button class="sa-btn primary">Analyser</button> <a class="sa-btn" href="/public/administration/securite/soc/analytics/export.csv?<?=http_build_query($f)?>">Export CSV</a></div></form>
<section class="sa-grid"><?php foreach(['events'=>'Événements','critical'=>'Critiques','incidents'=>'Incidents ouverts','detections'=>'Détections ouvertes'] as $x=>$label):?><article class="sa-card sa-kpi"><span><?=$label?></span><strong><?= (int)($k[$x]??0) ?></strong></article><?php endforeach?></section>
<section class="sa-grid"><?php foreach(['severity'=>'Gravités','categories'=>'Catégories','modules'=>'Modules','results'=>'Résultats','users'=>'Utilisateurs'] as $x=>$title):?><article class="sa-card"><h2><?=$title?></h2><?php $max=max(array_column($r[$x]??[['total'=>1]],'total')?:[1]);foreach(($r[$x]??[]) as $row):?><p><strong><?= $h($row['label']) ?></strong> — <?= (int)$row['total'] ?><span class="sa-bar"><i style="width:<?=min(100,round(((int)$row['total']/$max)*100))?>%"></i></span></p><?php endforeach?></article><?php endforeach?></section>
<section class="sa-card sa-scroll"><h2>Tendance quotidienne</h2><table class="sa-table"><thead><tr><th>Date</th><th>Événements</th><th>Critiques</th></tr></thead><tbody><?php foreach(($r['daily']??[]) as $row):?><tr><td><?=$h($row['bucket'])?></td><td><?=(int)$row['total']?></td><td><?=(int)$row['critical']?></td></tr><?php endforeach?></tbody></table></section>
<section class="sa-card sa-scroll"><h2>Événements récents</h2><table class="sa-table"><thead><tr><th>Date</th><th>Gravité</th><th>Catégorie</th><th>Module</th><th>Action</th><th>Résultat</th><th>Utilisateur</th><th>Message</th></tr></thead><tbody><?php foreach(($r['events']??[]) as $e):?><tr><td><?=$h($e['occurred_at'])?></td><td><?=$h($e['severity'])?></td><td><?=$h($e['category'])?></td><td><?=$h($e['module'])?></td><td><?=$h($e['action'])?></td><td><?=$h($e['result'])?></td><td><?=$h($e['user_id'])?></td><td><?=$h($e['message'])?></td></tr><?php endforeach?></tbody></table></section>
<section class="sa-card sa-scroll"><h2>Détections récentes</h2><table class="sa-table"><thead><tr><th>Date</th><th>Règle</th><th>Entité</th><th>Score</th><th>Gravité</th><th>Statut</th></tr></thead><tbody><?php foreach(($r['detections']??[]) as $d):?><tr><td><?=$h($d['detected_at'])?></td><td><?=$h($d['rule_name'])?></td><td><?=$h($d['entity_type'].' '.$d['entity_id'])?></td><td><?=(int)$d['score']?>/100</td><td><?=$h($d['severity'])?></td><td><?=$h($d['status'])?></td></tr><?php endforeach?></tbody></table></section></div>
