{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% load allauth account %}

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

{% block content %}
    <!-- Manage Email Section Start -->
    <section class="space-py-100">
        <div class="container">
            <div class="grid grid-cols-12">
                <div class="col-span-12">
                    <div class="codex-authbox">
                        <div class="auth-header">
                            <div class="codex-brand">
                                <a href="{% url 'main:home' %}">
                                    <img class="img-fluid light-logo" src="{% static 'main/assets/images/logo/logo.webp' %}" alt="logo">
                                    <img class="img-fluid dark-logo" src="{% static 'main/assets/images/logo/logo-light.webp' %}" alt="logo">
                                </a>
                            </div>
                            <h3>{% trans "Manage Email Address" %}</h3>
                        </div>
                        {% if not emailaddresses %}
                            <div class="alert alert-warning">
                                {% include "account/snippets/warn_no_email.html" %}
                            </div>
                        {% endif %}
                        {% url 'account_email' as action_url %}
                        <form method="post" action="{{ action_url }}">
                            {% csrf_token %}

                            {% if current_emailaddress %}
                                <div class="mb-4">
                                    <label class="form-label">{% trans "Current Email:" %}</label>
                                    <input type="email" class="form-control" value="{{ current_emailaddress.email }}" disabled>
                                </div>
                            {% endif %}

                            {% if new_emailaddress %}
                                <div class="mb-4">
                                    <label class="form-label">
                                        {% if not current_emailaddress %}
                                            {% trans "Current Email:" %}
                                        {% else %}
                                            {% trans "Changing To:" %}
                                        {% endif %}
                                    </label>
                                    <input type="email" class="form-control" value="{{ new_emailaddress.email }}" disabled>
                                    <small class="form-text text-muted">{% trans "Your email address is still pending verification." %}</small>
                                    <div class="d-flex gap-2 mt-2">
                                        <button form="pending-email" type="submit" name="action_send" class="btn btn-secondary">{% trans "Re-send Verification" %}</button>
                                        {% if current_emailaddress %}
                                            <button form="pending-email" type="submit" name="action_remove" class="btn btn-danger">{% trans "Cancel Change" %}</button>
                                        {% endif %}
                                    </div>
                                </div>
                            {% endif %}

                            <div class="mb-4">
                                <label for="email" class="form-label">{% trans "Change To:" %}</label>
                                <input id="email" name="email" type="email" class="form-control" value="{{ form.email.value }}">
                                {% if form.email.errors %}
                                    <div class="text-danger">{{ form.email.errors }}</div>
                                {% endif %}
                            </div>

                            <div class="d-flex justify-content-between align-items-center">
                                <button type="submit" name="action_add" class="btn btn-primary">{% trans "Change Email" %}</button>
                            </div>
                        </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>
                </div>
            </div>
        </div>
    </section>
    <!-- Manage Email Section End -->
{% endblock content %}

{% block extra_body %}
    {{ block.super }}
{% endblock extra_body %}
