<?php

declare(strict_types=1);

/** @var array{title_main:string,title_sub:string}|null $fateBrand */
/** @var array{id:int,username:string,display_name:string,avatar_rel:string}|null $fatePublicMember */
/** @var bool $fateAdminNavVisible */

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();
}

require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_plugins.php';

$fateMinimalNavScript = basename((string) ($_SERVER['SCRIPT_NAME'] ?? 'index.php'));
$fateMinimalNavIsHome = $fateMinimalNavScript === 'index.php';
$fateMinimalNavIsMember = $fateMinimalNavScript === 'member_profile.php';
$fateMinimalNavIsLogin = $fateMinimalNavScript === 'login.php';
$fateMinimalNavIsRegister = $fateMinimalNavScript === 'register.php';
$fateMinimalNavIsBlog = $fateMinimalNavScript === 'blog.php' || $fateMinimalNavScript === 'blog_post.php';
$fateMinimalNavIsForum = str_contains((string) ($_SERVER['SCRIPT_NAME'] ?? ''), '/forum/');

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();
}
?>
<header class="minimal-header" role="banner">
    <div class="minimal-header__inner">
        <a class="minimal-brand bar-brand" href="./">
            <span class="minimal-brand__main"><?= htmlspecialchars($fateBrand['title_main'], ENT_QUOTES, 'UTF-8') ?></span>
            <span class="minimal-brand__sub"><?= htmlspecialchars($fateBrand['title_sub'], ENT_QUOTES, 'UTF-8') ?></span>
        </a>
        <nav class="minimal-nav" aria-label="主要導覽">
            <a class="minimal-nav__link<?= $fateMinimalNavIsHome ? ' minimal-nav__link--active' : '' ?>" href="./">探索列表</a>
            <?php if (!empty($fateBlogNavVisible)): ?>
                <a class="minimal-nav__link<?= $fateMinimalNavIsBlog ? ' minimal-nav__link--active' : '' ?>" href="blog.php"><?= htmlspecialchars($fateBlogNavLabel, ENT_QUOTES, 'UTF-8') ?></a>
            <?php endif; ?>
            <?php if (fate_store_forum_plugin_active()): ?>
                <a class="minimal-nav__link<?= $fateMinimalNavIsForum ? ' minimal-nav__link--active' : '' ?>" href="forum/">討論區</a>
            <?php endif; ?>
            <?php if (isset($fatePublicMember) && $fatePublicMember !== null): ?>
                <a class="minimal-nav__link<?= $fateMinimalNavIsMember ? ' minimal-nav__link--active' : '' ?>" href="member_profile.php">我的帳號</a>
                <a class="minimal-nav__link" href="logout.php">登出</a>
            <?php else: ?>
                <a class="minimal-nav__link<?= $fateMinimalNavIsLogin ? ' minimal-nav__link--active' : '' ?>" href="login.php">登入</a>
                <a class="minimal-nav__link<?= $fateMinimalNavIsRegister ? ' minimal-nav__link--active' : '' ?>" href="register.php">註冊</a>
            <?php endif; ?>
            <?php if (!empty($fateAdminNavVisible)): ?>
                <a class="minimal-nav__link" href="admin/">管理後台</a>
            <?php endif; ?>
        </nav>
    </div>
</header>
