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

App::adminGuard();

// ── Liens d'accès étudiant·e ──────────────────────────────────────────────────
$shareLink      = ShareLink::make();
$links          = $shareLink->listActive();
$archivedLinks  = $shareLink->listArchived();

$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$baseUrl  = $protocol . '://' . ($_SERVER['HTTP_HOST'] ?? 'localhost');

// ── Demandes d'accès aux fichiers ─────────────────────────────────────────────
require_once APP_ROOT . '/src/Controllers/FileAccessController.php';

$controller = FileAccessController::create();
$vars = $controller->handle();
extract($vars);

// ── Page setup ────────────────────────────────────────────────────────────────
$pageTitle = 'Accès';
$isAdmin   = true;
$bodyClass = 'admin-body';

require_once APP_ROOT . '/templates/head.php';
echo '<link rel="stylesheet" href="/assets/css/file-access.css">';
include APP_ROOT . '/templates/header.php';
include APP_ROOT . '/templates/admin/acces.php';
require_once APP_ROOT . '/templates/admin/footer.php';
