<?php

declare(strict_types=1);

/** @var array{title_main:string,title_sub:string} $fateBrand */
/** @var bool $fateAdminNavVisible */
/** @var bool $fateForumNavVisible */
/** @var bool $fateBlogNavVisible */
/** @var string $fateBlogNavLabel */
/** @var string $fateAuthNavPage login|register|'' */

if (!isset($fateBlogNavVisible)) {
    require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_blog.php';
    $fateBlogNavVisible = fate_blog_nav_visible_for_frontend();
}

if (!isset($fateBlogNavLabel) || $fateBlogNavLabel === '') {
    if (!function_exists('fate_blog_nav_label')) {
        require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_blog.php';
    }
    $fateBlogNavLabel = fate_blog_nav_label();
}

if (!isset($fateBrand) || !is_array($fateBrand)) {
    require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_ui_settings.php';
    $fateBrand = fate_public_site_branding();
}

$fateAuthNavPage = isset($fateAuthNavPage) && is_string($fateAuthNavPage) ? $fateAuthNavPage : '';
?>
<body>
    <header class="topbar">
        <div class="topbar-inner">
            <a class="brand" href="./"><?= htmlspecialchars($fateBrand['title_main'], ENT_QUOTES, 'UTF-8') ?> <span><?= htmlspecialchars($fateBrand['title_sub'], ENT_QUOTES, 'UTF-8') ?></span></a>
            <nav>
                <a href="./">探索列表</a>
                <?php if (!empty($fateBlogNavVisible)): ?>
                    <a href="blog.php"><?= htmlspecialchars($fateBlogNavLabel, ENT_QUOTES, 'UTF-8') ?></a>
                <?php endif; ?>
                <?php if (!empty($fateForumNavVisible)): ?>
                    <a href="forum/">討論區</a>
                <?php endif; ?>
                <?php
                if (!function_exists('fate_masseur_weekly_recommend_enabled')) {
                    require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_masseur_rewards.php';
                }
                if (fate_masseur_weekly_recommend_enabled()):
                ?>
                    <a href="masseur_weekly.php">週推榜</a>
                <?php endif; ?>
                <a href="login.php"<?= $fateAuthNavPage === 'login' ? ' aria-current="page"' : '' ?>>登入</a>
                <a href="register.php"<?= $fateAuthNavPage === 'register' ? ' aria-current="page"' : '' ?>>註冊</a>
                <?php if (!empty($fateAdminNavVisible)): ?>
                    <a href="admin/">管理後台</a>
                <?php endif; ?>
            </nav>
        </div>
    </header>
