<?php
require __DIR__ . '/lib.php';
header('Content-Type: application/json; charset=utf-8');

if (!is_authenticated()) {
    http_response_code(403);
    echo json_encode(['ok' => false, 'error' => 'Accès refusé'], JSON_UNESCAPED_UNICODE);
    exit;
}

$slug = slugify($_GET['form'] ?? '');
if (!$slug) {
    echo json_encode(['ok' => false, 'error' => 'Paramètre form manquant'], JSON_UNESCAPED_UNICODE);
    exit;
}

echo json_encode(build_stats($slug), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
