<?php
require_once __DIR__ . "/../../bootstrap.php";
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once __DIR__ . '/../../src/Database.php';

$pageTitle = "Contenus";

if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

$allowedPageSlugs = ['about', 'licenses'];

try {
    $db = new Database();
    $db->deduplicateLanguages();
    $allPages       = $db->getAllPages();
    $pages          = array_values(array_filter($allPages, fn($p) => in_array($p['slug'], $allowedPageSlugs, true)));
    $aproposKeys    = $db->getAllAproposContents();
    $formHelpBlocks = $db->getAllFormHelpBlocks();
    $siteSettings   = $db->getAllSettings();
} catch (Exception $e) {
    error_log("Error loading contenus: " . $e->getMessage());
    die("Erreur lors du chargement des contenus.");
}

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