{% extends "account/_layout.html" %}

{% load i18n %}

{% block page_title %}{% trans "Account" %} | {{ block.super }}{% endblock %}

{% block main_content %}
  <div class="ui page stackable grid centered">
    <div class="ten wide column">
      <h1>{% trans "E-mail Addresses" %}</h1>

      {% if user.emailaddress_set.all %}
        <div class="ui tall stacked segment">

          <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 %}

            <div class="ui middle aligned divided list">
              {% for emailaddress in user.emailaddress_set.all %}
                <div class="item">
                  <div class="content">
                    <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 or user.emailaddress_set.count == 1 %}
                             checked="checked"
                             {%endif %}
                             value="{{emailaddress.email}}"/>
                    </label>
                    {{ emailaddress.email }}

                    {% if emailaddress.verified %}
                      <div class="ui green horizontal label">{% trans "Verified" %}</div>
                    {% else %}
                      <div class="ui red horizontal label">{% trans "Unverified" %}</div>
                    {% endif %}
                    {% if emailaddress.primary %}
                      <div class="ui blue horizontal label">{% trans "Primary" %}</div>
                    {% endif %}
                  </div>
                </div>
              {% endfor %}
            </div>

            <div>
              <button class="ui button blue" type="submit" name="action_primary" >
                {% trans 'Make Primary' %}</button>
              <button class="ui button green" type="submit" name="action_send" >
                {% trans 'Re-send Verification' %}</button>
              <button class="ui button red" type="submit" name="action_remove" >
                {% trans 'Remove' %}</button>
            </div>
          </form>
        </div>
      {% 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 %}

      <h2>{% trans "Add E-mail Address" %}</h2>
      <div class="ui tall stacked segment">
        <form method="post" action="{% url 'account_email' %}"
              class="ui form {% if form.errors %}error{% endif %}">
          {% csrf_token %}

          <div class="field {% if form.errors.email %}error{% endif %}">
            {{ form.email.label_tag }}
            {{ form.email }}

            {% if form.errors.email %}
              <div class="ui pointing red basic label">
                {% for error in form.errors.email %}
                  <p>{{ error }}</p>
                {% endfor %}
              </div>
            {% endif %}
          </div>

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