<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Eversync</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    {% load static %}
    <link rel="icon" href="{% static 'favicon.ico' %}">
    <link rel="stylesheet" href="{% static 'index-style.css' %}">
    {% block scripts %}
        {% include "sentry_replay.html" %}
    {% endblock %}
    <style>
        body {
            margin: 0;
            padding: 0;
        }
        .container {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 80vh;
        }
        .welcome-box {
            width: 100%;
            max-width: 600px;
            padding: 32px 24px;
            border-radius: 12px;
            background: #fff;
            margin: 40px auto 0 auto;
            box-shadow: 0 2px 16px rgba(0,0,0,0.08);
        }
        .emailaddress-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .emailaddress-item {
            margin-bottom: 24px;
            padding-bottom: 16px;
            border-bottom: 1px solid #f0f0f0;
        }
        .email-label-row {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 8px;
        }
        .email-buttons {
            display: flex;
            flex-direction: column;
            gap: 8px;
            margin-left: 28px; /* align under email */
        }
        .email-buttons button {
            width: fit-content;
            align-self: flex-start;
        }
        @media (max-width: 700px) {
            .welcome-box {
                max-width: 95vw;
                padding: 16px 5vw;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <a href="/"><img src="{% static 'eversync2.png' %}" alt="Eversync Logo" style="height: 80px; margin-right: 10px; display: flex; align-items: center; gap: 5px;"></a>
            <a href="/" class="logo" >eversync</a>
            <div class="nav-links" style="position: relative;">
                <div class="dropdown">
                    <button class="dropdown-toggle" style="background: none; border: none; color: white; font-size: 16px; cursor: pointer;">
                        Welcome, {{ user.username }} <i class="fas fa-caret-down"></i>
                    </button>
                    <div class="dropdown-menu" style="display: none; position: absolute; right: 0; background-color: #333; border: 1px solid #444; border-radius: 4px; padding: 10px; width: 184px;">
                        <form action="{% url 'manage' %}" method="post" style="margin: 0;">
                            {% csrf_token %}
                            <button type="submit" class="logout-button" style="background-color: transparent; color: white; border: none; cursor: pointer;">Manage Account</button>
                        </form>
                        <form action="{% url 'logoutz' %}" method="post" style="margin: 0;">
                            {% csrf_token %}
                            <button type="submit" class="logout-button" style="background-color: transparent; color: white; border: none; cursor: pointer;">Log Out</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="welcome-box">
            {% load i18n %}
            <h1>{% trans "Email Addresses" %}</h1>
            {% if user.emailaddress_set.all %}
                <p>{% trans "The following email addresses are associated with your account:" %}</p>
                <form action="{% url 'account_email' %}" class="email_list" method="post">
                    {% csrf_token %}
                    <fieldset>
                        <ul class="emailaddress-list">
                        {% for emailaddress in user.emailaddress_set.all %}
                            <li class="emailaddress-item">
                                <div class="email-label-row">
                                    <label for="email_radio_{{forloop.counter}}">
                                        <input id="email_radio_{{forloop.counter}}" type="radio" name="email"
                                        {% if emailaddress.primary %}checked="checked"{% endif %}
                                        value="{{emailaddress.email}}"/>
                                        {{ emailaddress.email }}
                                    </label>
                                    {% if emailaddress.verified %}
                                        <span class="verified">{% trans "Verified" %}</span>
                                    {% else %}
                                        <span class="unverified">{% trans "Unverified" %}</span>
                                    {% endif %}
                                    {% if emailaddress.primary %}
                                        <span class="primary">{% trans "Primary" %}</span>
                                    {% endif %}
                                </div>
                                <div class="email-buttons">
                                    <button type="submit" name="action_primary" value="{{ emailaddress.email }}">{% trans "Make Primary" %}</button>
                                    <button type="submit" name="action_send" value="{{ emailaddress.email }}">{% trans "Resend Verification" %}</button>
                                    <button type="submit" name="action_remove" value="{{ emailaddress.email }}">{% trans "Remove" %}</button>
                                </div>
                            </li>
                        {% endfor %}
                        </ul>
                    </fieldset>
                </form>
            {% else %}
                <p>{% trans "No email address associated with this account. Re-log in to add a new email." %}</p>
            {% endif %}
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const toggle = document.querySelector('.dropdown-toggle');
            const menu = document.querySelector('.dropdown-menu');
            toggle.addEventListener('click', function () {
                menu.style.display = menu.style.display === 'block' ? 'none' : 'block';
            });
        });
    </script>   
</body>
</html>