<?php
$s = settings();
$biz = $s['business_name'] ?? 'Laos Coffee';
$logo = !empty($s['logo']) ? media_url($s['logo']) : '';
$heroVid = !empty($s['hero_video']) ? media_url($s['hero_video']) : '';
$heroPoster = !empty($s['hero_poster']) ? media_url($s['hero_poster']) : $logo;
$storyUrl = safe_url($s['instagram_story'] ?? ('https://www.instagram.com/stories/' . ltrim($s['instagram'] ?? 'laos.cekmekoy', '@') . '/'));
$showSplash = ($s['show_splash'] ?? '1') === '1';
$mapLink = safe_url($s['map_url'] ?? '');
$igUser = !empty($s['instagram']) ? ltrim($s['instagram'], '@') : '';
?>

<?php if ($showSplash): ?>
<!-- SPLASH — mobil / telefon içi karşılama -->
<div class="splash" id="splash">
    <div class="splash-bg">
        <?php if ($heroVid): ?>
            <video autoplay muted loop playsinline webkit-playsinline preload="<?= video_preload(true) ?>" poster="<?= e(media_poster($heroPoster)) ?>" disablePictureInPicture>
                <source src="<?= e($heroVid) ?>" type="video/mp4">
            </video>
        <?php endif; ?>
        <div class="splash-overlay"></div>
    </div>
    <div class="splash-inner">
        <?php if ($logo): ?>
            <img class="splash-logo" src="<?= e($logo) ?>" alt="<?= e($biz) ?>">
        <?php else: ?>
            <div class="splash-logo-text"><?= e($biz) ?></div>
        <?php endif; ?>
        <p class="splash-welcome"><?= e($s['welcome_title'] ?? 'Hoşgeldiniz') ?></p>
        <a href="<?= e(url('menu')) ?>" class="laos-btn laos-btn-glass" id="splashMenuBtn">Menüyü Göster <span class="splash-arrow">↓</span></a>
    </div>
    <nav class="laos-splash-dock" aria-label="Hızlı bağlantılar">
        <?php if ($mapLink): ?>
            <a href="<?= e($mapLink) ?>" target="_blank" rel="noopener" class="dock-btn" title="Konum">
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 21s7-4.5 7-11a7 7 0 1 0-14 0c0 6.5 7 11 7 11z"/><circle cx="12" cy="10" r="2.5"/></svg>
            </a>
        <?php endif; ?>
        <a href="<?= e(url('/')) ?>" class="dock-btn dock-logo<?= $logo ? '' : ' dock-text' ?>" title="<?= e($biz) ?>">
            <?php if ($logo): ?>
                <img src="<?= e($logo) ?>" alt="">
            <?php else: ?>
                <span><?= e(mb_substr($biz, 0, 1)) ?></span>
            <?php endif; ?>
        </a>
        <?php if ($igUser): ?>
            <a href="https://instagram.com/<?= e($igUser) ?>" target="_blank" rel="noopener" class="dock-btn" title="Instagram">
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/></svg>
            </a>
        <?php endif; ?>
        <a href="<?= e(url('menu')) ?>" class="dock-btn" title="Menü">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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>
        </a>
    </nav>
    <?php if ($storyUrl): ?>
        <a href="<?= e($storyUrl) ?>" target="_blank" rel="noopener" class="laos-story-link">Story'i İzle! ↗</a>
    <?php endif; ?>
</div>
<?php endif; ?>

