<!DOCTYPE html>
<?php $locale = current_locale(); ?>
<html lang="<?= e($locale) ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="theme-color" content="<?= e(config('brand.theme_color', '#1c6944')) ?>">
    <title><?= e(($title ?? config('name')) . ' | ' . config('name')) ?></title>
    <link rel="stylesheet" href="<?= e(asset_url('css/app.css')) ?>">
    <script defer src="<?= e(asset_url('js/app.js')) ?>"></script>
</head>
<?php $pagePath = request_path(); ?>
<body>
    <div class="page-shell<?= ($pagePath === '/' || $pagePath === '/participant/start') ? ' page-shell-home' : '' ?>">
        <header class="site-header">
            <div class="site-header-main">
                <a class="brand" href="<?= e(base_url('/')) ?>">
                    <img class="brand-logo" src="<?= e(asset_url(config('brand.logo', 'images/sentral-college-penang-logo.png'))) ?>" alt="<?= e(trans('brand.header_title', [], $locale)) ?> logo">
                    <span class="brand-lockup">
                        <strong><?= e(trans('brand.header_title', [], $locale)) ?></strong>
                    </span>
                </a>

                <div class="site-header-utility">
                    <div class="locale-switcher" aria-label="<?= e(trans('common.ui_language', [], $locale)) ?>">
                        <span class="locale-switcher-label"><?= e(trans('common.ui_language', [], $locale)) ?></span>
                        <?php foreach (supported_languages() as $languageCode => $languageLabel): ?>
                            <a class="<?= $locale === $languageCode ? 'locale-pill is-active' : 'locale-pill' ?>" href="<?= e(locale_url($languageCode)) ?>"><?= e($languageLabel) ?></a>
                        <?php endforeach; ?>
                    </div>

                    <div class="header-utility-actions">
                        <?php if (is_admin_authenticated()): ?>
                            <span class="header-context-label"><?= e(trans('common.administrator', [], $locale)) ?></span>
                            <form method="post" action="<?= e(base_url('/admin/logout')) ?>">
                                <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                <button class="ghost-button" type="submit"><?= e(trans('common.logout', [], $locale)) ?></button>
                            </form>
                        <?php else: ?>
                            <a class="ghost-button" href="<?= e(base_url('/admin/login')) ?>"><?= e(trans('nav.administrator', [], $locale)) ?></a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <?php if (is_admin_authenticated()): ?>
                <nav class="header-nav" aria-label="<?= e(trans('common.administrator', [], $locale)) ?>">
                    <a class="<?= ($activeSection ?? '') === 'reports' ? 'header-nav-link is-active' : 'header-nav-link' ?>" href="<?= e(base_url('/admin/reports')) ?>"><?= e(trans('nav.reports', [], $locale)) ?></a>
                    <a class="<?= ($activeSection ?? '') === 'areas' ? 'header-nav-link is-active' : 'header-nav-link' ?>" href="<?= e(base_url('/admin/areas')) ?>"><?= e(trans('nav.interest_areas', [], $locale)) ?></a>
                    <a class="<?= ($activeSection ?? '') === 'questions' ? 'header-nav-link is-active' : 'header-nav-link' ?>" href="<?= e(base_url('/admin/questions')) ?>"><?= e(trans('nav.questions', [], $locale)) ?></a>
                    <a class="<?= ($activeSection ?? '') === 'careers' ? 'header-nav-link is-active' : 'header-nav-link' ?>" href="<?= e(base_url('/admin/careers')) ?>"><?= e(trans('nav.careers', [], $locale)) ?></a>
                    <a class="<?= ($activeSection ?? '') === 'programmes' ? 'header-nav-link is-active' : 'header-nav-link' ?>" href="<?= e(base_url('/admin/programmes')) ?>"><?= e(trans('nav.programmes', [], $locale)) ?></a>
                </nav>
            <?php endif; ?>
        </header>

        <?php if ($message = flash('success')): ?>
            <div class="flash flash-success"><?= e($message) ?></div>
        <?php endif; ?>

        <?php if ($message = flash('error')): ?>
            <div class="flash flash-error"><?= e($message) ?></div>
        <?php endif; ?>

        <main class="page-content">
            <?= $content ?>
        </main>
    </div>
</body>
</html>