{% extends "base.html" %}

{% block content %}
<h1 class="title">User Search</h1>

<div class="box">
    <form method="GET" action="{{ url_for('admin.user_search') }}">
        <div class="field has-addons">
            <div class="control is-expanded">
                <input class="input" type="text" name="q" placeholder="Search by Discord or Minecraft username..."
                    value="{{ query }}">
            </div>
            <div class="control">
                <button class="button is-info">Search</button>
            </div>
        </div>
    </form>
</div>

{% if query %}
<div class="box">
    <h2 class="subtitle">Results for "{{ query }}"</h2>
    <table class="table is-fullwidth is-hoverable">
        <thead>
            <tr>
                <th>ID</th>
                <th>Discord User</th>
                <th>Minecraft User</th>
                <th>Joined</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
            <tr>
                <td>{{ user.id }}</td>
                <td>{{ user.username }}</td>
                <td>{{ user.minecraft_username or 'N/A' }}</td>
                <td>{{ user.created_at.strftime('%Y-%m-%d %H:%M') if user.created_at else 'Unknown' }}</td>
                <td>
                    <a href="{{ url_for('admin.user_detail', user_id=user.id) }}" class="button is-small is-link">View
                        Details</a>
                </td>
            </tr>
            {% else %}
            <tr>
                <td colspan="5">No users found.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}
{% endblock %}