<!-- ANA SAYFA (telefon içi mobil akış) -->
<main class="laos-page" id="mainPage">

    <!-- Mobil hero bandı (PC'de sol panelde gösterilir) -->
    <section class="laos-hero laos-mobile-only">
        <?php if ($heroVid): ?>
            <video class="laos-hero-vid" autoplay muted loop playsinline webkit-playsinline preload="<?= video_preload(true) ?>" poster="<?= e(media_poster($heroPoster)) ?>" disablePictureInPicture>
                <source src="<?= e($heroVid) ?>" type="video/mp4">
            </video>
        <?php endif; ?>
        <div class="laos-hero-overlay"></div>
        <div class="laos-hero-content">
            <span class="laos-badge"><?= e($s['hero_badge'] ?? "LAOS'A HOŞ GELDİNİZ") ?></span>
            <h1 class="laos-hero-title"><?= e($s['business_slogan'] ?? 'Menüyü açın, kahvenizi seçin.') ?></h1>
            <p class="laos-hero-sub"><?= e($s['hero_subtitle'] ?? '') ?></p>
            <div class="laos-chips">
                <?php if ($mapLink): ?>
                    <a href="<?= e($mapLink) ?>" target="_blank" rel="noopener" class="laos-chip">Konum</a>
                <?php endif; ?>
                <?php if ($igUser): ?>
                    <a href="https://instagram.com/<?= e($igUser) ?>" target="_blank" rel="noopener" class="laos-chip">Instagram</a>
                <?php endif; ?>
            </div>
        </div>
    </section>

    <!-- Logo + karşılama -->
    <section class="laos-welcome reveal">
        <div class="container laos-welcome-inner">
            <?php if ($logo): ?>
                <img class="laos-welcome-logo" src="<?= e($logo) ?>" alt="<?= e($biz) ?>">
            <?php endif; ?>
            <p class="laos-welcome-label"><?= e($s['welcome_title'] ?? 'Hoşgeldiniz') ?></p>
            <p class="laos-welcome-text"><?= e($s['welcome_text'] ?? '') ?></p>
            <a class="laos-btn laos-btn-main" href="<?= e(url('menu')) ?>">Menüyü Göster</a>
            <?php if ($storyUrl): ?>
                <a href="<?= e($storyUrl) ?>" target="_blank" rel="noopener" class="laos-btn laos-btn-story inline">Story'i İzle!</a>
            <?php endif; ?>
        </div>
    </section>

    <!-- KATEGORİLER -->
    <section class="laos-section" id="categories">
        <div class="container">
            <h2 class="laos-h2 reveal">Menü Kategorileri</h2>
        </div>
        <div class="laos-cat-stack">
            <?php foreach ($categories as $i => $c): ?>
                <a class="laos-cat-card reveal" href="<?= e(url('kategori/'.$c['slug'])) ?>" style="--d:<?= $i*80 ?>ms">
                    <div class="laos-cat-media">
                        <?php if (!empty($c['video'])): ?>
                            <video muted loop playsinline webkit-playsinline autoplay preload="<?= video_preload() ?>" poster="<?= e(media_poster($c['image'] ?? null)) ?>" disablePictureInPicture>
                                <source src="<?= e(media_url($c['video'])) ?>" type="video/mp4">
                            </video>
                        <?php elseif (!empty($c['image'])): ?>
                            <img loading="lazy" src="<?= e(media_url($c['image'])) ?>" alt="<?= e($c['name']) ?>">
                        <?php endif; ?>
                        <div class="laos-cat-shade"></div>
                    </div>
                    <div class="laos-cat-label">
                        <h3><?= e($c['name']) ?></h3>
                        <span class="laos-cat-arrow">→</span>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </section>

    <!-- ÖNE ÇIKAN 3 ÜRÜN -->
    <?php if (!empty($featured)): ?>
    <section class="laos-section laos-feat-section">
        <div class="container">
            <h2 class="laos-h2 reveal">Ne İçeceğine Karar<br>Veremedin Mi?</h2>
            <p class="laos-sub reveal">Senin için menüden üç ferah seçenek seçtik.</p>
        </div>
        <div class="laos-feat-row">
            <?php foreach ($featured as $p):
                $catLabel = $p['category_name'] ?? '';
                if ($p['slug'] === 'limonata' || stripos($p['name'], 'Limonata') !== false) {
                    $catLabel = 'Soft İçeceklerden';
                }
            ?>
                <a class="laos-feat-card reveal" href="<?= e(url('urun/'.$p['slug'])) ?>">
                    <div class="laos-feat-media">
                        <?php if (!empty($p['video'])): ?>
                            <video autoplay muted loop playsinline webkit-playsinline preload="<?= video_preload() ?>" poster="<?= e(media_poster($p['image'] ?? null)) ?>" disablePictureInPicture>
                                <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 endif; ?>
                        <div class="laos-feat-shade"></div>
                    </div>
                    <div class="laos-feat-body">
                        <?php if ($catLabel): ?><span class="laos-feat-cat"><?= e($catLabel) ?></span><?php endif; ?>
                        <h3><?= e($p['name']) ?></h3>
                        <span class="laos-price"><?= e(money($p['price'], $s['currency'] ?? '₺')) ?></span>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </section>
    <?php endif; ?>

    <!-- ETKİNLİKLER -->
    <?php if (!empty($events)): ?>
    <section class="laos-section">
        <div class="container">
            <h2 class="laos-h2 reveal">Etkinlikler</h2>
            <p class="laos-sub reveal"><?= e($biz) ?>'de sizi bekleyen özel etkinlikler.</p>
        </div>
        <div class="laos-events">
            <?php foreach ($events as $ev): ?>
                <article class="laos-event reveal">
                    <?php if (!empty($ev['video']) || !empty($ev['image'])): ?>
                        <div class="laos-event-media">
                            <?php if (!empty($ev['video'])): ?>
                                <video autoplay muted loop playsinline webkit-playsinline preload="<?= video_preload() ?>" poster="<?= e(media_poster($ev['image'] ?? null)) ?>" disablePictureInPicture><source src="<?= e(media_url($ev['video'])) ?>" type="video/mp4"></video>
                            <?php else: ?>
                                <img loading="lazy" decoding="async" src="<?= e(media_poster($ev['image'])) ?>" alt="<?= e($ev['title']) ?>">
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>
                    <div class="laos-event-body">
                        <?php if (!empty($ev['date_text'])): ?><span class="laos-event-date"><?= e($ev['date_text']) ?></span><?php endif; ?>
                        <h3><?= e($ev['title']) ?></h3>
                        <p><?= e($ev['description']) ?></p>
                        <div class="laos-event-foot">
                            <?php if (!empty($ev['price_text'])): ?><span class="laos-price"><?= e($ev['price_text']) ?></span><?php endif; ?>
                            <?php if (!empty($ev['badge'])): ?><span class="laos-pill"><?= e($ev['badge']) ?></span><?php endif; ?>
                        </div>
                        <?php $evLink = safe_url($ev['link_url'] ?? ''); if ($evLink): ?>
                            <a class="laos-btn laos-btn-sm" href="<?= e($evLink) ?>" target="_blank" rel="noopener"><?= e($ev['link_text'] ?: 'Detaylar') ?></a>
                        <?php endif; ?>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </section>
    <?php endif; ?>

</main>
