<?php require_once __DIR__ . '/../includes/bootstrap.php';
$error = '';
$bootstrapCss = ugfx_vendor_asset('assets/vendor/bootstrap/css/bootstrap.min.css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css', '../');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  if (!ugfx_verify_csrf((string)($_POST['csrf_token'] ?? ''))) {
    $error = 'Security check failed. Refresh and try again.';
  } elseif (ugfx_admin_attempt(trim($_POST['username'] ?? ''), trim($_POST['password'] ?? ''))) {
    header('Location: dashboard.php');
    exit;
  }
  $error = 'Login failed';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="robots" content="noindex,nofollow">
<title>Admin Login</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=Inter:wght@400;600;700;800&family=Orbitron:wght@700;800&display=swap" rel="stylesheet">
<link href="<?= htmlspecialchars($bootstrapCss) ?>" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/theme.css">
</head>
<body class="ugfx-body d-flex align-items-center" style="min-height:100vh;">
<div class="container">
  <div class="row justify-content-center">
    <div class="col-md-6 col-xl-4">
      <div class="ugfx-card p-4">
        <div class="ugfx-micro-label">UGFX ADMIN</div>
        <h1 class="h3 mb-3">Sign in</h1>
        <?php if ($error): ?><div class="alert alert-danger"><?= htmlspecialchars($error) ?></div><?php endif; ?>
        <form method="post" class="d-grid gap-3">
          <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(ugfx_csrf_token()) ?>">
          <input class="form-control" name="username" placeholder="Username">
          <input class="form-control" type="password" name="password" placeholder="Password">
          <button class="btn ugfx-btn-primary">Login</button>
        </form>
        <p class="text-secondary small mt-3 mb-0">No ACCESS Without Autherisation</p>
      </div>
    </div>
  </div>
</div>
</body>
</html>
