{extends file="layout.tpl"}

{block name="content"}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Bezpieczeństwo</h4>
            <p class="text-muted mb-0">Przegląd stanu bezpieczeństwa systemu</p>
        </div>
    </div>

    <!-- Statystyki -->
    <div class="row g-4 mb-4">
        <div class="col-sm-6 col-xl-3">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <p class="text-muted mb-1">Logowania (30 dni)</p>
                            <h3 class="mb-0">{$stats.logins.total|default:0}</h3>
                        </div>
                        <div class="text-primary"><i class="bi bi-door-open fs-1"></i></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <p class="text-muted mb-1">Nieudane próby</p>
                            <h3 class="mb-0 text-danger">{$stats.logins.failed|default:0}</h3>
                        </div>
                        <div class="text-danger"><i class="bi bi-x-circle fs-1"></i></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <p class="text-muted mb-1">Zablokowane IP</p>
                            <h3 class="mb-0 text-warning">{$stats.blocked_ips|default:0}</h3>
                        </div>
                        <div class="text-warning"><i class="bi bi-shield-x fs-1"></i></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <p class="text-muted mb-1">Reguły IP</p>
                            <h3 class="mb-0">{($stats.ip_rules.whitelist|default:0) + ($stats.ip_rules.blacklist|default:0)}</h3>
                        </div>
                        <div class="text-info"><i class="bi bi-shield-lock fs-1"></i></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-4">
        <!-- Ostatnie nieudane logowania -->
        <div class="col-lg-6">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0"><i class="bi bi-exclamation-triangle me-2 text-danger"></i>Ostatnie nieudane logowania</h5>
                    <a href="{$baseUrl}/reports/logins?success=0" class="btn btn-sm btn-outline-secondary">Zobacz wszystkie</a>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                                <tr>
                                    <th>IP</th>
                                    <th>Użytkownik</th>
                                    <th>Data</th>
                                </tr>
                            </thead>
                            <tbody>
                                {foreach $recentFailed as $login}
                                <tr>
                                    <td><code>{$login.ip_address}</code></td>
                                    <td>{$login.username|default:'-'}</td>
                                    <td>{$login.created_at|date_format:"%d.%m %H:%M"}</td>
                                </tr>
                                {foreachelse}
                                <tr>
                                    <td colspan="3" class="text-center py-4 text-muted">Brak nieudanych prób</td>
                                </tr>
                                {/foreach}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Top failed IPs -->
        <div class="col-lg-6">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0"><i class="bi bi-bar-chart me-2"></i>Najczęstsze nieudane IP</h5>
                </div>
                <div class="card-body p-0">
                    <ul class="list-group list-group-flush">
                        {foreach $stats.top_failed_ips as $ip}
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            <code>{$ip.ip_address}</code>
                            <span class="badge bg-danger rounded-pill">{$ip.count} prób</span>
                        </li>
                        {foreachelse}
                        <li class="list-group-item text-center text-muted">Brak danych</li>
                        {/foreach}
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <!-- Szybkie akcje -->
    <div class="card mt-4">
        <div class="card-header">
            <h5 class="card-title mb-0"><i class="bi bi-lightning me-2"></i>Szybkie akcje</h5>
        </div>
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-4">
                    <a href="{$baseUrl}/security/ip-rules" class="btn btn-outline-primary w-100">
                        <i class="bi bi-shield-lock me-2"></i>Zarządzaj regułami IP
                    </a>
                </div>
                <div class="col-md-4">
                    <a href="{$baseUrl}/reports/logins" class="btn btn-outline-secondary w-100">
                        <i class="bi bi-clock-history me-2"></i>Historia logowań
                    </a>
                </div>
                <div class="col-md-4">
                    <a href="{$baseUrl}/admin/settings" class="btn btn-outline-secondary w-100">
                        <i class="bi bi-gear me-2"></i>Ustawienia bezpieczeństwa
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
