{% 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">
        <h3><i class="ri-settings-5-line"></i> Settings</h3>
    </div>
</div>

{% 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">
        <table class="table table-flush">
            <thead>
                <tr>
                    <th scope="col">Name</th>
                    <th scope="col">Value</th>
                    <th scope="col">Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for setting in context.settings %}
                <tr>
                    <td>{{ setting.name }}</td>
                    {% if setting.name == 'SMTP Password' %}
                        <td>
                            {% if setting.value == "" %}
                                <i>Password not set</i>
                            {% else %}
                                <i>Password set</i>
                            {% endif %}
                        </td>
                    {% else %}
                        <td>{{ setting.value }}</td>
                    {% endif %}
                    <td>
                        {% if setting.name == 'Password Reset Interval' %}
                            {% if context.suspend_setting == "false" %}
                                <a href="#!" class="disabled btn btn-primary">Edit</a>
                            {% else %}
                                <a href="#!" data-bs-toggle="modal" data-bs-target="#setting-{{ loop.index0 }}" class="btn btn-primary">Edit</a>
                            {% endif %}
                        {% else %}
                            <a href="#!" data-bs-toggle="modal" data-bs-target="#setting-{{ loop.index0 }}" class="btn btn-primary">Edit</a>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

{% for setting in context.settings %}
<div class="modal fade" id="setting-{{ loop.index0 }}" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <form action="" method="post">
                <div class="modal-header bg-light">
                    <h1 class="modal-title fs-5">Edit {{ setting.name}}</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="value" class="form-label">{{ setting.name}}</label>
                        {% if setting.name == 'SMTP Password' %}
                            <input type="password" class="form-control" id="value" name="value" value="" required>
                        {% else %}
                            <input type="text" class="form-control" id="value" name="value" value="{{ setting.value }}" required>
                        {% endif %}
                        <input type="hidden" name="id" value="{{ setting.id }}" 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>
{% endfor %}

{% endblock %}