<?php
declare(strict_types=1);

/**
 * @var \App\View\AppView $this
 * @var string|null $currentAdminName
 */
$currentPath = $this->getRequest()->getPath();
$navItems = [
    ['label' => 'Inbox',        'url' => ['_name' => 'admin_messages'],     'active' => str_starts_with($currentPath, '/admin/messages')],
    ['label' => 'Bookings',     'url' => ['_name' => 'admin_bookings'],     'active' => str_starts_with($currentPath, '/admin/bookings')],
    ['label' => 'Teachers',     'url' => ['_name' => 'admin_teachers'],     'active' => str_starts_with($currentPath, '/admin/teachers')],
    ['label' => 'Applications', 'url' => ['_name' => 'admin_applications'], 'active' => str_starts_with($currentPath, '/admin/applications')],
    ['label' => 'Public site',  'url' => ['_name' => 'home'],               'active' => false],
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?= $this->Html->charset() ?>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="color-scheme" content="light">
    <meta name="theme-color" content="#FFFFFF">
    <title><?= $this->fetch('title', 'CandleCraft Admin') ?></title>
    <link rel="icon" type="image/svg+xml" href="<?= $this->Url->build('/favicon.svg') ?>">
    <link rel="apple-touch-icon" href="<?= $this->Url->build('/img/candlecraft-app-icon.svg') ?>">
    <link rel="manifest" href="<?= $this->Url->build('/manifest.webmanifest') ?>">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <?= $this->Html->css('candlecraft') ?>
    <?= $this->fetch('meta') ?>
    <?= $this->fetch('css') ?>
</head>
<body class="cc-root">
    <a class="cc-skip-link" href="#main-content">Skip to content</a>

    <header class="cc-admin-topbar">
        <div class="cc-admin-topbar__left">
            <a class="cc-admin-topbar__brand" href="<?= $this->Url->build(['_name' => 'admin_messages']) ?>">
                <span class="cc-mark cc-mark--sm" aria-hidden="true"></span>
                <span>CandleCraft <span style="color: var(--cc-ink-3); font-weight: 500;">· Admin</span></span>
            </a>
            <nav class="cc-admin-topbar__nav" aria-label="Admin navigation">
                <?php foreach ($navItems as $item): ?>
                    <a href="<?= $this->Url->build($item['url']) ?>" class="<?= $item['active'] ? 'is-active' : '' ?>"><?= h($item['label']) ?></a>
                <?php endforeach; ?>
            </nav>
        </div>
        <div class="cc-admin-topbar__right">
            <?php if (!empty($currentAdminName)): ?>
                <span class="cc-admin-topbar__email"><?= h((string)$currentAdminName) ?></span>
                <span class="cc-admin-topbar__avatar" aria-hidden="true"><?= h(strtoupper(substr((string)$currentAdminName, 0, 1))) ?></span>
            <?php endif; ?>
            <a class="cc-btn cc-btn--ghost cc-btn--sm" href="<?= $this->Url->build(['_name' => 'admin_logout']) ?>">Log out</a>
        </div>
    </header>

    <?php $flashMessages = $this->Flash->render(); ?>
    <?php if (!empty(trim((string)$flashMessages))): ?>
        <div class="cc-flash-wrap"><?= $flashMessages ?></div>
    <?php endif; ?>

    <main id="main-content">
        <?= $this->fetch('content') ?>
    </main>

    <?= $this->fetch('script') ?>
    <?= $this->Html->script('candlecraft', ['defer' => true]) ?>
</body>
</html>
