<!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' %}" ">


    <style>
        @media (max-width: 700px) {
            .welcome-box {
                flex: none;
                width: auto;
                max-width: 90vw;
                margin: 0 0 20px 0;
                padding: 15px;
            }
            .welcome-section {
                flex-direction: column !important;
                width: 100%;
            }
            .welcome-section .welcome-box {
                width: 100% !important;
                max-width: 100%;
            }
        }
    </style>
</head>
    
</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">
            <h1>Manage your Eversync account</h1>
            <p>You are logged in as {{ user.username }}</p>
        </div>

        <div class="welcome-section" style="display: flex; gap: 20px;">
            <div class="welcome-box" style="width: 20%;">
                <h2>Change Username</h2>
                <form method="post" action="{% url 'change_username' %}">
                    {% csrf_token %}
                    <label for="new_username">New Username:</label><br>
                    <input type="text" id="new_username" name="new_username" required style="margin-top: 5px; margin-bottom: 10px; padding: 8px; border-radius: 4px; width: 90%;"><br>
                    <button type="submit" style="background-color: #4CAF50; color: white; border: 1px solid #4CAF50; padding: 8px 16px; border-radius: 4px; cursor: pointer; width: auto; font-size: 14px;">Update Username</button>
                </form>
            </div>
        
            <div class="welcome-box" style="width: 20%;">
                <h2>Change Password</h2>
                <form method="post" action="{% url 'change_password' %}">
                {% csrf_token %}
                <label for="{{ password_form.old_password.id_for_label }}">Old Password:</label><br>
                <input type="password" id="{{ password_form.old_password.id_for_label }}" name="old_password" required style="margin-top: 5px; margin-bottom: 10px; padding: 8px; border-radius: 4px; width: 90%;"><br>
                {{ password_form.old_password.errors }}
            
                <label for="{{ password_form.new_password1.id_for_label }}">New Password:</label><br>
                <input type="password" id="{{ password_form.new_password1.id_for_label }}" name="new_password1" required style="margin-top: 5px; margin-bottom: 10px; padding: 8px; border-radius: 4px; width: 90%;"><br>
                {{ password_form.new_password1.errors }}
            
                <label for="{{ password_form.new_password2.id_for_label }}">Confirm New Password:</label><br>
                <input type="password" id="{{ password_form.new_password2.id_for_label }}" name="new_password2" required style="margin-top: 5px; margin-bottom: 10px; padding: 8px; border-radius: 4px; width: 90%;"><br>
                {% if password_form.errors %}
                <div style="color: #ff4d4f; margin-bottom: 15px; padding: 10px; background-color: #fff2f0; border: 1px solid #ffccc7; border-radius: 6px;">{{ password_form.new_password2.errors }}</div>
                {% endif %}

                <button type="submit" style="background-color: #4CAF50; color: white; border: 1px solid #4CAF50; padding: 8px 16px; border-radius: 4px; cursor: pointer; width: auto; font-size: 14px;">Update Password</button>
                </form>
            </div>

            <div class="welcome-box" style="width: 20%;">
                <h2>Manage 2FA settings</h2>
                <form action="/accounts/2fa/">

                <button type="submit" style="background-color: #4CAF50; color: white; border: 1px solid #4CAF50; padding: 8px 16px; border-radius: 4px; cursor: pointer; width: auto; font-size: 14px;">Manage</button>
                </form>
            </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>     