<?php use App\Core\Csrf; $r=$report; ?>
<style>
.ss-wrap{max-width:1180px;margin:0 auto}.ss-actions,.ss-stats{display:flex;gap:12px;flex-wrap:wrap;margin:14px 0}.ss-card{background:#fff;border:1px solid #dfe5ec;border-radius:14px;padding:18px;box-shadow:0 4px 14px rgba(0,0,0,.04)}.ss-stat{flex:1;min-width:190px}.ss-stat b{font-size:28px;display:block}.ss-table{width:100%;border-collapse:collapse}.ss-table th,.ss-table td{padding:12px;border-bottom:1px solid #edf0f4;text-align:left}.ss-btn{display:inline-block;border:0;border-radius:9px;padding:10px 13px;background:#25354d;color:white;text-decoration:none;cursor:pointer}.ss-btn-danger{background:#982f38}.ss-muted{color:#667085}.ss-badge{display:inline-block;padding:4px 8px;border-radius:999px;background:#eef2f6}.ss-warning{border-left:5px solid #982f38}@media(max-width:760px){.ss-table thead{display:none}.ss-table tr,.ss-table td{display:block}.ss-table tr{padding:12px 0}.ss-table td{border:0;padding:5px 0}}
</style>
<div class="ss-wrap">
<div class="ss-actions"><a class="ss-btn" href="/public/administration/securite">← Sécurité</a><a class="ss-btn" href="/public/administration/securite/incidents">Réponse aux incidents</a></div>
<section class="ss-card"><small>SECURITY-NATIVE-020</small><h2>Contrôle des sessions actives</h2><p>Révoque immédiatement une session compromise sans afficher d’adresse IP, de jeton ni d’empreinte de navigateur.</p></section>
<div class="ss-stats"><section class="ss-card ss-stat"><span>Sessions actives</span><b><?= (int)$r['active_sessions'] ?></b></section><section class="ss-card ss-stat"><span>Utilisateurs connectés</span><b><?= (int)$r['active_users'] ?></b></section><section class="ss-card ss-stat"><span>Dernière analyse</span><b style="font-size:18px"><?= htmlspecialchars($r['generated_at']) ?></b></section></div>
<?php if($canManage): ?><section class="ss-card ss-warning"><h3>Mesure d’urgence</h3><p>Révoquer toutes les autres sessions actives. La session actuelle reste ouverte pour poursuivre la remédiation.</p><form method="post" action="/public/administration/securite/sessions/revoquer-autres" onsubmit="return confirm('Révoquer toutes les autres sessions actives ?');"><?= Csrf::field() ?><button class="ss-btn ss-btn-danger">Révoquer toutes les autres sessions</button></form></section><?php endif; ?>
<section class="ss-card" style="margin-top:14px"><h3>Sessions par utilisateur</h3><table class="ss-table"><thead><tr><th>Utilisateur</th><th>Compte</th><th>Sessions</th><th>Dernière activité</th><th>Action</th></tr></thead><tbody>
<?php foreach($r['users'] as $u): ?><tr><td><strong><?= htmlspecialchars(trim($u['prenom'].' '.$u['nom'])) ?></strong><?php if((int)$u['id']===$currentUserId): ?> <span class="ss-badge">Vous</span><?php endif; ?></td><td class="ss-muted"><?= htmlspecialchars($u['email_masked']) ?></td><td><?= (int)$u['active_sessions'] ?></td><td><?= htmlspecialchars((string)$u['last_seen_at']) ?></td><td><?php if($canManage): ?><form method="post" action="/public/administration/securite/sessions/revoquer" onsubmit="return confirm('Révoquer toutes les sessions de cet utilisateur ?');"><?= Csrf::field() ?><input type="hidden" name="user_id" value="<?= (int)$u['id'] ?>"><button class="ss-btn ss-btn-danger">Révoquer</button></form><?php else: ?>Lecture seule<?php endif; ?></td></tr><?php endforeach; ?>
<?php if(!$r['users']): ?><tr><td colspan="5">Aucune session active détectée.</td></tr><?php endif; ?>
</tbody></table></section></div>
