{% extends "admin/base.html" %}
{% block title %}Пользователи — Админ-панель{% endblock %}
{% block nav_users %}active{% endblock %}
{% block page_title %}👥 Пользователи{% endblock %}
{% block top_actions %}
<div class="a-flex">
    <input type="text" id="userSearch" class="a-input a-input-sm" style="width:200px" placeholder="Поиск по имени..." value="{{ search or '' }}">
    <button class="a-btn a-btn-primary" onclick="searchUsers()">🔍 Найти</button>
</div>
{% endblock %}

{% block content %}
{% if users %}
<div class="a-table-wrap">
    <table class="a-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Имя</th>
                <th>Баланс</th>
                <th>Статус</th>
                <th>Кейсов</th>
                <th>Контрактов</th>
                <th>Предметов</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for u in users %}
            <tr>
                <td>{{ u.id }}</td>
                <td>
                    <a href="/admin/user/{{ u.id }}" style="color:#f59e0b;text-decoration:none;font-weight:500">
                        {{ u.username }}
                    </a>
                </td>
                <td>{{ u.balance|money }} ₽</td>
                <td>
                    {% if u.is_admin %}<span class="a-badge a-badge-admin">Админ</span>{% endif %}
                    {% if u.is_banned %}<span class="a-badge a-badge-banned">Забанен</span>{% endif %}
                    {% if not u.is_admin and not u.is_banned %}<span class="a-badge a-badge-user">Игрок</span>{% endif %}
                </td>
                <td>{{ u.case_openings }}</td>
                <td>{{ u.contracts }}</td>
                <td>{{ u.inventory_count }}</td>
                <td class="td-actions">
                    <a href="/admin/user/{{ u.id }}" class="a-btn a-btn-sm">✏️</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% else %}
<div class="a-empty">
    <div class="a-empty-icon">📭</div>
    <h3>Пользователи не найдены</h3>
</div>
{% endif %}
{% endblock %}

{% block scripts %}
<script>
function searchUsers() {
    const q = document.getElementById('userSearch').value.trim();
    window.location.href = '/admin/users' + (q ? '?search=' + encodeURIComponent(q) : '');
}
document.getElementById('userSearch').addEventListener('keydown', e => {
    if (e.key === 'Enter') searchUsers();
});
</script>
{% endblock %}
