<?php
// partials/structure/app_config.php

// Host-Infos ermitteln (für URLs / Redirects etc.)
$scheme     = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host       = $_SERVER['HTTP_HOST'] ?? app_primary_domain();
$requestUri = $_SERVER['REQUEST_URI'] ?? '/';

// Aktuelle Sprache & Sprachen aus den GLOBALS (fileload.php)
$currentLang     = $GLOBALS['lang']           ?? ($lang ?? 'en');
$allAvailable    = $GLOBALS['availableLangs'] ?? [];

// Optional: Environment aus config.php (du hattest $env → $GLOBALS['usb_env'])
$env = $GLOBALS['usb_env'] ?? 'prod';

// -----------------------------------------------
// USBCheck JavaScript-Konfiguration
// -----------------------------------------------
$usbConfig = [
    'lang'        => $currentLang,

    // Basis-Pfade
    'assetsBase'  => '/assets',

    // Versionierung für JS/CSS
    'assetVersion'=> defined('ASSET_VERSION') ? ASSET_VERSION : null,

    // Environment (prod, staging, dev)
    'env'         => $env,

    // Domains
    'domains'     => [
        'primaryDomain'   => app_primary_domain(),
        'primaryUrl'      => app_primary_url(),
        'fakecheckDomain' => app_fakecheck_domain(),
        'fakecheckUrl'    => app_fakecheck_url(),
    ],

    // Fakecheck-Tool-Config
    'fakecheck' => [
        'baseUrl'    => $GLOBALS['usb_base_url']  ?? '',
        'apiBaseUrl' => $GLOBALS['usb_api_base']  ?? 'https://api.usbcheck.it',
        'locale'     => $currentLang,
    ],

    // i18n-Konfiguration
    'i18n' => [
        'available' => $allAvailable,
        'current'   => $currentLang,
    ],
];
?>
<script>
    window.usbConfig = <?= json_encode(
        $usbConfig,
        JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE
    ) ?>;
</script>
