{% 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="{{ url_for('reset_scheduled_emails') }}" class="btn btn-warning float-end me-2">Reset Scheduled Reminders</a>
        <a href="{{ url_for('schedule') }}" class="btn btn-dark float-end me-2">Back</a>
        <h3><i class="ri-time-line"></i> Scheduled Reminders</h3>
        <p class="lead">The following are the scheduled email reminders.</p>
    </div>
</div>
<div class="row">
    <div class="col">
        <table class="table table-flush">
            <thead>
                <tr>
                    <th scope="col">Date to Send</th>
                    <th scope="col">Days before expiration</th>
                    <th scope="col">Username</th>
                    <th scope="col">Email</th>
                    <th class="text-end" scope="col">Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for reminder in context.reminders %}
                <tr>
                    <td>{{ reminder.date }} {{ reminder.date | time_until }}</td>
                    <td>{{ reminder.interval }}</td>
                    <td>{{ reminder.username }}</td>
                    <td>{{ reminder.email }}</td>
                    <td class="text-end">
                        <a href="#!" data-bs-toggle="modal" data-bs-target="#reminder-{{ loop.index0 }}" class="btn btn-danger">Delete</a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

{% for reminder in context.reminders %}
<div class="modal fade" id="reminder-{{ 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 reminder?</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('reminder_remove', id=reminder.id) }}">Yes, remove the reminder</a>
            </div>
        </div>
    </div>
</div>
{% endfor %}

{% endblock %}