<?php
declare(strict_types=1);

header('Content-Type: application/json; charset=utf-8');

$themesFile = dirname(__DIR__) . '/privatedata/themes-family.json';

if (!is_file($themesFile)) {
    http_response_code(404);
    echo json_encode([
        'ok' => false,
        'error' => 'Fichier themes-family.json introuvable',
    ], JSON_UNESCAPED_UNICODE);
    exit;
}

$themes = json_decode((string) file_get_contents($themesFile), true);

if (!is_array($themes)) {
    http_response_code(500);
    echo json_encode([
        'ok' => false,
        'error' => 'JSON famille invalide',
    ], JSON_UNESCAPED_UNICODE);
    exit;
}

echo json_encode([
    'ok' => true,
    'mode' => 'family',
    'themes' => $themes,
], JSON_UNESCAPED_UNICODE);