{% extends "base.html" %}
{% block title %}Players{% endblock %}
{% block page_title %}<i class="bi bi-people-fill me-2"></i>Players{% endblock %}

{% block content %}
<form method="get" class="row g-2 mb-3">
    <div class="col-auto flex-grow-1">
        <input type="text" name="q" class="form-control" placeholder="Search by player name…" value="{{ search }}">
    </div>
    <div class="col-auto">
        <button class="btn btn-success">Search</button>
        {% if search %}<a href="{{ url_for('panel.players') }}" class="btn btn-outline-secondary ms-1">Reset</a>{% endif %}
    </div>
</form>

<div class="card">
    <div class="card-header d-flex justify-content-between">
        <span>{{ total }} players found</span>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
        <table class="table table-hover table-sm mb-0">
            <thead class="table-dark">
                <tr><th>Player</th><th>IP</th><th>First Seen</th><th>Last Seen</th><th>Playtime</th><th>OP</th><th></th></tr>
            </thead>
            <tbody>
            {% for p in players %}
            <tr>
                <td class="fw-semibold">
                    <i class="bi bi-person-circle me-1 text-success"></i>{{ p.username }}
                </td>
                <td class="small text-muted">{{ p.ip_address or '—' }}</td>
                <td class="small text-muted text-nowrap">{{ p.first_seen | fmt_dt }}</td>
                <td class="small text-muted text-nowrap">{{ p.last_seen  | fmt_dt }}</td>
                <td class="small">{{ p.total_playtime_sec | fmt_duration }}</td>
                <td>
                    {% if p.is_op %}
                    <span class="badge bg-warning text-dark"><i class="bi bi-shield-fill"></i> OP</span>
                    {% else %}<span class="text-muted">—</span>{% endif %}
                </td>
                <td>
                    <a href="{{ url_for('panel.player_detail', uuid=p.uuid) }}" class="btn btn-sm btn-outline-primary">
                        <i class="bi bi-eye"></i>
                    </a>
                </td>
            </tr>
            {% else %}
            <tr><td colspan="7" class="text-center text-muted py-4">No players found</td></tr>
            {% endfor %}
            </tbody>
        </table>
        </div>
    </div>
</div>
{% include "_pagination.html" %}
{% endblock %}
