<?php

declare(strict_types=1);

putenv('XKB_CONFIG_ROOT=/usr/share/X11/xkb');
putenv('XLOCALEDIR=/usr/share/X11/locale');
// Bootstrap: Load composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';

// PSR-4 Autoloader for ServerManager namespace
spl_autoload_register(function ($class) {
    $prefix = 'ServerManager\\';
    $baseDir = __DIR__ . '/ServerManager/';

    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }

    $relativeClass = substr($class, $len);
    $file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';

    if (file_exists($file)) {
        require $file;
    }
});

// Initialize Icon Font
$iconFontCandidates = [
    __DIR__ . '/../assets/fonts/fa-solid-900.ttf',
    __DIR__ . '/../assets/fonts/fontawesome/fa7_freesolid_900.otf',
    '/usr/share/fonts/truetype/fontawesome-webfont.ttf',
    '/usr/share/fonts/truetype/fontawesome/fa-solid-900.ttf',
    '/usr/share/fonts/truetype/fa-solid-900.ttf',
];

$iconFontPath = null;
foreach ($iconFontCandidates as $candidate) {
    if (is_file($candidate)) {
        $iconFontPath = $candidate;
        break;
    }
}

if ($iconFontPath !== null) {
    \PHPNative\Framework\IconFontRegistry::setDefaultFontPath($iconFontPath);
} else {
    echo "Hinweis: FontAwesome Font nicht gefunden. Icons werden ohne Symbol dargestellt.\n";
}

// Run the application
$app = new ServerManager\App();
$app->run();
