<?php
require_once '/var/www/html/config/config.php';
require_once '/var/www/html/include/LogoTime.php';

// 0=Blanc-BW   -   1=Blanc-Couleur   -   2=Gris-2   -   3=LightRouge1-LightBleu1   -   4=LightRouge2-LightBleu2_VDC   -    5=LightBleu-LightBeige_MIK    ***** 
// ------------------------------------------------------------------------------------------------------------------------------------------------------------
// 6=Rouge-Bleu_MRC - 7=LightBleu1-LightRouge1_RXY   -   8=DarkBleu-DarkBrun_Taupe  -   9=DarkRouge-DarkBrun_Taupe     -   10=DarkRouge-DarkBleu_VDC_MRC  ***** 
//   $NBThemeJ = 2 ; //  -- 0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7  ***** 
//   $NBThemeN = 12 ; //  -- 8 -- 9 -- 10 -- 11 -- 12 *****
$ThemeNB = 0;
$ThemesLocal = [
    0  => '/var/www/html/include/Themes/ThemesCouleurs0.php',
    1  => '/var/www/html/include/Themes/ThemesCouleurs1.php',
    2  => '/var/www/html/include/Themes/ThemesCouleurs2.php',
    3  => '/var/www/html/include/Themes/ThemesCouleurs3.php',
    4  => '/var/www/html/include/Themes/ThemesCouleurs4.php',
    5  => '/var/www/html/include/Themes/ThemesCouleurs5.php',
    6  => '/var/www/html/include/Themes/ThemesCouleurs6.php',
    7  => '/var/www/html/include/Themes/ThemesCouleurs7.php',
    8  => '/var/www/html/include/Themes/ThemesCouleurs8.php',
    9  => '/var/www/html/include/Themes/ThemesCouleurs9.php',
    10 => '/var/www/html/include/Themes/ThemesCouleurs10.php',
    11 => '/var/www/html/include/Themes/ThemesCouleurs11.php',
    12 => '/var/www/html/include/Themes/ThemesCouleurs12.php',
    13 => '/var/www/html/include/Themes/ThemesCouleurs13.php',
    14 => '/var/www/html/include/Themes/ThemesCouleurs14.php' 
];

$themeConfigFile = '/var/www/html/css/couleurs.json';
$defaultDayFile   = '/var/www/html/include/ThemesDefaultDay.php';
$defaultNightFile = '/var/www/html/include/ThemesDefaultNight.php';

$themeConfig = [];
if (file_exists($themeConfigFile)) {
    $themeConfig = json_decode(file_get_contents($themeConfigFile), true);
    if (!is_array($themeConfig)) {
        $themeConfig = [];
    }
}
$ThemeNB = (count($ThemesLocal)) - 1;
$NBThemeJ = isset($themeConfig['dayTheme']) ? (int) $themeConfig['dayTheme'] : 4;
$NBThemeN = isset($themeConfig['nightTheme']) ? (int) $themeConfig['nightTheme'] : 8;

$NBThemeJ = max(0, min($ThemeNB, $NBThemeJ)); // $ThemeNB = 14
$NBThemeN = max(0, min($ThemeNB, $NBThemeN));

if ($logo === LOGO) {
    $themeIndex = $NBThemeJ;
    $defaultFile = $defaultDayFile;
    } elseif ($logo === LOGOn || $logo === LOGOn2) {
        $themeIndex = $NBThemeN;
        $defaultFile = $defaultNightFile;
    } else {
    $themeIndex = $NBThemeJ;
    $defaultFile = $defaultDayFile;
}

$themeFile = $ThemesLocal[$themeIndex] ?? null;

    if ($themeFile && file_exists($themeFile)) {
        require $themeFile;
    } elseif (file_exists($defaultFile)) {
        require $defaultFile;
}
?>
