{% extends "base.html" %}

{% block title %}User Management - aiosyslogd{% endblock %}

{% block content %}
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">User Management</h1>
        <div class="btn-toolbar mb-2 mb-md-0">
            <a href="{{ url_for('add_user') }}" class="btn btn-sm btn-outline-secondary">
                Add User
            </a>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-striped table-sm">
            <thead>
                <tr>
                    <th>Username</th>
                    <th>Admin</th>
                    <th>Enabled</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                <tr>
                    <td>{{ user.username }}</td>
                    <td>{{ "Yes" if user.is_admin else "No" }}</td>
                    <td>{{ "Yes" if user.is_enabled else "No" }}</td>
                    <td>
                        <a href="{{ url_for('edit_user', username=user.username) }}" class="btn btn-sm btn-primary">Edit</a>
                        {% if user.username != current_user.username %}
                        <form action="{{ url_for('delete_user', username=user.username) }}" method="post" style="display: inline;">
                            <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this user?');">Delete</button>
                        </form>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
