<?php
require_once __DIR__ . '/../includes/config.php';

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email    = trim($_POST['email'] ?? '');
    $password = $_POST['password'] ?? '';

    if ($email === ADMIN_EMAIL) {
        $passwordValid = false;
        if (strpos(ADMIN_PASSWORD_HASH, 'PLACEHOLDER') !== false) {
            $passwordValid = strcmp('Inexpo2026Admin', $password) === 0;
        } else {
            $passwordValid = password_verify($password, ADMIN_PASSWORD_HASH);
        }
        if ($passwordValid) {
            $_SESSION['admin_logged_in'] = true;
            $_SESSION['admin_login_time'] = date('Y-m-d H:i:s');
            header('Location: /admin/dashboard.php');
            exit;
        }
    }
    $error = 'Invalid email or password';
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login | 20th Kenya Expo</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700;900&family=DM+Sans:wght@300;400;500&family=Bebas+Neue&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="/assets/css/style.css">
</head>
<body class="admin-login-page">
<div class="admin-login-card">
  <div class="admin-login-logo">
    <div style="font-family:'Playfair Display',serif;font-size:1.4rem;font-weight:900;color:#fff;">KENYA <span style="color:var(--secondary);">/</span> TRADE EXPO</div>
    <span>20th Anniversary Edition &middot; Admin Panel</span>
    <div class="anniversary-badge mt-3" style="margin:16px auto 0;display:flex;width:56px;height:56px;font-size:1rem;">XX</div>
  </div>

  <?php if ($error): ?>
  <div class="alert alert-danger" style="background:rgba(204,0,0,0.15);border:1px solid rgba(204,0,0,0.3);color:#ff6b6b;font-size:0.85rem;padding:10px 14px;border-radius:8px;margin-bottom:20px;">
    <i class="fas fa-exclamation-circle me-2"></i><?php echo htmlspecialchars($error); ?>
  </div>
  <?php endif; ?>

  <form method="POST" action="">
    <div class="mb-3">
      <label class="form-label">Email Address</label>
      <input type="email" name="email" class="form-control" value="<?php echo htmlspecialchars(ADMIN_EMAIL); ?>" required autofocus>
    </div>
    <div class="mb-4">
      <label class="form-label">Password</label>
      <input type="password" name="password" class="form-control" required>
    </div>
    <button type="submit" class="btn btn-gold w-100">Login to Admin Panel</button>
  </form>
  <p class="text-center mt-3" style="font-size:0.75rem;color:var(--text-muted);">
    <a href="/index.php" style="color:var(--text-muted);"><i class="fas fa-arrow-left me-1"></i>Back to Website</a>
  </p>
</div>
</body>
</html>
