<?php
session_start();
require_once __DIR__ . '/../../controllers/LanguageController.php';
$lang_array = LanguageController::loadLanguage();
$lang_code = $_SESSION['lang'] ?? 'es'; // Obtener el código de idioma de la sesión
?>
<!DOCTYPE html>
<html lang="<?php echo substr($lang_code, 0, 2); ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $lang_array['login_title']; ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #98FF98; /* Verde Menta */
        }
        .card {
            border-radius: 15px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <div class="container vh-100 d-flex justify-content-center align-items-center">
        <div class="card p-4" style="width: 100%; max-width: 400px;">
            <div class="d-flex justify-content-end">
                <div class="dropdown">
                    <button class="btn btn-secondary dropdown-toggle" type="button" id="languageDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                        Idioma
                    </button>
                    <ul class="dropdown-menu" aria-labelledby="languageDropdown">
                        <li><a class="dropdown-item" href="../../controllers/LanguageController.php?action=set_language&lang=es">Español</a></li>
                        <li><a class="dropdown-item" href="../../controllers/LanguageController.php?action=set_language&lang=en">English</a></li>
                    </ul>
                </div>
            </div>
            <h1 class="text-center mb-4"><?php echo $lang_array['login_heading']; ?></h1>
            <?php if (isset($_GET['error'])):
            ?>
                <div class="alert alert-danger">Usuario o contraseña incorrectos.</div>
            <?php endif; ?>
            <form id="login-form" action="../../controllers/AuthController.php" method="POST">
                <input type="hidden" name="action" value="login">
                <div class="mb-3">
                    <label for="username" class="form-label"><?php echo $lang_array['username']; ?></label>
                    <input type="text" class="form-control" id="username" name="username" required>
                </div>
                <div class="mb-3">
                    <label for="password" class="form-label"><?php echo $lang_array['password']; ?></label>
                    <input type="password" class="form-control" id="password" name="password" required>
                </div>
                <button type="submit" class="btn btn-primary w-100"><?php echo $lang_array['login_button']; ?></button>
            </form>
            <div class="text-center mt-3">
                <a href="#"><?php echo $lang_array['forgot_password']; ?></a>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>