{% extends "base.html" %}

{% block content %}
<div class="content-card">
    <div class="page-header">
        <h1>Userverwaltung</h1>
    </div>

    {% if users %}
        <table class="admin-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>E-Mail</th>
                    <th>Aktiv</th>
                    <th>Letzter Login</th>
                    <th>Aktionen</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                <tr>
                    <td>{{ user.id }}</td>
                    <td>{{ user.name }}</td>
                    <td>{{ user.email }}</td>
                    <td>{{ "Ja" if user.is_active else "Nein" }}</td>
                    <td>{{ user.last_login or "-" }}</td>
                    <td class="actions">
                        {% if not user.is_active %}
                        <form method="post"
                              action="{{ url_for('admin_user_activate', user_id=user.id) }}"
                              style="display:inline;">
                            <button type="submit" class="btn btn-small">Aktivieren</button>
                        </form>
                        {% endif %}

                        {% if user.id != session.get('user_id') %}
                        <form method="post"
                              action="{{ url_for('admin_user_delete', user_id=user.id) }}"
                              style="display:inline;"
                              onsubmit="return confirm('Benutzer wirklich löschen?');">
                            <button type="submit" class="btn btn-small btn-danger">Löschen</button>
                        </form>
                        {% else %}
                        <span class="muted">Aktueller Benutzer</span>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>Keine Benutzer vorhanden.</p>
    {% endif %}
</div>
{% endblock %}