<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #1a1a1a;
            color: #ffffff;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background-color: #2a2a2a;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            margin-bottom: 1.5rem;
        }
        form {
            display: flex;
            flex-direction: column;
        }
        input {
            margin-bottom: 1rem;
            padding: 0.5rem;
            border: none;
            border-radius: 4px;
            background-color: #3a3a3a;
            color: #ffffff;
        }
        button {
            padding: 0.5rem;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
    </style>
    {% block head_extra %}{% endblock %}
    <script>
        async function handleLogin(event) {
            event.preventDefault();
            const formData = new FormData(event.target);
            const response = await fetch('/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: new URLSearchParams(formData)
            });
            if (response.ok) {
                console.log(document.cookie)
                window.location.href = '/';
            } else {
                alert('Login failed. Please check your credentials.');
            }
        }
    </script>
</head>
<body>
    <div class="login-container">
        <h1>Login</h1>
        <form onsubmit="handleLogin(event)">
            <input type="text" name="username" placeholder="Username" required>
            <input type="password" name="password" placeholder="Password" required>
            <button type="submit">Log In</button>
        </form>
        {% block content %}{% endblock %}
        <div>
            <p>Don't have an account? <a href="/signup">Sign Up</a></p>
        </div>
    </div>
</body>
</html>