<?php

use FatBottom\Core\View;

$businessName = (string) $config->get('business.name', 'Fat Bottom Grille');
$isAdmin = isset($adminPage);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#09131d">
    <meta name="description" content="Order burgers, burritos, dinner plates, sides, and drinks online from Fat Bottom Grille in Keyser, West Virginia.">
    <title><?= e($title ?? $businessName) ?> | <?= e($businessName) ?></title>
    <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=Barlow+Condensed:wght@600;700;800&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= e(asset('assets/app.css')) ?>">
    <?php if (!empty($squareEnabled) && !empty($squareAppId) && !empty($squareLocationId)): ?>
        <script src="<?= $squareEnvironment === 'production'
            ? 'https://web.squarecdn.com/v1/square.js'
            : 'https://sandbox.web.squarecdn.com/v1/square.js' ?>"></script>
    <?php endif; ?>
</head>
<body class="<?= $isAdmin ? 'admin-body' : 'store-body' ?>">
<a class="skip-link" href="#main">Skip to content</a>

<?php if ($isAdmin): ?>
    <div class="admin-shell">
        <?php View::partial('partials/admin-nav', compact('adminPage', 'config', 'currentUser')); ?>
        <div class="admin-content">
            <header class="admin-topbar">
                <div>
                    <span class="eyebrow">Staff workspace</span>
                    <h1><?= e($title ?? 'Dashboard') ?></h1>
                </div>
                <div class="admin-top-actions">
                    <button class="button button-ghost button-small theme-toggle" type="button" data-theme-toggle>Light Mode</button>
                    <a class="button button-ghost button-small" href="<?= e(url('/')) ?>" target="_blank" rel="noopener">View Store</a>
                    <form action="<?= e(url('/logout')) ?>" method="post">
                        <?= csrf_field() ?>
                        <button class="button button-small" type="submit">Sign Out</button>
                    </form>
                </div>
            </header>
            <?php View::partial('partials/flash', compact('flashMessages')); ?>
            <main id="main" class="admin-main">
                <?php require $templatePath; ?>
            </main>
        </div>
    </div>
<?php else: ?>
    <div class="announcement">
        <span><?= e($config->get('business.announcement')) ?></span>
        <span class="announcement-detail"><?= e($config->get('business.hours')) ?></span>
    </div>
    <header class="site-header">
        <div class="container nav-wrap">
            <a class="brand" href="<?= e(url('/')) ?>" aria-label="<?= e($businessName) ?> home">
                <span class="brand-mark">
                    <img src="<?= e(asset('assets/images/fat-bottom-grille-logo.jpg')) ?>" alt="">
                </span>
                <span class="brand-copy">
                    <strong><?= e($businessName) ?></strong>
                    <small>Keyser, West Virginia</small>
                </span>
            </a>
            <button class="nav-toggle" type="button" aria-expanded="false" aria-controls="site-nav">
                <span></span><span></span><span></span>
                <span class="sr-only">Toggle navigation</span>
            </button>
            <nav class="site-nav" id="site-nav" aria-label="Main navigation">
                <a class="<?= active_path('/') ?>" href="<?= e(url('/')) ?>">Home</a>
                <a class="<?= active_path('/menu') ?>" href="<?= e(url('/menu')) ?>">Order Online</a>
                <?php if ($currentUser): ?>
                    <?php if (in_array($currentUser['role'], ['admin', 'manager', 'staff'], true)): ?>
                        <a href="<?= e(url('/admin')) ?>">Dashboard</a>
                    <?php endif; ?>
                    <a class="<?= active_path('/account') ?>" href="<?= e(url('/account')) ?>">My Account</a>
                <?php else: ?>
                    <a class="<?= active_path('/login') ?>" href="<?= e(url('/login')) ?>">Sign In</a>
                <?php endif; ?>
                <button class="theme-toggle nav-theme-toggle" type="button" data-theme-toggle>Light Mode</button>
                <a class="cart-link" href="<?= e(url('/cart')) ?>">
                    Your Order
                    <span class="cart-count"><?= (int) ($currentCart['item_count'] ?? 0) ?></span>
                </a>
            </nav>
        </div>
    </header>
    <?php View::partial('partials/flash', compact('flashMessages')); ?>
    <main id="main">
        <?php require $templatePath; ?>
    </main>
    <footer class="site-footer">
        <div class="container footer-grid">
            <div>
                <div class="footer-brand"><?= e($businessName) ?></div>
                <p>Good food, generous portions, and a seat at the table in Keyser.</p>
            </div>
            <div>
                <h2>Visit</h2>
                <address>
                    <?= e($config->get('business.street')) ?><br>
                    <?= e($config->get('business.city')) ?>, <?= e($config->get('business.state')) ?>
                    <?= e($config->get('business.postal_code')) ?>
                </address>
            </div>
            <div>
                <h2>Get In Touch</h2>
                <?php if ($config->get('business.phone')): ?>
                    <a href="tel:<?= e(preg_replace('/[^0-9+]/', '', (string) $config->get('business.phone'))) ?>">
                        <?= e($config->get('business.phone')) ?>
                    </a>
                <?php endif; ?>
                <?php if ($config->get('business.email')): ?>
                    <a href="mailto:<?= e($config->get('business.email')) ?>"><?= e($config->get('business.email')) ?></a>
                <?php endif; ?>
                <?php if (!$config->get('business.phone') && !$config->get('business.email')): ?>
                    <p>Contact details coming soon.</p>
                <?php endif; ?>
            </div>
            <div>
                <h2>Hours</h2>
                <p><?= e($config->get('business.hours')) ?></p>
            </div>
        </div>
        <div class="container footer-bottom">
            <span>&copy; <?= date('Y') ?> <?= e($businessName) ?></span>
            <span>410 W Piedmont St, Keyser, WV</span>
        </div>
    </footer>
<?php endif; ?>

<script src="<?= e(asset('assets/app.js')) ?>" defer></script>
</body>
</html>
