<?php
$s = settings();
$cur = $s['currency'] ?? '₺';
?>
<div class="page-hero">
    <div class="container">
        <a class="back-link" href="<?= e(url('/')) ?>">← Anasayfa</a>
        <h1 class="page-title">Menü</h1>
        <p class="page-sub"><?= e($s['business_name'] ?? '') ?></p>
    </div>
</div>

<!-- Kategori hızlı gezinme -->
<nav class="cat-nav" id="catNav">
    <div class="container cat-nav-inner">
        <?php foreach ($categories as $c): ?>
            <a href="#cat-<?= (int)$c['id'] ?>" class="cat-nav-item"><?= e($c['name']) ?></a>
        <?php endforeach; ?>
    </div>
</nav>

<div class="container section">
    <?php foreach ($categories as $c): ?>
        <section class="menu-cat" id="cat-<?= (int)$c['id'] ?>">
            <div class="menu-cat-head reveal">
                <h2><?= e($c['name']) ?></h2>
                <?php if (!empty($c['description'])): ?><p><?= e($c['description']) ?></p><?php endif; ?>
            </div>
            <div class="product-list">
                <?php foreach (($byCat[$c['id']] ?? []) as $p): ?>
                    <a class="product-row reveal" href="<?= e(url('urun/'.$p['slug'])) ?>">
                        <div class="pr-media">
                            <?php if (!empty($p['video'])): ?>
                                <video muted loop playsinline webkit-playsinline preload="metadata" poster="<?= e(media_poster($p['image'] ?? null)) ?>"><source src="<?= e(media_url($p['video'])) ?>" type="video/mp4"></video>
                            <?php elseif (!empty($p['image'])): ?>
                                <img loading="lazy" decoding="async" src="<?= e(media_poster($p['image'])) ?>" alt="<?= e($p['name']) ?>">
                            <?php else: ?>
                                <span class="pr-emoji">🍽️</span>
                            <?php endif; ?>
                        </div>
                        <div class="pr-body">
                            <h3><?= e($p['name']) ?></h3>
                            <?php if (!empty($p['description'])): ?>
                                <p class="pr-desc"><?= e(mb_strimwidth($p['description'],0,90,'…')) ?></p>
                            <?php endif; ?>
                            <div class="pr-meta">
                                <?php if (!empty($p['calories'])): ?><span class="mini">🔥 <?= (int)$p['calories'] ?> kcal</span><?php endif; ?>
                                <?php if (!empty($p['allergens'])): ?><span class="mini">⚠️ <?= e($p['allergens']) ?></span><?php endif; ?>
                            </div>
                        </div>
                        <div class="pr-price"><?= e(money($p['price'], $cur)) ?></div>
                    </a>
                <?php endforeach; ?>
                <?php if (empty($byCat[$c['id']])): ?>
                    <p class="empty-note">Bu kategoride henüz ürün yok.</p>
                <?php endif; ?>
            </div>
        </section>
    <?php endforeach; ?>
</div>
