{% extends "base.html" %}
{% block title %}Commands{% endblock %}
{% block page_title %}<i class="bi bi-terminal-fill me-2"></i>Commands{% 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">
        <input type="text" name="q" class="form-control form-control-sm" placeholder="Command text…" value="{{ search }}">
    </div>
    <div class="col-md-2">
        <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.commands') }}" class="btn btn-outline-secondary btn-sm ms-1">Reset</a>
    </div>
</form>
<div class="card">
    <div class="card-header">{{ total }} commands</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>Time</th><th>Player</th><th>Server</th><th>Command</th><th>Position</th></tr>
            </thead>
            <tbody>
            {% for r in rows %}
            <tr>
                <td class="small text-muted text-nowrap">{{ r.timestamp | fmt_dt }}</td>
                <td class="small fw-semibold">{{ r.player_name or '—' }}</td>
                <td><span class="badge bg-secondary">{{ r.server_name or '—' }}</span></td>
                <td class="small font-monospace text-warning">{{ r.command }}</td>
                <td class="small text-muted">
                    {% if r.world %}{{ r.world }} ({{ r.x|round(0)|int }}, {{ r.y|round(0)|int }}, {{ r.z|round(0)|int }}){% else %}—{% endif %}
                </td>
            </tr>
            {% else %}
            <tr><td colspan="5" class="text-center text-muted py-4">No commands</td></tr>
            {% endfor %}
            </tbody>
        </table>
        </div>
    </div>
</div>
{% include "_pagination.html" %}
{% endblock %}
