<?php
/** @var \BotGuard\Core\View $this */
$this->layout('layouts.app');
$total = (int) ($summary['total'] ?? 0);
$pct = static fn (int $n): string => $total > 0 ? round($n / $total * 100, 1) . '%' : '0%';
?>
<h1 class="h4 mb-3">Risk Reports</h1>

<?= $this->partial('partials.stat_cards', ['summary' => $summary]) ?>

<div class="row g-3 mb-4">
    <div class="col-md-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body">
                <h6 class="card-title mb-3">Risk Distribution</h6>
                <table class="table table-sm mb-0">
                    <tr><td>Verified Humans</td><td class="text-end fw-bold text-success"><?= $pct((int) ($summary['humans'] ?? 0)) ?></td></tr>
                    <tr><td>Suspicious Sessions</td><td class="text-end fw-bold text-warning"><?= $pct((int) ($summary['suspicious'] ?? 0)) ?></td></tr>
                    <tr><td>Bots Blocked</td><td class="text-end fw-bold text-danger"><?= $pct((int) ($summary['bots'] ?? 0)) ?></td></tr>
                    <tr><td>JavaScript Disabled</td><td class="text-end"><?= e((int) ($summary['js_disabled'] ?? 0)) ?></td></tr>
                    <tr><td>Cookies Disabled</td><td class="text-end"><?= e((int) ($summary['cookies_disabled'] ?? 0)) ?></td></tr>
                </table>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body">
                <h6 class="card-title mb-3">Average Risk Score</h6>
                <div class="display-4 fw-bold"><?= e((float) ($summary['avg_score'] ?? 0)) ?><span class="fs-6 text-secondary">/100</span></div>
                <p class="text-secondary small mt-2">Higher is more human. Based on the last 30 days.</p>
            </div>
        </div>
    </div>
</div>

<?= $this->partial('partials.trend_chart', ['trend' => $trend, 'chartId' => 'reportTrend']) ?>
