{% extends "dcbase/profile_edit.html" %}
{% load i18n %}

{% block pageTitle %}{% trans "Account" %}{% endblock %}

{% block style %}
    {{ block.super }}
    <style>
        .email-status { font-weight: bold; margin-left: 5px; }
        .email-button:not(:first-child) { margin-left: 5px; }
    </style>
{% endblock %}

{% block panelBody %}
    {% if user.emailaddress_set.all %}
        <p>{% trans 'The following e-mail addresses are associated with your account:' %}</p>

        <form action="{% url 'account_email' %}" class="email_list" method="post">
            {% csrf_token %}
            <fieldset class="blockLabels">
                {% for emailaddress in user.emailaddress_set.all %}
                    <div class="radio">
                        <label for="email_radio_{{ forloop.counter }}" class="{% if emailaddress.primary %}primary_email{% endif %}">
                            <input id="email_radio_{{ forloop.counter }}" type="radio" name="email"
                                   {% if emailaddress.primary %}checked="checked"{% endif %} value="{{ emailaddress.email }}"/>
                            {{ emailaddress.email }}
                            {% if emailaddress.primary %}
                                <span class="email-status text-primary">{% trans "Primary" %}</span>{% endif %}
                            {% if emailaddress.verified %}
                                <span class="email-status text-success">{% trans "Verified" %}</span>
                            {% else %}
                                <span class="email-status text-danger">{% trans "Unverified" %}</span>
                            {% endif %}
                        </label>
                    </div>
                {% endfor %}

                <div class="buttonHolder">
                    <button class="email-button btn btn-primary" type="submit" name="action_primary">{% trans 'Make Primary' %}</button>
                    <button class="email-button btn btn-default" type="submit" name="action_send">{% trans 'Re-send Verification' %}</button>
                    <button class="email-button btn btn-danger" type="submit" name="action_remove">{% trans 'Remove' %}</button>
                </div>
            </fieldset>
        </form>
    {% else %}
        <p>
            <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 %}

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

    <form method="post" action="{% url 'account_email' %}" class="add_email">
        {% include "dcbase/form.html" %}
        <button class="btn btn-primary" name="action_add" type="submit">{% trans "Add E-mail" %}</button>
    </form>
{% endblock %}

{% block script %}
    <script type="text/javascript">
        (function () {
            var message = "{% trans 'Do you really want to remove the selected e-mail address?' %}";
            var actions = document.getElementsByName('action_remove');
            if (actions.length) {
                actions[0].addEventListener("click", function (e) {
                    if (!confirm(message)) {
                        e.preventDefault();
                    }
                });
            }
        })();
    </script>
{% endblock %}
