<?php
require_once __DIR__ . '/auth-check.php';
require_once __DIR__ . '/../includes/functions.php';

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $admin = getData('admin');
    $password = $_POST['password'] ?? '';
    if (!empty($admin['password']) && password_verify($password, $admin['password'])) {
        $_SESSION['admin_logged_in'] = true;
        header('Location: dashboard.php');
        exit;
    } else {
        $error = 'Invalid password. Please try again.';
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login | Ethiopia Food Expo</title>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&family=Roboto+Condensed:wght@400;700&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="<?php echo BASE_URL; ?>/assets/css/admin.css">
    <style>
        body { background: var(--green-deep); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
        .login-card { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 2.5rem; width: 100%; max-width: 400px; }
        .login-brand { text-align: center; margin-bottom: 1.5rem; }
        .login-brand h1 { font-family: var(--font-heading); font-size: 1.25rem; color: #fff; text-transform: uppercase; margin: 0; }
        .login-brand p { font-size: 0.8rem; color: var(--muted); margin: 0; }
    </style>
</head>
<body>
    <div class="login-card">
        <div class="login-brand">
            <h1>Ethiopia Food Expo</h1>
            <p>Admin Panel</p>
        </div>
        <?php if ($error): ?>
        <div class="alert alert-danger" style="font-size:0.85rem;padding:0.75rem 1rem;"><?php echo e($error); ?></div>
        <?php endif; ?>
        <form method="POST">
            <div class="mb-3">
                <label class="form-label" style="color:var(--muted);font-size:0.78rem;">Email</label>
                <input type="email" class="form-control" value="marketing@infairsafrica.com" disabled style="background:var(--bg2);color:var(--text);">
            </div>
            <div class="mb-3">
                <label class="form-label" style="color:var(--muted);font-size:0.78rem;">Password</label>
                <div class="input-group">
                    <input type="password" name="password" id="loginPass" class="form-control" autofocus required>
                    <button class="btn btn-outline-secondary" type="button" data-toggle-password="#loginPass" style="font-size:0.75rem;">Show</button>
                </div>
            </div>
            <button type="submit" class="btn-admin-primary w-100" style="padding:0.6rem;">Log In</button>
        </form>
        <div class="text-center mt-3">
            <a href="forgot-password.php" style="font-size:0.8rem;color:var(--muted);text-decoration:none;">Forgot Password?</a>
        </div>
    </div>
    <script src="<?php echo BASE_URL; ?>/assets/js/main.js"></script>
</body>
</html>
