<?php
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';

if (!AdminAuth::hasPassword()) {
    header('Location: /admin/');
    exit;
}
if (AdminAuth::isAuthenticated()) {
    header('Location: /admin/');
    exit;
}

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $password = $_POST['password'] ?? '';
    if (AdminAuth::login($password)) {
        header('Location: /admin/');
        exit;
    }
    $error = 'Mot de passe incorrect.';
}

$pageTitle = 'Connexion';
$isAdmin = true; $bodyClass = 'admin-body';
require_once APP_ROOT . '/templates/head.php';
include APP_ROOT . '/templates/header.php';
include APP_ROOT . '/templates/admin/login.php';
require_once APP_ROOT . '/templates/admin/footer.php';
