<?php
/** @var array|null $currentUser */
/** @var Auth $auth */
/** @var I18n $i18n */
/** @var string $activeTheme */
/** @var Settings $settings */
/** @var Module $moduleRegistry */

$pageTitle = t('home.title');
include WEBROOT_PATH . '/includes/header.php';
?>

<h1><?= t('app.welcome') ?></h1>

<?php if ($currentUser): ?>
<p><?= t('home.logged_in', [
    'username' => htmlspecialchars($currentUser['username']),
    'role'     => implode(', ', array_map(
        fn($r) => htmlspecialchars(t('role.' . $r)),
        $currentUser['roles'] ?? []
    )) ?: '—',
]) ?></p>

<div class="card-grid">
    <div class="card">
        <h2><?= t('nav.profile') ?></h2>
        <p><?= t('user.language') ?> : <?= t('lang.' . $i18n->getLanguage()) ?></p>
        <p><?= t('user.theme') ?> : <?= t('theme.' . $activeTheme) ?></p>
        <a href="/profile" class="btn btn-secondary"><?= t('nav.profile') ?></a>
    </div>

    <?php if ($auth->hasRole(ROLE_APP_ADMIN)): ?>
    <div class="card">
        <h2><?= t('nav.admin') ?></h2>
        <p><?= t('admin.welcome') ?></p>
        <a href="/admin/" class="btn btn-primary"><?= t('admin.dashboard') ?></a>
    </div>
    <?php endif; ?>
</div>

<?php else: ?>
<p><?= t('home.visitor') ?></p>
<?php endif; ?>

<?php include WEBROOT_PATH . '/includes/footer.php'; ?>
