<?php
require_once __DIR__ . '/auth.php';


if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

$error = null;

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

    if ($password === '') {
        $error = 'Passwort fehlt';
    } elseif (function_admin_passwort_verifizieren($pdo, $password)) {
        $_SESSION['admin_logged_in'] = true;

        header('Location: index.php');
        exit;
    } else {
        $error = 'Falsches Passwort';
    }
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Admin Login</title>

<style>
body{
    margin:0;
    background:#0f1115;
    color:#e6e6e6;
    font-family:system-ui,sans-serif;
    display:flex;
    align-items:center;
    justify-content:center;
    height:100vh;
}
.box{
    background:#151922;
    padding:24px;
    border:1px solid #2a2f3a;
    width:320px;
}
h3{margin-top:0}
input{
    width:94%;
    padding:8px;
    margin-top:10px;
    background:#1c2130;
    border:1px solid #2a2f3a;
    color:#e6e6e6;
}
button{
    width:100%;
    padding:8px;
    margin-top:10px;
    background:#1c2130;
    border:1px solid #2a2f3a;
    color:#e6e6e6;
}
button{cursor:pointer}
.error{
    margin-top:10px;
    color:#ff6b6b;
}
</style>
</head>
<body>

<div class="box">
    <h3>Admin Login</h3>

    <form method="post">
        <input
            type="password"
            name="password"
            placeholder="Admin-Passwort"
            autofocus
        >
        <button type="submit">Login</button>
    </form>

    <?php if ($error): ?>
        <div class="error"><?= htmlspecialchars($error) ?></div>
    <?php endif; ?>
</div>

</body>
</html>
