{% extends 'auth_layout.html' %}
{% block content %}
{% if context.message %}
    <div class="row">
        <div class="col text-center text-primary">
            <i class="ri-error-warning-fill"></i> {{ context.message }}
        </div>
    </div>
{% endif %}
<div class="row">
    <div class="col">
        <a href="#!" data-bs-toggle="modal" data-bs-target="#add-user" class="btn btn-primary float-end"><i class="ri-user-add-line"></i> Add Admin User</a>
        <h3><i class="ri-shield-user-line"></i> Admin Users</h3>
        <p class="lead">Admin Users are users that can modify this tool.</p>
    </div>
</div>
<div class="row">
    <div class="col">
        <table class="table table-flush">
            <thead>
                <tr>
                    <th scope="col">Username</th>
                    <th scope="col">Create Date</th>
                    <th scope="col">Login Status</th>
                    <th scope="col">Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for user in context.users %}
                <tr>
                    <td>{{ user.username }}</td>
                    <td>{{ user.date_created }}</td>
                    <td>{{ user.logged_in }}</td>
                    <td>
                        <a href="{{ url_for('admin_users_edit', id=user.id) }}" class="btn btn-primary">Edit</a>
                        <a href="#!" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#remove-user-{{ loop.index0 }}">Delete</a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

<div class="modal fade" id="add-user" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header bg-light">
                <h1 class="modal-title fs-5"><i class="ri-user-add-line"></i> Add Admin User</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="" method="post">
                <div class="modal-body">
                    <div class="mb-3">
                        <input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
                    </div>
                    <div class="mb-3">
                        <input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
                    </div>
                    <div class="mb-3">
                        <input type="password" class="form-control" id="confirm_password" name="confirm_password" placeholder="Confirm Password" required>
                    </div>
                </div>
                <div class="modal-footer bg-light">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <input type="submit" class="btn btn-primary" value="Save">
                </div>
            </form>
        </div>
    </div>
</div>

{% for user in context.users %}
<div class="modal fade" id="remove-user-{{ loop.index0 }}" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header bg-light">
                <h1 class="modal-title fs-5">Confirmation</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="mb-3">
                    <p class="lead">Are you sure you want to delete this user?</p>
                </div>
            </div>
            <div class="modal-footer bg-light">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                <a class="btn btn-danger" href="{{ url_for('admin_users_delete', id=user.id) }}">Yes, remove the user</a>
            </div>
        </div>
    </div>
</div>
{% endfor %}

{% endblock %}