{% extends "accounts/settings.html" %}
{% load i18n %}
{% block title %}{% translate "E-mail Addresses" %}{% endblock %}
{% block inner %}
  <div style="max-width:480px;" >
    <!-- <h1 class="title">{% translate "E-mail Addresses" %}</h1> -->
    {% if user.emailaddress_set.all %}
      <p class="block">{% translate '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="ctrlHolder field">
	      <label for="email_radio_{{forloop.counter}}" class="{% if emailaddress.primary %}primary_email{%endif%} field radio">
		<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}}" class="radio"/>

		{{ emailaddress.email }}
		{% if emailaddress.verified %}
		  <span class="verified tag">{% translate "Verified" %}</span>
		{% else %}
		  <span class="unverified tag is-danger">{% translate "Unverified" %}</span>
		{% endif %}
		{% if emailaddress.primary %}<span class="primary tag is-primary">{% translate "Primary" %}</span>{% endif %}
	      </label>
	    </div>
	  {% endfor %}

	  <div class="buttonHolder buttons mb-4">
	    <button class="secondaryAction button is-small" type="submit" name="action_primary" >{% translate 'Make Primary' %}</button>
	    <button class="secondaryAction button is-small" type="submit" name="action_send" >{% translate 'Re-send Verification' %}</button>
	    <button class="primaryAction button is-small" type="submit" name="action_remove" >{% translate 'Remove' %}</button>
	  </div>

	</fieldset>
      </form>

    {% else %}
      <p class="block"><strong>{% translate '提醒:'%}</strong> {% translate "您目前没有设置任何电子邮件地址。您确实应该添加一个电子邮件地址，以便接收通知、重置密码等。" %}</p>
    {% endif %}

    {% if can_add_email %}
      <h2 class="subtitle">{% translate "添加邮箱" %}</h2>

      <form method="post" action="{% url 'account_email' %}" class="add_email">
	{% csrf_token %}
	{{form}}
	<button class="button is-primary" name="action_add" type="submit">{% translate "保存" %}</button>
      </form>

    {% endif %}
  </div>
{% endblock %}


{% block extra_js %}
  {{block.super}}
  <script type="text/javascript">
   (function() {
     var message = "{% translate '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 %}
