{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">Raport aktywności</h4>
            <p class="text-muted mb-0">Statystyki aktywności użytkowników</p>
        </div>
        <div class="btn-group">
            <a href="?days=7" class="btn btn-outline-secondary {if $days == 7}active{/if}">7 dni</a>
            <a href="?days=30" class="btn btn-outline-secondary {if $days == 30}active{/if}">30 dni</a>
            <a href="?days=90" class="btn btn-outline-secondary {if $days == 90}active{/if}">90 dni</a>
        </div>
    </div>

    <!-- Podsumowanie -->
    <div class="row g-4 mb-4">
        <div class="col-sm-6 col-xl-3">
            <div class="card bg-primary bg-opacity-10 border-primary">
                <div class="card-body">
                    <h6 class="text-primary">Aktywni użytkownicy</h6>
                    <h2 class="mb-0">{$report.summary.active_users|default:0}</h2>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card bg-success bg-opacity-10 border-success">
                <div class="card-body">
                    <h6 class="text-success">Logowania ({$days} dni)</h6>
                    <h2 class="mb-0">{$report.summary.logins_count|default:0}</h2>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card bg-warning bg-opacity-10 border-warning">
                <div class="card-body">
                    <h6 class="text-warning">Nowi użytkownicy</h6>
                    <h2 class="mb-0">{$report.summary.new_users|default:0}</h2>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card bg-info bg-opacity-10 border-info">
                <div class="card-body">
                    <h6 class="text-info">Akcje w logach</h6>
                    <h2 class="mb-0">{$report.summary.log_entries|default:0}</h2>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-4">
        <!-- Aktywność użytkowników -->
        <div class="col-lg-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0"><i class="bi bi-people me-2"></i>Aktywność użytkowników</h5>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                                <tr>
                                    <th>Użytkownik</th>
                                    <th>Rola</th>
                                    <th>Logowania</th>
                                    <th>Nieudane</th>
                                    <th>Akcje</th>
                                    <th>Ostatnie logowanie</th>
                                </tr>
                            </thead>
                            <tbody>
                                {foreach $report.user_stats as $user}
                                <tr>
                                    <td><strong>{$user.username}</strong></td>
                                    <td>
                                        {if $user.role == 'admin'}<span class="badge bg-danger">Admin</span>
                                        {elseif $user.role == 'reseller'}<span class="badge bg-primary">Reseller</span>
                                        {else}<span class="badge bg-secondary">User</span>{/if}
                                    </td>
                                    <td><span class="badge bg-success">{$user.logins_period|default:0}</span></td>
                                    <td>
                                        {if $user.failed_logins > 0}
                                        <span class="badge bg-danger">{$user.failed_logins}</span>
                                        {else}
                                        <span class="text-muted">0</span>
                                        {/if}
                                    </td>
                                    <td>{$user.actions_count|default:0}</td>
                                    <td>
                                        {if $user.last_login}
                                        {$user.last_login|date_format:"%d.%m.%Y %H:%M"}
                                        {else}
                                        <span class="text-muted">Nigdy</span>
                                        {/if}
                                    </td>
                                </tr>
                                {foreachelse}
                                <tr><td colspan="6" class="text-center py-4 text-muted">Brak danych</td></tr>
                                {/foreach}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Top akcji -->
        <div class="col-lg-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0"><i class="bi bi-bar-chart me-2"></i>Najczęstsze akcje</h5>
                </div>
                <div class="card-body p-0">
                    <ul class="list-group list-group-flush">
                        {foreach $report.top_actions as $action}
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            <span>{$action.action}</span>
                            <span class="badge bg-primary rounded-pill">{$action.count}</span>
                        </li>
                        {foreachelse}
                        <li class="list-group-item text-center text-muted">Brak danych</li>
                        {/foreach}
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
