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

// Already logged in
if (admin_is_logged_in()) {
    header('Location: /admin/');
    exit;
}

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $password = $_POST['password'] ?? '';
    if (admin_login($password)) {
        header('Location: /admin/');
        exit;
    }
    $error = 'Invalid password.';
    // Small delay to slow brute force
    sleep(1);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BizNode Admin — Login</title>
<link rel="stylesheet" href="/admin/assets/style.css">
</head>
<body class="login-page">
<div class="login-box">
  <div class="login-logo">🔑 BizNode Admin</div>
  <h1 class="login-title">Sign In</h1>
  <?php if ($error): ?>
  <div class="alert alert-error"><?= htmlspecialchars($error) ?></div>
  <?php endif; ?>
  <form method="POST" action="/admin/login.php">
    <div class="form-group">
      <label class="form-label">Admin Password</label>
      <input type="password" name="password" class="form-input" autofocus required
             placeholder="Enter admin password">
    </div>
    <button type="submit" class="btn btn-primary btn-full">Sign In</button>
  </form>
</div>
</body>
</html>
