{% extends "base.html" %}
{% block title %}Sessions{% endblock %}
{% block page_title %}<i class="bi bi-clock-history me-2"></i>Sessions{% endblock %}
{% block content %}
<form method="get" class="row g-2 align-items-end mb-3">
    <div class="col-md-3">
        <input type="text" name="player" class="form-control form-control-sm" placeholder="Player…" value="{{ player }}">
    </div>
    <div class="col-md-3">
        <select name="server" class="form-select form-select-sm">
            <option value="">All Servers</option>
            {% for s in servers %}<option {{ 'selected' if s == server }}>{{ s }}</option>{% endfor %}
        </select>
    </div>
    <div class="col-auto">
        <button class="btn btn-success btn-sm">Filter</button>
        <a href="{{ url_for('panel.sessions') }}" class="btn btn-outline-secondary btn-sm ms-1">Reset</a>
    </div>
</form>
<div class="card">
    <div class="card-header">{{ total }} sessions</div>
    <div class="card-body p-0">
        <div class="table-responsive">
        <table class="table table-sm table-hover mb-0">
            <thead class="table-dark">
                <tr><th>Player</th><th>Server</th><th>Login</th><th>Logout</th><th>Duration</th><th>IP</th><th>Country</th><th>Client</th></tr>
            </thead>
            <tbody>
            {% for r in rows %}
            <tr>
                <td class="small fw-semibold">
                    <a href="{{ url_for('panel.player_detail', uuid=r.player_uuid) }}" class="text-decoration-none">
                        <i class="bi bi-person-circle me-1 text-success"></i>{{ r.player_name }}
                    </a>
                </td>
                <td><span class="badge bg-secondary">{{ r.server_name or '—' }}</span></td>
                <td class="small text-muted text-nowrap">{{ r.login_time | fmt_dt }}</td>
                <td class="small text-muted text-nowrap">{{ r.logout_time | fmt_dt }}</td>
                <td class="small">
                    {% if r.logout_time %}{{ r.duration_sec | fmt_duration }}
                    {% else %}<span class="badge bg-success">Online</span>{% endif %}
                </td>
                <td class="small text-muted">{{ r.ip_address or '—' }}</td>
                <td class="small text-muted">{{ r.country or '—' }}</td>
                <td class="small text-muted">{{ r.client_version or '—' }}</td>
            </tr>
            {% else %}
            <tr><td colspan="8" class="text-center text-muted py-4">No sessions</td></tr>
            {% endfor %}
            </tbody>
        </table>
        </div>
    </div>
</div>
{% include "_pagination.html" %}
{% endblock %}
