{% 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 %}

{% if context.suspend_setting == "false" %}
<div class="alert alert-warning" role="alert">
  The scheduler is currently running. To make changes, you must first disable the scheduler. <a href="{{ url_for('disable_scheduler') }}">Click here to disable the scheduler.</a>
</div>
{% else %}
<div class="alert alert-primary" role="alert">
  The scheduler is currently disabled. <a href="{{ url_for('enable_scheduler') }}">Click here to enable the scheduler.</a>
</div>
{% endif %}

<div class="row">
    <div class="col">
        <a href="#!" data-bs-toggle="modal" data-bs-target="#remove-all-users" class="btn btn-danger float-end {% if context.suspend_setting == "false" %} disabled {% endif %}"><i class="ri-delete-bin-line"></i> Remove all ILS Users</a>
        <a href="#!" data-bs-toggle="modal" data-bs-target="#add-user" class="btn btn-primary float-end me-2 {% if context.suspend_setting == "false" %} disabled {% endif %}"><i class="ri-user-add-line"></i> Add ILS User</a>
        <a href="{{ url_for('admin_ils_users_csv_download') }}" class="btn btn-dark float-end me-2"><i class="ri-file-download-fill"></i> CSV Export</a>
        <a href="{{ url_for('admin_ils_users_csv_import') }}" class="btn btn-dark float-end me-2 {% if context.suspend_setting == "false" %} disabled {% endif %}"><i class="ri-file-upload-fill"></i> CSV Import</a>
        <h3><i class="ri-shield-user-fill"></i> ILS Users</h3>
        <p class="lead">ILS users accounts establish with the ILS system.</p>
    </div>
</div>

<div class="row">
    <div class="col">
        <table class="table table-flush">
            <thead>
                <tr>
                    <th scope="col">Username</th>
                    <th scope="col">Email</th>
                    <th scope="col">Reset Date</th>
                    <th scope="col"></th>
                    <th scope="col"></th>
                </tr>
            </thead>
            <tbody>
                {% for user in context.users %}
                <tr>
                    <td>{{ user.username }}</td>
                    <td>{{ user.email }}</td>
                    <!-- check if user.reset_datetime is today -->

                    <td>
                        {{ user.reset_datetime }}
                    </td>
                    <td>
                        {{ user.reset_datetime|time_since }}
                    </td>
                    <td>
                        {% if context.suspend_setting == "false" %}
                            <a href="#!" class="disabled btn btn-secondary w-100">Edit</a>
                        {% else %}
                            <a href="{{ url_for('admin_ils_users_edit', id=user.id) }}" class="btn btn-secondary w-100">Edit</a>
                        {% endif %}
                    </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-fill"></i> Add ILS 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="email" class="form-control" id="email" name="email" placeholder="Email" required>
                    </div>
                    <div class="mb-3">
                        <input type="date" class="form-control" id="date" name="date" placeholder="Last Password Reset Date">
                    </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>


<div class="modal fade" id="remove-all-users" 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-delete-bin-line-fill"></i> Confirmation</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                # Confirmation asking user to confirm removal of all ILS users
                <p class="lead">
                    Are you sure you want to remove all ILS users?
                </p>
            </div>
            <div class="modal-footer bg-light">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                <a href="{{ url_for('admin_ils_users_delete_all') }}" class="btn btn-danger">Remove All</a>
            </div>

        </div>
    </div>
</div>


{% endblock %}