<?php
require '../includes/db.php';
session_start();

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password'];

    $stmt = $pdo->prepare("SELECT * FROM admin WHERE username = ?");
    $stmt->execute([$username]);
    $admin = $stmt->fetch();

    if ($admin && password_verify($password, $admin['password'])) {
        $_SESSION['admin_logged_in'] = true;
        $_SESSION['admin_username'] = $admin['username'];
        header("Location: dashboard.php");
        exit();
    } else {
        $error = "Invalid credentials";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Admin Login - FastPay Gateway</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body {
      background: linear-gradient(135deg, #4a00e0, #8e2de2);
      color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }
    .login-box {
      background: rgba(255, 255, 255, 0.05);
      padding: 30px;
      border-radius: 15px;
      backdrop-filter: blur(10px);
      box-shadow: 0 0 10px rgba(0,0,0,0.2);
      width: 100%;
      max-width: 400px;
    }
    .login-box h3 {
      text-align: center;
      margin-bottom: 25px;
      color: #fff;
    }
    .form-control {
      background-color: rgba(255,255,255,0.1);
      border: none;
      color: #fff;
    }
    .form-control::placeholder {
      color: #ccc;
    }
    .form-control:focus {
      box-shadow: none;
      background-color: rgba(255,255,255,0.2);
    }
    .btn-custom {
      background-color: #ff6a00;
      border: none;
      color: white;
      font-weight: bold;
    }
    .btn-custom:hover {
      background-color: #ff851a;
    }
  </style>
</head>
<body>
  <div class="login-box">
    <h3>Admin Panel Login</h3>
    <?php if (!empty($error)): ?>
      <div class="alert alert-danger text-center"> <?= htmlspecialchars($error) ?> </div>
    <?php endif; ?>
    <form method="POST">
      <div class="mb-3">
        <label>Username</label>
        <input type="text" name="username" class="form-control" required placeholder="admin">
      </div>
      <div class="mb-3">
        <label>Password</label>
        <input type="password" name="password" class="form-control" required placeholder="admin123">
      </div>
      <button type="submit" class="btn btn-custom w-100">Login</button>
    </form>
  </div>
</body>
</html>
