<?php
// Ensure we have necessary variables
$websiteSettings = $websiteSettings ?? [];
$activeMenu = $activeMenu ?? 'home';

// Format tanggal Indonesia function (only declare if not exists)
if (!function_exists('formatTanggalIndonesia')) {
    function formatTanggalIndonesia($timestamp = null) {
        $hari = array('Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu');
        $bulan = array(1 => 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');
        
        $time = $timestamp ? $timestamp : time();
        $namaHari = $hari[date('w', $time)];
        $tanggal = date('j', $time);
        $namaBulan = $bulan[date('n', $time)];
        $tahun = date('Y', $time);
        
        return $namaHari . ', ' . $tanggal . ' ' . $namaBulan . ' ' . $tahun;
    }
}
?>

<!-- Top Info Bar -->
<div class="top-info-bar">
    <div class="top-info-content">
        <!-- Desktop Menu (Hidden on Mobile) -->
        <div class="top-info-left">
            <i class="fab fa-android"></i>
            <a href="<?php echo $websiteSettings['download_app_link'] ?? '#'; ?>" class="top-link" target="_blank">DOWNLOAD APLIKASI TOGEL</a>
            <span class="separator">|</span>
            <a href="<?php echo $websiteSettings['register_member_link'] ?? '#'; ?>" class="top-link" target="_blank">DAFTAR JADI MEMBER</a>
            <span class="separator">|</span>
            <i class="fab fa-telegram"></i>
            <a href="<?php echo $websiteSettings['telegram_link'] ?? '#'; ?>" class="top-link" target="_blank">TELEGRAM</a>
            <span class="separator">|</span>
            <i class="fas fa-comments"></i>
            <a href="<?php echo $websiteSettings['livechat_link'] ?? '#'; ?>" class="top-link" target="_blank">LIVECHAT</a>
        </div>
        
        <!-- WhatsApp -->
        <div class="top-info-right">
            <a href="https://wa.me/<?php echo $websiteSettings['whatsapp_number'] ?? '6281389114046'; ?>" class="whatsapp-btn" target="_blank">
                <i class="fab fa-whatsapp"></i> WHATSAPP
            </a>
            <div class="current-time">
                <span id="header-date"><?php echo strtoupper(formatTanggalIndonesia()); ?></span>
            </div>
        </div>
        
        <!-- Mobile Menu Stack -->
        <div class="mobile-menu-stack">
            <!-- Row 1: Download App -->
            <div class="menu-row">
                <i class="fab fa-android"></i>
                <a href="<?php echo $websiteSettings['download_app_link'] ?? '#'; ?>" class="top-link" target="_blank">DOWNLOAD APLIKASI TOGEL</a>
            </div>
            
            <!-- Row 2: Three buttons -->
            <div class="menu-row">
                <a href="<?php echo $websiteSettings['register_member_link'] ?? '#'; ?>" class="top-link-small" target="_blank">DAFTAR JADI MEMBER</a>
                <span class="separator">|</span>
                <i class="fab fa-telegram"></i>
                <a href="<?php echo $websiteSettings['telegram_link'] ?? '#'; ?>" class="top-link-small" target="_blank">TELEGRAM</a>
                <span class="separator">|</span>
                <i class="fas fa-comments"></i>
                <a href="<?php echo $websiteSettings['livechat_link'] ?? '#'; ?>" class="top-link-small" target="_blank">LIVECHAT</a>
            </div>
        </div>
    </div>
</div>

<!-- Main Navigation -->
<div class="main-navigation">
    <div class="nav-container">
        <div class="nav-left">
            <a href="index.php" class="logo">
                <?php $siteLogoPath = $websiteSettings['site_logo'] ?? 'assets/logos/site_logo_1759911230.png'; ?>
                <img src="<?php echo $siteLogoPath; ?>?v=<?php echo pm_asset_version($siteLogoPath); ?>" alt="Inatogel" class="logo-img" loading="eager" decoding="async">
            </a>
        </div>
        <div class="nav-center">
            <nav class="nav-menu">
                <a href="index.php" class="nav-link <?php echo $activeMenu === 'home' ? 'active' : ''; ?>">
                    <i class="fas fa-home"></i> Home
                </a>
                <a href="livedraw.php" class="nav-link <?php echo $activeMenu === 'livedraw' ? 'active' : ''; ?>">
                    <i class="fas fa-broadcast-tower"></i> Live Draw
                </a>
                <a href="prediksi.php" class="nav-link <?php echo $activeMenu === 'prediksi' ? 'active' : ''; ?>">
                    <i class="fas fa-chart-line"></i> Prediksi Togel
                </a>
                <a href="<?php echo $websiteSettings['slot_gacor_link'] ?? '#'; ?>" class="nav-link <?php echo $activeMenu === 'slot' ? 'active' : ''; ?>" target="_blank">
                    <i class="fas fa-dice"></i> Slot Gacor
                </a>
                
                <!-- Desktop Dropdowns, Mobile Direct Links -->
                <div class="nav-dropdown desktop-only">
                    <a href="#" class="nav-link dropdown-toggle <?php echo $activeMenu === 'alat' ? 'active' : ''; ?>">
                        <i class="fas fa-tools"></i> Alat Togel <i class="fas fa-chevron-down"></i>
                    </a>
                    <div class="dropdown-menu">
                        <a href="jadwal-togel.php" class="dropdown-item">
                            <i class="fas fa-calendar"></i> Jadwal Togel
                        </a>
                        <a href="bbfs-generator.php" class="dropdown-item">
                            <i class="fas fa-random"></i> BBFS Generator
                        </a>
                        <a href="buku-mimpi.php" class="dropdown-item">
                            <i class="fas fa-book"></i> Buku Mimpi
                        </a>
                        <a href="paito-warna.php" class="dropdown-item">
                            <i class="fas fa-palette"></i> Paito Warna
                        </a>
                        <a href="konversi-toto-sgp.php" class="dropdown-item">
                            <i class="fas fa-exchange-alt"></i> Konversi Toto SGP
                        </a>
                    </div>
                </div>
                
                <!-- Mobile Direct Menu Items -->
                <a href="jadwal-togel.php" class="nav-link mobile-only <?php echo $activeMenu === 'jadwal' ? 'active' : ''; ?>">
                    <i class="fas fa-calendar"></i> Jadwal Togel
                </a>
                <a href="bbfs-generator.php" class="nav-link mobile-only <?php echo $activeMenu === 'bbfs' ? 'active' : ''; ?>">
                    <i class="fas fa-random"></i> Bbfs Generator
                </a>
                <a href="buku-mimpi.php" class="nav-link mobile-only <?php echo $activeMenu === 'mimpi' ? 'active' : ''; ?>">
                    <i class="fas fa-book"></i> Buku Mimpi
                </a>
                <a href="paito-warna.php" class="nav-link mobile-only <?php echo $activeMenu === 'paito' ? 'active' : ''; ?>">
                    <i class="fas fa-palette"></i> Paito Togel Warna
                </a>
                <a href="konversi-toto-sgp.php" class="nav-link mobile-only">
                    <i class="fas fa-exchange-alt"></i> Konversi Toto Sgp
                </a>
                
                <a href="data-result.php" class="nav-link <?php echo $activeMenu === 'data' ? 'active' : ''; ?>">
                    <i class="fas fa-database"></i> Data Result
                </a>
                
                <!-- Mobile More Items -->
                <a href="bukti-jackpot.php" class="nav-link mobile-only <?php echo $activeMenu === 'bukti' ? 'active' : ''; ?>">
                    <i class="fas fa-trophy"></i> Bukti Jackpot
                </a>
                <a href="<?php echo $websiteSettings['promo_link'] ?? '#'; ?>" class="nav-link mobile-only" <?php echo !empty($websiteSettings['promo_link']) && $websiteSettings['promo_link'] !== '#' ? 'target="_blank"' : ''; ?>>
                    <i class="fas fa-gift"></i> Promosi
                </a>
                <a href="keluhan.php" class="nav-link mobile-only <?php echo $activeMenu === 'keluhan' ? 'active' : ''; ?>">
                    <i class="fas fa-comments"></i> Keluhan
                </a>
                <a href="#" class="nav-link mobile-only">
                    <i class="fas fa-book-open"></i> Panduan
                </a>
                
                <!-- Desktop More Dropdown -->
                <div class="nav-dropdown desktop-only">
                    <a href="#" class="nav-link dropdown-toggle <?php echo $activeMenu === 'more' ? 'active' : ''; ?>">
                        <i class="fas fa-ellipsis-h"></i> More <i class="fas fa-chevron-down"></i>
                    </a>
                    <div class="dropdown-menu">
                        <a href="<?php echo $websiteSettings['promo_link'] ?? '#'; ?>" class="dropdown-item" <?php echo !empty($websiteSettings['promo_link']) && $websiteSettings['promo_link'] !== '#' ? 'target="_blank"' : ''; ?>>
                            <i class="fas fa-gift"></i> Promosi
                        </a>
                        <a href="bukti-jackpot.php" class="dropdown-item">
                            <i class="fas fa-trophy"></i> Bukti Jackpot
                        </a>
                        <a href="keluhan.php" class="dropdown-item">
                            <i class="fas fa-comments"></i> Keluhan
                        </a>
                        <a href="#" class="dropdown-item">
                            <i class="fas fa-book-open"></i> Panduan
                        </a>
                        <a href="history.php" class="dropdown-item">
                            <i class="fas fa-history"></i> History Result
                        </a>
                    </div>
                </div>
            </nav>
        </div>
        <div class="nav-right">
            <button class="mobile-toggle" onclick="toggleMobileMenu()">
                <i class="fas fa-bars"></i>
            </button>
        </div>
    </div>
</div>

<!-- Marquee Text -->
<div class="marquee-section">
    <div class="marquee-container">
        <div class="marquee-text <?php echo $websiteSettings['marquee_speed'] ?? 'slow'; ?>">
            <?php 
            // Get marquee text from website settings
            $marqueeText = '';
            if (!empty($websiteSettings['marquee_text'])) {
                $marqueeText = $websiteSettings['marquee_text'];
            } elseif (!empty($websiteSettings['welcome_text'])) {
                $marqueeText = $websiteSettings['welcome_text'];
            } else {
                // Fallback text
                $marqueeText = 'Selamat datang di Inatogel Situs Games Online Terbaik dan Terpercaya di Indonesia • Promo Menarik Setiap Hari • Bonus New Member 100% • RTP Live Tertinggi';
            }
            echo htmlspecialchars($marqueeText);
            ?>
        </div>
    </div>
</div>

<!-- Banner Section -->
<div class="banner-section">
    <div class="banner-container">
        <div class="banner-grid">
            <?php 
            // Force show 3 banners with fallback
            $defaultBanners = [
                1 => 'assets/banners/slide_1_1759306244.webp',
                2 => 'assets/banners/slide_2_1759306253.webp', 
                3 => 'assets/banners/slide_3_1759306260.webp'
            ];
            
            for ($i = 1; $i <= 3; $i++): 
                $bannerImage = !empty($websiteSettings["banner_{$i}_image"]) ? $websiteSettings["banner_{$i}_image"] : $defaultBanners[$i];
                $bannerLink = $websiteSettings["banner_{$i}_link"] ?? '#';
                $tinyPlaceholder = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
            ?>
                <div class="banner-item">
                    <a href="<?php echo $bannerLink; ?>" target="_blank">
                        <?php if ($i === 1): ?>
                            <img src="<?php echo $bannerImage; ?>" alt="Banner <?php echo $i; ?> - Promo Togel Online" loading="eager">
                        <?php else: ?>
                            <img src="<?php echo $tinyPlaceholder; ?>" data-src="<?php echo $bannerImage; ?>" alt="Banner <?php echo $i; ?> - Promo Togel Online" class="lazy-placeholder">
                        <?php endif; ?>
                    </a>
                </div>
            <?php endfor; ?>
        </div>
    </div>
</div>

<!-- Action Buttons -->
<div class="action-buttons-section">
    <div class="action-buttons-container">
        <a href="<?php echo $websiteSettings['login_link'] ?? '#'; ?>" class="action-btn login" target="_blank">
            <i class="fas fa-sign-in-alt"></i>
            <span>LOGIN</span>
        </a>
        <a href="<?php echo $websiteSettings['promo_link'] ?? '#'; ?>" class="action-btn promo" target="_blank">
            <i class="fas fa-gift"></i>
            <span>PROMO</span>
        </a>
        <a href="<?php echo $websiteSettings['slot_gacor_link'] ?? '#'; ?>" class="action-btn rtp" target="_blank">
            <i class="fas fa-chart-bar"></i>
            <span>RTP SLOT</span>
        </a>
        <a href="bukti-jackpot.php" class="action-btn jackpot">
            <i class="fas fa-trophy"></i>
            <span>BUKTI JACKPOT</span>
        </a>
    </div>
</div>

