{% extends 'base.html' %}
{% load i18n %}
{% load allauth %}

{% block head_title %}{% trans "Email Address" %}{% endblock head_title %}

{% block content %}
<div class="container mx-auto max-w-md mt-6">
  <h1 class="text-3xl font-bold text-center mb-6">{% trans "Email Address" %}</h1>
  {% if not emailaddresses %}
    {% include "account/snippets/warn_no_email.html" %}
  {% endif %}
  {% url 'account_email' as action_url %}
  <form method="post" action="{{ action_url }}" class="space-y-4">
    {% csrf_token %}
    {% if current_emailaddress %}
      <div>
        <label for="current_email" class="block font-medium>{% trans "Current email" %}:</label>
        <input id="current_email" type="email" value="{{ current_emailaddress.email }}" disabled class="input input-bordered w-full">
      </div>
    {% endif %}
    {% if new_emailaddress %}
      <div>
        <label for="new_email" class="block font-medium>
          {% if not current_emailaddress %}
            {% trans "Current email" %}:
          {% else %}
            {% trans "Changing to" %}:
          {% endif %}
        </label>
        <input id="new_email" type="email" value="{{ new_emailaddress.email }}" disabled class="input input-bordered w-full">
        <p class="text-sm text-gray-600 mt-1">
          {% trans "Your email address is still pending verification." %}
        </p>
        <div class="flex space-x-2 mt-2">
          <button form="pending-email" type="submit" name="action_send" class="btn btn-secondary btn-sm">{% trans "Re-send Verification" %}</button>
          {% if current_emailaddress %}
            <button form="pending-email" type="submit" name="action_remove" class="btn btn-danger btn-sm">{% trans "Cancel Change" %}</button>
          {% endif %}
        </div>
      </div>
    {% endif %}
    <div>
      <label for="{{ form.email.id_for_label }}" class="block font-medium>{% trans "Change to" %}:</label>
      {{ form.email }}
      {{ form.email.errors }}
    </div>
    {{ redirect_field }}
    <button type="submit" name="action_add" class="btn btn-primary w-full">{% trans "Change Email" %}</button>
  </form>

  {% if new_emailaddress %}
    <form style="display: none" id="pending-email" method="post" action="{% url 'account_email' %}">
      {% csrf_token %}
      <input type="hidden" name="email" value="{{ new_emailaddress.email }}">
    </form>
  {% endif %}
</div>
{% endblock content %}
