<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Connexion</title>
    <style>
        /* Styles généraux */
        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #6a11cb, #2575fc);
            color: #fff;
            text-align: center;
            padding: 0;
            margin: 0;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            animation: backgroundAnimation 10s ease infinite;
        }

        /* Animation du fond */
        @keyframes backgroundAnimation {
            0% {
                background: linear-gradient(135deg, #6a11cb, #2575fc);
            }
            50% {
                background: linear-gradient(135deg, #ff6a00, #d84c6f);
            }
            100% {
                background: linear-gradient(135deg, #6a11cb, #2575fc);
            }
        }

        h1 {
            font-size: 2.5rem;
            color: #fff;
            margin-bottom: 30px;
            letter-spacing: 2px;
            text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
        }

        /* Style du formulaire */
        .form-container {
            background: rgba(255, 255, 255, 0.1);
            padding: 30px 40px;
            border-radius: 10px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 400px;
        }

        input {
            padding: 12px;
            font-size: 16px;
            width: 100%;
            margin-bottom: 20px;
            border: 2px solid #ddd;
            border-radius: 5px;
            background: #fff;
            color: #333;
            transition: border-color 0.3s ease;
        }

        input:focus {
            border-color: #2575fc;
            outline: none;
        }

        button {
            padding: 12px 25px;
            font-size: 16px;
            background: #2575fc;
            color: white;
            border: none;
            border-radius: 30px;
            cursor: pointer;
            width: 100%;
            transition: transform 0.3s ease, background-color 0.3s ease;
        }

        button:hover {
            background-color: #6a11cb;
            transform: translateY(-5px);
        }

        button:active {
            transform: scale(0.95);
        }

        /* Message d'erreur */
        #errorMessage {
            color: red;
            margin-top: 15px;
            font-size: 1rem;
        }

        /* Responsivité */
        @media (max-width: 768px) {
            h1 {
                font-size: 2rem;
            }

            .form-container {
                width: 90%;
                padding: 25px;
            }
        }

        @media (max-width: 480px) {
            h1 {
                font-size: 1.6rem;
            }
        }
    </style>
</head>
<body>
    <h1>Connexion</h1>
    <div class="form-container">
        <input type="text" id="nameInput" placeholder="Entrez votre pseudo" />
        <button id="loginButton">Se Connecter</button>
        <p id="errorMessage"></p>
    </div>

    <script type="module">
        import { initializeApp } from "https://www.gstatic.com/firebasejs/11.1.0/firebase-app.js";
        import { getAuth, signInAnonymously } from "https://www.gstatic.com/firebasejs/11.1.0/firebase-auth.js";

        const firebaseConfig = {
            apiKey: "AIzaSyAnoTZXPZGF1e6OABQNaiTm2azaEwr4nwA",
            authDomain: "courses-35750.firebaseapp.com",
            projectId: "courses-35750",
            storageBucket: "courses-35750.appspot.com",
            messagingSenderId: "579827180001",
            appId: "1:579827180001:web:929b09f8ff002a96b632a0"
        };

        const app = initializeApp(firebaseConfig);
        const auth = getAuth(app);

        const loginButton = document.getElementById("loginButton");
        const nameInput = document.getElementById("nameInput");
        const errorMessage = document.getElementById("errorMessage");
        const validNames = ["gret", "xav", "milou", "nono", "antho"];

        loginButton.addEventListener("click", async () => {
            const name = nameInput.value.trim().toLowerCase();
            if (validNames.includes(name)) {
                try {
                    await signInAnonymously(auth);
                    localStorage.setItem('userName', name);  // Sauvegarder le nom d'utilisateur
                    window.location.href = 'listes.html';  // Rediriger vers la page des listes
                } catch (error) {
                    errorMessage.textContent = "Erreur de connexion : " + error.message;
                }
            } else {
                errorMessage.textContent = "Prénom non autorisé.";
            }
        });
    </script>
</body>
</html>
