<?php
session_start();
include '../db.php';

$error = '';

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

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

    if ($admin && $password === $admin['password']) { // For demo; later: password_verify
        $_SESSION['admin_id'] = $admin['id'];
        header('Location: dashboard.php');
        exit;
    } else {
        $error = "Invalid username or password.";
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Admin Login</title>
    <link rel="stylesheet" href="../style.css">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
	<style>
.container { max-width:400px; margin:2rem auto; }
form { display:flex; flex-direction:column; gap:0.8rem; }
input[type="text"], input[type="password"] { padding:0.6rem; border-radius:6px; border:1px solid #ccc; }
button { padding:0.6rem; background:#007BFF; color:#fff; border:none; border-radius:6px; cursor:pointer; }
button:hover { background:#0056b3; }
</style>
</head>
<body>
<div class="container">
    <h2>Admin Login</h2>
    <?php if($error): ?><p style="color:red;"><?= htmlspecialchars($error) ?></p><?php endif; ?>
    <form method="POST">
        <input type="text" name="username" placeholder="Username" required><br><br>
        <input type="password" name="password" placeholder="Password" required><br><br>
        <button type="submit">Login</button>
    </form>
</div>
</body>
</html>
