{% extends 'core/page.html' %}
{% load i18n %}

{% block page %}

<h1>{% trans "E-mail Addresses" %}</h1>

{% if user.emailaddress_set.all %}

<p>{% trans 'The following e-mail addresses are associated with your account:' %}</p>

<form class="mb-5" action="{% url 'account_email' %}" method="post">
    {% csrf_token %}

    {% for emailaddress in user.emailaddress_set.all %}
    <div class="d-flex gap-1 align-items-center pt-2 pb-2 border-top {% if forloop.last %}border-bottom{% endif %}">
        <div class="form-radio me-auto">
            <input class="form-radio-input" id="email_radio_{{forloop.counter}}"
                   type="radio" name="email" value="{{emailaddress.email}}"
                   {% if emailaddress.primary or user.emailaddress_set.count == 1 %}checked="checked"{%endif %} />
            <label class="form-radio-label ms-1" for="email_radio_{{forloop.counter}}">{{ emailaddress.email }}</label>
        </div>
        {% if emailaddress.primary %}
        <div class="badge text-bg-primary">{% trans "Primary" %}</div>
        {% endif %}

        {% if emailaddress.verified %}
        <span class="badge text-bg-success">{% trans "Verified" %}</span>
        {% else %}
        <span class="badge text-bg-warning">{% trans "Unverified" %}</span>
        {% endif %}
    </div>
    {% endfor %}

    <div class="d-flex gap-3 align-items-center mt-3">
        <button class="btn btn-outline-primary" type="submit" name="action_primary" >{% trans 'Make Primary' %}</button>
        <button class="btn btn-outline-secondary" type="submit" name="action_send" >{% trans 'Re-send Verification' %}</button>
        <button class="btn btn-outline-danger" type="button" data-bs-toggle="modal" data-bs-target="#remove-email-modal">
            {% trans 'Remove' %}
        </button>
    </div>

    <div class="modal" id="remove-email-modal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{% trans 'Remove email' %}</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">
                    {% trans 'Do you really want to remove the selected e-mail address?' %}
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                        {% trans 'Close' %}
                    </button>
                    <button type="submit" class="btn btn-danger" name="action_remove">
                        {% trans 'Remove' %}
                    </button>
                </div>
            </div>
        </div>
    </div>
</form>

{% else %}

<p class="mb-5">
    <strong>{% trans 'Warning:'%}</strong> {% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}
</p>

{% endif %}

<h2>{% trans "Add E-mail Address" %}</h2>

<form method="post" action="{% url 'account_email' %}" class="add_email">
    {% csrf_token %}

    {{ form }}

    <button class="btn btn-primary" name="action_add" type="submit">{% trans "Add E-mail" %}</button>
</form>

{% endblock %}
