<?php
/** @var \BotGuard\Core\View $this */
$this->layout('layouts.app');
?>
<div class="d-flex justify-content-between align-items-center mb-3">
    <h1 class="h4 mb-0">Admin Overview</h1>
    <div class="d-flex gap-2">
        <a href="/admin/modules" class="btn btn-outline-primary btn-sm"><i class="bi bi-sliders"></i> Modules</a>
        <a href="/admin/thresholds" class="btn btn-outline-primary btn-sm"><i class="bi bi-speedometer"></i> Thresholds</a>
        <a href="/admin/smtp" class="btn btn-outline-primary btn-sm"><i class="bi bi-envelope"></i> SMTP</a>
        <a href="/admin/announcements" class="btn btn-outline-primary btn-sm"><i class="bi bi-megaphone"></i> Announcements</a>
        <a href="/admin/backups" class="btn btn-outline-primary btn-sm"><i class="bi bi-database"></i> Backups</a>
    </div>
</div>

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

<div class="row g-3 mb-4">
    <div class="col-lg-8">
        <?= $this->partial('partials.trend_chart', ['trend' => $trend, 'chartId' => 'adminTrend']) ?>
    </div>
    <div class="col-lg-4">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body">
                <h6 class="card-title mb-3">Module Health (avg human %)</h6>
                <?php if (empty($moduleHealth)): ?>
                    <p class="text-secondary small mb-0">No detection data yet.</p>
                <?php else: foreach ($moduleHealth as $m): ?>
                    <div class="mb-2">
                        <div class="d-flex justify-content-between small">
                            <span><?= e($m['module']) ?></span>
                            <span class="text-secondary"><?= e($m['avg_human_pct']) ?>%</span>
                        </div>
                        <div class="progress mt-1" style="height:5px">
                            <div class="progress-bar bg-info" style="width: <?= (float) $m['avg_human_pct'] ?>%"></div>
                        </div>
                    </div>
                <?php endforeach; endif; ?>
            </div>
        </div>
    </div>
</div>

<div class="row g-3">
    <div class="col-lg-6"><?= $this->partial('partials.top_list', ['title' => 'Top Countries', 'rows' => $topCountries]) ?></div>
    <div class="col-lg-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body d-flex flex-column justify-content-center">
                <h6 class="card-title">Registered Users</h6>
                <div class="display-5 fw-bold"><?= e($userCount) ?></div>
            </div>
        </div>
    </div>
</div>
