<?php
declare(strict_types=1);

/**
 * @var \App\View\AppView $this
 * @var string|null $currentAdminName
 * @var bool|null $isAdminAuthenticated
 */
$currentPath = $this->getRequest()->getPath();
$navItems = [
    ['label' => 'Home',     'url' => ['_name' => 'home'],         'active' => $currentPath === '/'],
    ['label' => 'Programs', 'url' => ['_name' => 'home', '#' => 'programs'], 'active' => false],
    ['label' => 'Team',     'url' => ['_name' => 'home', '#' => 'team'], 'active' => false],
    ['label' => 'Book',     'url' => ['_name' => 'booking_index'], 'active' => str_starts_with($currentPath, '/book')],
    ['label' => 'Enquire',  'url' => ['_name' => 'contact_add'],  'active' => str_starts_with($currentPath, '/contact')],
];
?>
<!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 Academy') ?></title>
    <meta name="description" content="CandleCraft Academy — warm, beginner-friendly pottery and knitting classes in a small studio. Book a class, meet the teachers, or send an enquiry.">
    <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-site-header">
        <div class="cc-site-header__inner">
            <a class="cc-site-header__brand" href="<?= $this->Url->build(['_name' => 'home']) ?>" aria-label="CandleCraft Academy home">
                <span class="cc-mark" aria-hidden="true"></span>
                <span>CandleCraft</span>
            </a>
            <nav class="cc-site-header__nav" aria-label="Primary 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 class="cc-site-header__cta-group">
                <a class="cc-btn cc-btn--primary cc-btn--sm" href="<?= $this->Url->build(['_name' => 'booking_index']) ?>">Book a class</a>
                <button type="button" class="cc-site-header__mobile" data-cc-drawer-open aria-label="Open menu" aria-controls="cc-drawer" aria-expanded="false">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><line x1="4" y1="7" x2="20" y2="7"/><line x1="4" y1="12" x2="20" y2="12"/><line x1="4" y1="17" x2="20" y2="17"/></svg>
                </button>
            </div>
        </div>
    </header>

    <div class="cc-drawer" id="cc-drawer" data-cc-drawer aria-hidden="true">
        <div class="cc-drawer__panel" role="dialog" aria-label="Menu">
            <div class="cc-drawer__head">
                <span class="cc-site-header__brand">
                    <span class="cc-mark cc-mark--sm" aria-hidden="true"></span>
                    <span>CandleCraft</span>
                </span>
                <button type="button" class="cc-drawer__close" data-cc-drawer-close aria-label="Close menu">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><line x1="6" y1="6" x2="18" y2="18"/><line x1="6" y1="18" x2="18" y2="6"/></svg>
                </button>
            </div>
            <nav class="cc-drawer__nav" aria-label="Mobile 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 class="cc-drawer__footer">
                <a class="cc-btn cc-btn--primary cc-btn--block" href="<?= $this->Url->build(['_name' => 'booking_index']) ?>">Book a class</a>
                <a class="cc-btn cc-btn--outline cc-btn--block" href="<?= $this->Url->build(['_name' => 'contact_add']) ?>">Send an enquiry</a>
                <a class="cc-btn cc-btn--ghost cc-btn--sm" href="<?= $this->Url->build(['_name' => 'admin_login']) ?>">Admin &rarr;</a>
            </div>
        </div>
    </div>

    <?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>

    <footer class="cc-site-footer">
        <div class="cc-site-footer__grid">
            <div>
                <div class="cc-site-footer__brand">
                    <span class="cc-mark" aria-hidden="true"></span>
                    <span>CandleCraft Academy</span>
                </div>
                <p class="cc-site-footer__tag">A small, warm studio teaching pottery and knitting to beginners, returning makers, and anyone ready to slow down and make something with their hands.</p>
            </div>
            <div class="cc-site-footer__col">
                <h5>Learn</h5>
                <a href="<?= $this->Url->build(['_name' => 'home', '#' => 'programs']) ?>">Programs</a>
                <a href="<?= $this->Url->build(['_name' => 'home', '#' => 'team']) ?>">Meet the team</a>
                <a href="<?= $this->Url->build(['_name' => 'home', '#' => 'howitworks']) ?>">How it works</a>
                <a href="<?= $this->Url->build(['_name' => 'home', '#' => 'faq']) ?>">FAQ</a>
            </div>
            <div class="cc-site-footer__col">
                <h5>Visit</h5>
                <a href="<?= $this->Url->build(['_name' => 'booking_index']) ?>">Book a class</a>
                <a href="<?= $this->Url->build(['_name' => 'contact_add']) ?>">Send an enquiry</a>
                <a href="mailto:hello@candlecraft.local">hello@candlecraft.local</a>
            </div>
            <div class="cc-site-footer__col">
                <h5>About</h5>
                <a href="<?= $this->Url->build(['_name' => 'home', '#' => 'why']) ?>">Why us</a>
                <a href="<?= $this->Url->build(['_name' => 'teachers_index']) ?>">Meet the team</a>
                <a href="<?= $this->Url->build(['_name' => 'teacher_apply']) ?>">Teach with us</a>
                <a href="<?= $this->Url->build(['_name' => 'admin_login']) ?>">Admin &rarr;</a>
            </div>
        </div>
        <div class="cc-site-footer__bottom">
            <span>&copy; <?= date('Y') ?> CandleCraft Academy. All rights reserved.</span>
            <span>Made slowly, with warm hands.</span>
        </div>
    </footer>

    <a class="cc-floating-enquire" href="<?= $this->Url->build(['_name' => 'contact_add']) ?>" data-cc-floating-enquire hidden>
        <span>Enquire now</span>
        <svg width="14" height="10" viewBox="0 0 14 10" fill="none" aria-hidden="true">
            <path d="M1,5 L 13,5 M 9,1 L 13,5 L 9,9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
        </svg>
    </a>

    <button type="button" class="cc-chat-launch" data-cc-chat-launch aria-label="Open CandleCraft AI assistant">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>
        </svg>
        <span>Ask CandleCraft</span>
    </button>

    <aside class="cc-chat-panel" data-cc-chat-panel aria-hidden="true" aria-label="CandleCraft AI assistant">
        <div class="cc-chat-head">
            <div class="cc-chat-head__title">
                <span class="cc-chat-head__dot" aria-hidden="true"></span>
                <strong>Ask CandleCraft</strong>
            </div>
            <button type="button" class="cc-chat-head__close" data-cc-chat-close aria-label="Close chat">
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><line x1="6" y1="6" x2="18" y2="18"/><line x1="6" y1="18" x2="18" y2="6"/></svg>
            </button>
        </div>
        <div class="cc-chat-scroll" data-cc-chat-scroll role="log" aria-live="polite">
            <div class="cc-chat-msg cc-chat-msg--bot">Hi! I'm the CandleCraft assistant. Ask me anything about classes, teachers, or how to book.</div>
        </div>
        <form class="cc-chat-form" data-cc-chat-form>
            <label class="sr-only" for="cc-chat-input">Your message</label>
            <textarea id="cc-chat-input" data-cc-chat-input rows="1" placeholder="Ask about classes, times, pricing…"></textarea>
            <button type="submit" data-cc-chat-send aria-label="Send">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
            </button>
        </form>
    </aside>

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