<?php

function app_config(): array
{
    static $config = null;

    if ($config === null) {
        $config = require __DIR__ . '/../config/app.php';
    }

    return $config;
}

function e(?string $value): string
{
    return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
}

function render_app_head_assets(): void
{
    ?>
    <link rel="stylesheet" href="/assets/css/app.css?v=<?= e(asset_version()) ?>">
    <?php
    if (function_exists('render_topbar_styles')) {
        render_topbar_styles();
    }
}

function asset_version(): string
{
    $file = __DIR__ . '/../../public/assets/css/app.css';
    return file_exists($file) ? (string)filemtime($file) : '1';
}

function ym_role_label(?string $role): string
{
    return match ((string)$role) {
        'superadmin' => t('roles.superadmin', 'Superadministrator'),
        'org_admin' => t('roles.org_admin', 'Organisationsadministrator'),
        'org_manager' => t('roles.org_manager', 'Organisationsmanager'),
        'org_user' => t('roles.org_user', 'Organisationsbenutzer'),
        'user' => t('roles.user', 'Benutzer'),
        default => (string)$role,
    };
}
