{% extends "base.html" %}
{% block title %}Chat Log{% endblock %}
{% block page_title %}<i class="bi bi-chat-dots-fill me-2"></i>Chat Log{% endblock %}

{% block content %}
<form method="get" class="row g-2 align-items-end mb-3">
    <div class="col-12 col-md-3">
        <label class="form-label small">Message</label>
        <input type="text" name="q" class="form-control form-control-sm" placeholder="Search…" value="{{ search }}">
    </div>
    <div class="col-12 col-md-2">
        <label class="form-label small">Server</label>
        <select name="server" class="form-select form-select-sm">
            <option value="">Alle</option>
            {% for s in servers %}<option {{ 'selected' if s == server }}>{{ s }}</option>{% endfor %}
        </select>
    </div>
    <div class="col-12 col-md-2">
        <label class="form-label small">From</label>
        <input type="date" name="from" class="form-control form-control-sm" value="{{ date_from }}">
    </div>
    <div class="col-12 col-md-2">
        <label class="form-label small">To</label>
        <input type="date" name="to" class="form-control form-control-sm" value="{{ date_to }}">
    </div>
    <div class="col-auto">
        <button class="btn btn-success btn-sm">Filter</button>
        <a href="{{ url_for('chat') }}" class="btn btn-outline-secondary btn-sm ms-1">Reset</a>
    </div>
</form>

<div class="card">
    <div class="card-header">{{ total }} messages</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>Channel</th><th>Message</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><span class="badge bg-primary">{{ r.channel or 'global' }}</span></td>
                <td class="small">{{ r.message }}</td>
            </tr>
            {% else %}
            <tr><td colspan="5" class="text-center text-muted py-4">No messages found</td></tr>
            {% endfor %}
            </tbody>
        </table>
        </div>
    </div>
</div>
{% include "_pagination.html" %}
{% endblock %}
