{% extends 'auth_layout.html' %}
{% block content %}
{% if context.message %}
    <div class="row">
        <div class="col text-center text-primary mb-3">
            <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 change the Password Reset Interval, 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">
        {% if context.suspend_setting == "false" %}
            <a href="#!" class="disabled btn btn-primary float-end me-2"><i class="ri-add-line"></i>Add Schedule</a>
        {% else %}
            <a href="#!" data-bs-toggle="modal" data-bs-target="#add-schedule" class="btn btn-primary float-end me-2"><i class="ri-add-line"></i>Add Schedule</a>
        {% endif %}
        <a href="{{ url_for('scheduled_emails') }}" class="btn btn-dark float-end me-2"><i class="ri-time-line"></i> Scheduled Reminders</a>
        <h3><i class="ri-time-line"></i> Schedule</h3>
        <p class="lead">The following schedule rules will schedule and send email reminders to staff.</p>
    </div>
</div>
<div class="row">
    <div class="col">
        <table class="table table-flush">
            <thead>
                <tr>
                    <th scope="col">Interval</th>
                    <th scope="col"></th>
                </tr>
            </thead>
            <tbody>
                {% for schedule in context.schedules %}
                <tr>
                    <td>Send email reminder {{ schedule.interval }} day{% if schedule.interval > "1" %}s{% endif %} before password expires.</td>
                    <td class="text-end">
                        {% if context.suspend_setting == "false" %}
                            <a href="#!" class="disabled btn btn-danger">Delete</a>
                        {% else %}
                            <a href="#!" data-bs-toggle="modal" data-bs-target="#setting-{{ loop.index0 }}" class="btn btn-danger">Delete</a>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

<div class="modal fade" id="add-schedule" 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-add-line"></i> Add Schedule</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="" method="post">
                <div class="modal-body">
                    <p class="lead">
                        Enter the number of days before password expiration to send email reminders.
                    </p>
                    <div class="mb-3">
                        <input type="text" class="form-control" id="interval" name="interval" placeholder="Number of days" 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 schedule in context.schedules %}
<div class="modal fade" id="setting-{{ 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">
                <p class="lead">Are you sure you want to delete this schedule?</p>
            </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('schedule_remove', id=schedule.id) }}">Yes, remove the schedule</a>
            </div>
        </div>
    </div>
</div>
{% endfor %}

{% endblock %}