<!-- Footer Section -->
<footer class="main-footer">
    <div class="footer-container">
        <div class="footer-content">
            <div class="footer-section">
                <h4>Tentang <?php echo $websiteSettings['footer_company_name'] ?? 'Inatogel'; ?></h4>
                <p><?php echo $websiteSettings['footer_description'] ?? 'Situs Togel Live Draw Terpercaya dengan prediksi angka jitu dan data result terlengkap. Kami menyediakan layanan terbaik untuk para pecinta togel Indonesia.'; ?></p>
                <div class="footer-social">
                    <?php if (!empty($websiteSettings['telegram_link']) && $websiteSettings['telegram_link'] !== '#'): ?>
                    <a href="<?php echo $websiteSettings['telegram_link']; ?>" target="_blank" rel="noopener" aria-label="Telegram">
                        <i class="fab fa-telegram"></i>
                    </a>
                    <?php endif; ?>
                    <?php if (!empty($websiteSettings['whatsapp_number'])): ?>
                    <a href="https://wa.me/<?php echo $websiteSettings['whatsapp_number']; ?>" target="_blank" rel="noopener" aria-label="WhatsApp">
                        <i class="fab fa-whatsapp"></i>
                    </a>
                    <?php endif; ?>
                    <?php if (!empty($websiteSettings['facebook_link']) && $websiteSettings['facebook_link'] !== '#'): ?>
                    <a href="<?php echo $websiteSettings['facebook_link']; ?>" target="_blank" rel="noopener" aria-label="Facebook">
                        <i class="fab fa-facebook"></i>
                    </a>
                    <?php endif; ?>
                    <?php if (!empty($websiteSettings['instagram_link']) && $websiteSettings['instagram_link'] !== '#'): ?>
                    <a href="<?php echo $websiteSettings['instagram_link']; ?>" target="_blank" rel="noopener" aria-label="Instagram">
                        <i class="fab fa-instagram"></i>
                    </a>
                    <?php endif; ?>
                    <?php if (!empty($websiteSettings['twitter_link']) && $websiteSettings['twitter_link'] !== '#'): ?>
                    <a href="<?php echo $websiteSettings['twitter_link']; ?>" target="_blank" rel="noopener" aria-label="Twitter">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <?php endif; ?>
                    <?php if (!empty($websiteSettings['youtube_link']) && $websiteSettings['youtube_link'] !== '#'): ?>
                    <a href="<?php echo $websiteSettings['youtube_link']; ?>" target="_blank" rel="noopener" aria-label="YouTube">
                        <i class="fab fa-youtube"></i>
                    </a>
                    <?php endif; ?>
                </div>
            </div>
            
            <div class="footer-section">
                <h4>Menu Utama</h4>
                <ul class="footer-menu">
                    <li><a href="index.php">Home</a></li>
                    <li><a href="prediksi.php">Prediksi Togel</a></li>
                    <li><a href="data-result.php">Data Result</a></li>
                    <li><a href="paito-warna.php">Paito Warna</a></li>
                    <li><a href="buku-mimpi.php">Buku Mimpi</a></li>
                    <li><a href="jadwal-togel.php">Jadwal Togel</a></li>
                </ul>
            </div>
            
            <div class="footer-section">
                <h4>Tools & Generator</h4>
                <ul class="footer-menu">
                    <li><a href="bbfs-generator.php">BBFS Generator</a></li>
                    <li><a href="history.php">History Result</a></li>
                    <li><a href="konversi-toto-sgp.php">Konversi Toto SGP</a></li>
                    <li><a href="#">Live Draw</a></li>
                </ul>
            </div>
            
            <div class="footer-section">
                <h4>Kontak & Support</h4>
                <div class="footer-contact">
                    <?php if (!empty($websiteSettings['footer_address'])): ?>
                    <div class="contact-item">
                        <i class="fas fa-map-marker-alt"></i>
                        <span><?php echo $websiteSettings['footer_address']; ?></span>
                    </div>
                    <?php endif; ?>
                    <div class="contact-item">
                        <i class="fas fa-phone"></i>
                        <span><?php echo $websiteSettings['footer_phone'] ?? 'Customer Service 24/7'; ?></span>
                    </div>
                    <div class="contact-item">
                        <i class="fas fa-envelope"></i>
                        <span><a href="mailto:<?php echo $websiteSettings['contact_email'] ?? 'support@inatogel.com'; ?>" style="color: inherit; text-decoration: none;"><?php echo $websiteSettings['contact_email'] ?? 'support@inatogel.com'; ?></a></span>
                    </div>
                    <div class="contact-item">
                        <i class="fab fa-whatsapp"></i>
                        <span>WhatsApp: <?php echo $websiteSettings['whatsapp_display'] ?? '+62 813-8911-4046'; ?></span>
                    </div>
                    <?php if (!empty($websiteSettings['footer_business_hours'])): ?>
                    <div class="contact-item">
                        <i class="fas fa-clock"></i>
                        <span><?php echo $websiteSettings['footer_business_hours']; ?></span>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <div class="footer-bottom">
            <div class="footer-copyright">
                <p>&copy; <?php echo date('Y'); ?> <?php echo $websiteSettings['footer_company_name'] ?? 'Inatogel'; ?>. <?php echo $websiteSettings['footer_copyright_text'] ?? 'All rights reserved. | Situs Togel Terpercaya Indonesia'; ?></p>
                <div class="footer-disclaimer">
                    <small>
                        <?php echo $websiteSettings['footer_disclaimer'] ?? 'Disclaimer: Kami tidak bertanggung jawab atas kerugian yang ditimbulkan dari penggunaan prediksi ini. Bermain judi dapat menyebabkan kecanduan. Harap bermain dengan bijak dan bertanggung jawab.'; ?>
                    </small>
                </div>
            </div>
            <div class="footer-links">
                <a href="<?php echo $websiteSettings['footer_terms_link'] ?? '#'; ?>">Syarat & Ketentuan</a>
                <span>|</span>
                <a href="<?php echo $websiteSettings['footer_privacy_link'] ?? '#'; ?>">Kebijakan Privasi</a>
                <span>|</span>
                <a href="<?php echo $websiteSettings['footer_guide_link'] ?? '#'; ?>">Panduan</a>
                <span>|</span>
                <a href="<?php echo $websiteSettings['footer_contact_link'] ?? '#'; ?>">Kontak</a>
            </div>
        </div>
    </div>
</footer>

<!-- Structured Data for SEO -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "name": "<?php echo $websiteSettings['footer_company_name'] ?? 'Inatogel'; ?>",
  "description": "<?php echo strip_tags($websiteSettings['footer_description'] ?? 'Situs Togel Live Draw Terpercaya dengan prediksi angka jitu dan data result terlengkap.'); ?>",
  "url": "<?php echo 'https://' . $_SERVER['HTTP_HOST']; ?>",
  <?php if (!empty($websiteSettings['footer_address'])): ?>
  "address": {
    "@type": "PostalAddress",
    "addressLocality": "<?php echo $websiteSettings['footer_address']; ?>"
  },
  <?php endif; ?>
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "<?php echo $websiteSettings['whatsapp_display'] ?? '+62 813-8911-4046'; ?>",
    "contactType": "Customer Service",
    "email": "<?php echo $websiteSettings['contact_email'] ?? 'support@inatogel.com'; ?>",
    "availableLanguage": "Indonesian",
    "hoursAvailable": "24/7"
  },
  "sameAs": [
    <?php 
    $socialLinks = [];
    if (!empty($websiteSettings['facebook_link']) && $websiteSettings['facebook_link'] !== '#') 
        $socialLinks[] = '"' . $websiteSettings['facebook_link'] . '"';
    if (!empty($websiteSettings['instagram_link']) && $websiteSettings['instagram_link'] !== '#') 
        $socialLinks[] = '"' . $websiteSettings['instagram_link'] . '"';
    if (!empty($websiteSettings['twitter_link']) && $websiteSettings['twitter_link'] !== '#') 
        $socialLinks[] = '"' . $websiteSettings['twitter_link'] . '"';
    if (!empty($websiteSettings['youtube_link']) && $websiteSettings['youtube_link'] !== '#') 
        $socialLinks[] = '"' . $websiteSettings['youtube_link'] . '"';
    if (!empty($websiteSettings['telegram_link']) && $websiteSettings['telegram_link'] !== '#') 
        $socialLinks[] = '"' . $websiteSettings['telegram_link'] . '"';
    echo implode(',', $socialLinks);
    ?>
  ]
}
</script>

<!-- Back to Top Button -->
<button class="back-to-top" id="backToTop">
    <i class="fas fa-arrow-up"></i>
</button>

<!-- JavaScript Libraries and Custom Scripts -->
<script>
// Mobile Menu Toggle
function toggleMobileMenu() {
    const navCenter = document.querySelector('.nav-center');
    const mobileButton = document.querySelector('.mobile-menu-toggle');
    
    if (navCenter) {
        navCenter.classList.toggle('show-mobile');
        mobileButton.classList.toggle('active');
    }
}

// Hide loading screen with multiple fallbacks
function hideLoadingScreen() {
    const loadingScreen = document.getElementById('loadingScreen');
    if (loadingScreen) {
        loadingScreen.style.opacity = '0';
        loadingScreen.style.transition = 'opacity 0.3s ease';
        setTimeout(() => {
            loadingScreen.style.display = 'none';
        }, 300);
    }
}

// Multiple event listeners to ensure loading screen hides
window.addEventListener('load', hideLoadingScreen);
window.addEventListener('DOMContentLoaded', function() {
    // Fallback: hide loading screen after 2 seconds regardless
    setTimeout(hideLoadingScreen, 2000);
});

// Immediate fallback for very fast loading
document.addEventListener('readystatechange', function() {
    if (document.readyState === 'complete') {
        setTimeout(hideLoadingScreen, 500);
    }
});

// Update time display in top bar
function updateTopBarTime() {
    const now = new Date();
    const days = ['MINGGU', 'SENIN', 'SELASA', 'RABU', 'KAMIS', 'JUMAT', 'SABTU'];
    const months = ['JAN', 'FEB', 'MAR', 'APR', 'MEI', 'JUN', 'JUL', 'AGU', 'SEP', 'OKT', 'NOV', 'DES'];
    
    const dayName = days[now.getDay()];
    const date = String(now.getDate()).padStart(2, '0');
    const month = months[now.getMonth()];
    const year = now.getFullYear();
    const hours = String(now.getHours()).padStart(2, '0');
    const minutes = String(now.getMinutes()).padStart(2, '0');
    const seconds = String(now.getSeconds()).padStart(2, '0');
    
    const timeString = `${dayName}, ${date} ${month} ${year} | ${hours}:${minutes}:${seconds} |`;
    
    const timeElement = document.querySelector('.top-info-right span');
    if (timeElement) {
        timeElement.innerHTML = `<i class="fas fa-clock"></i> ${timeString}`;
    }
}

// Update time display
function updateTime() {
    const now = new Date();
    const options = { 
        weekday: 'long', 
        year: 'numeric', 
        month: 'long', 
        day: 'numeric',
        timeZone: 'Asia/Jakarta'
    };
    const dateString = now.toLocaleDateString('id-ID', options);
    const timeString = now.toLocaleTimeString('id-ID', {
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        timeZone: 'Asia/Jakarta'
    });
    
    const headerDate = document.getElementById('header-date');
    if (headerDate) {
        headerDate.textContent = `${dateString.toUpperCase()} ( ${timeString} )`;
    }
}

// Update time every second
setInterval(updateTime, 1000);
setInterval(updateTopBarTime, 1000);
updateTopBarTime(); // Initial call
updateTime(); // Initial call

// Countdown timer functionality
function initCountdownTimers() {
    document.querySelectorAll('.countdown-timer').forEach(timer => {
        const targetTime = timer.getAttribute('data-target');
        if (!targetTime) return;
        
        const updateTimer = () => {
            const now = new Date().getTime();
            const target = new Date(targetTime).getTime();
            const distance = target - now;
            
            if (distance < 0) {
                timer.textContent = "CLOSED";
                timer.classList.add('expired');
                return;
            }
            
            const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
            const seconds = Math.floor((distance % (1000 * 60)) / 1000);
            
            timer.textContent = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
        };
        
        updateTimer();
        setInterval(updateTimer, 1000);
    });
}

// Initialize countdown timers
initCountdownTimers();

// Filter functionality
document.addEventListener('DOMContentLoaded', function() {
    // Filter functionality
    document.querySelectorAll('.filter-btn').forEach(btn => {
        btn.addEventListener('click', function() {
            // Remove active class from all buttons
            document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
            // Add active class to clicked button
            this.classList.add('active');
            
            const filterValue = this.getAttribute('data-filter');
            const marketCards = document.querySelectorAll('.market-card');
            
            marketCards.forEach(card => {
                const marketName = card.querySelector('.market-name');
                if (!marketName) return;
                
                if (filterValue === '' || marketName.textContent.includes(filterValue)) {
                    card.style.display = 'block';
                    card.style.animation = 'fadeIn 0.3s ease-in-out';
                } else {
                    card.style.display = 'none';
                }
            });
        });
    });
    
    // Clear filter
    const clearFilterBtn = document.querySelector('.clear-filter-btn');
    if (clearFilterBtn) {
        clearFilterBtn.addEventListener('click', function() {
            document.querySelectorAll('.filter-btn').forEach(btn => btn.classList.remove('active'));
            document.querySelector('.filter-btn[data-filter=""]').classList.add('active');
            document.querySelectorAll('.market-card').forEach(card => {
                card.style.display = 'block';
                card.style.animation = 'fadeIn 0.3s ease-in-out';
            });
        });
    }
    
    // Mobile menu toggle
    const mobileMenuToggle = document.getElementById('mobile-menu-toggle');
    if (mobileMenuToggle) {
        mobileMenuToggle.addEventListener('click', function() {
            const navCenter = document.querySelector('.nav-center');
            if (navCenter) {
                navCenter.classList.toggle('show-mobile');
            }
        });
    }
    
    // Back to top functionality
    const backToTopBtn = document.getElementById('backToTop');
    if (backToTopBtn) {
        window.addEventListener('scroll', function() {
            if (window.pageYOffset > 300) {
                backToTopBtn.classList.add('show');
            } else {
                backToTopBtn.classList.remove('show');
            }
        });
        
        backToTopBtn.addEventListener('click', function() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        });
    }
    
    // Add smooth hover effects to market cards
    document.querySelectorAll('.market-card').forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-5px) scale(1.02)';
        });
        
        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0) scale(1)';
        });
    });
    
    // Add click effects to buttons
    document.querySelectorAll('.action-btn, .menu-btn, .market-btn').forEach(btn => {
        btn.addEventListener('click', function(e) {
            // Create ripple effect
            const ripple = document.createElement('span');
            const rect = this.getBoundingClientRect();
            const size = Math.max(rect.width, rect.height);
            const x = e.clientX - rect.left - size / 2;
            const y = e.clientY - rect.top - size / 2;
            
            ripple.style.width = ripple.style.height = size + 'px';
            ripple.style.left = x + 'px';
            ripple.style.top = y + 'px';
            ripple.classList.add('ripple');
            ripple.style.cssText += `
                position: absolute;
                border-radius: 50%;
                background: rgba(255, 255, 255, 0.3);
                transform: scale(0);
                animation: ripple 0.6s linear;
                pointer-events: none;
            `;
            
            // Add ripple animation keyframes if not exists
            if (!document.querySelector('#ripple-animation')) {
                const style = document.createElement('style');
                style.id = 'ripple-animation';
                style.textContent = `
                    @keyframes ripple {
                        to { transform: scale(4); opacity: 0; }
                    }
                `;
                document.head.appendChild(style);
            }
            
            this.style.position = 'relative';
            this.style.overflow = 'hidden';
            this.appendChild(ripple);
            
            setTimeout(() => {
                ripple.remove();
            }, 600);
        });
    });
});

// Dropdown toggle function
function toggleDropdown(type) {
    // Remove active class from all nav buttons
    document.querySelectorAll('.nav-btn').forEach(btn => btn.classList.remove('active'));
    
    // Add active class to clicked button
    const clickedBtn = document.querySelector(`.${type}-btn`);
    if (clickedBtn) {
        clickedBtn.classList.add('active');
    }
    
    // Handle dropdown actions based on type
    switch(type) {
        case 'result':
            // Show result section or navigate to result page
            break;
        case 'prediksi':
            window.location.href = 'prediksi.php';
            break;
        case 'paito':
            window.location.href = 'paito-warna.php';
            break;
        case 'mimpi':
            window.location.href = 'buku-mimpi.php';
            break;
    }
}

// Add CSS for animations
const animationCSS = `
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(20px); }
        to { opacity: 1; transform: translateY(0); }
    }
    
    .back-to-top {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        background: linear-gradient(45deg, #ffd700, #ffed4a);
        color: #1a1a2e;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        font-size: 18px;
        box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
        transition: all 0.3s ease;
        opacity: 0;
        transform: translateY(100px);
        z-index: 1000;
    }
    
    .back-to-top.show {
        opacity: 1;
        transform: translateY(0);
    }
    
    .back-to-top:hover {
        transform: translateY(-5px);
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4);
    }
    
    @media (max-width: 768px) {
        .nav-center {
            display: none;
            position: absolute;
            top: 100%;
            left: 0;
            width: 100%;
            background: #34495e;
            flex-direction: column;
            padding: 20px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.3);
        }
        
        .nav-center.show-mobile {
            display: flex;
        }
    }
`;

// Add the CSS to the page
if (!document.querySelector('#dynamic-animations')) {
    const style = document.createElement('style');
    style.id = 'dynamic-animations';
    style.textContent = animationCSS;
    document.head.appendChild(style);
}
</script>

<!-- Hide Loading Screen -->
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Hide loading screen once page is loaded
    const loadingScreen = document.getElementById('loadingScreen');
    if (loadingScreen) {
        setTimeout(function() {
            loadingScreen.style.opacity = '0';
            setTimeout(function() {
                loadingScreen.style.display = 'none';
            }, 300);
        }, 500);
    }
});

// Banner hover effects
document.querySelectorAll('.banner-item').forEach(item => {
    item.addEventListener('mouseenter', function() {
        this.style.transform = 'translateY(-5px) scale(1.02)';
    });
    
    item.addEventListener('mouseleave', function() {
        this.style.transform = 'translateY(0) scale(1)';
    });
});

// Mobile Menu Toggle
function toggleMobileMenu() {
    const navCenter = document.querySelector('.nav-center');
    const overlay = document.querySelector('.mobile-menu-overlay') || createMobileOverlay();
    
    navCenter.classList.toggle('show-mobile');
    overlay.classList.toggle('show');
}

// Create mobile overlay if it doesn't exist
function createMobileOverlay() {
    const overlay = document.createElement('div');
    overlay.className = 'mobile-menu-overlay';
    overlay.onclick = function() {
        closeMobileMenu();
    };
    document.body.appendChild(overlay);
    return overlay;
}

// Close mobile menu
function closeMobileMenu() {
    const navCenter = document.querySelector('.nav-center');
    const overlay = document.querySelector('.mobile-menu-overlay');
    
    navCenter.classList.remove('show-mobile');
    if (overlay) overlay.classList.remove('show');
}

// Mobile Banner Slider
let currentMobileBanner = 0;
const mobileBanners = document.querySelectorAll('.banner-item');
const totalMobileBanners = mobileBanners.length;

function showMobileBanner(n) {
    mobileBanners.forEach(banner => banner.classList.remove('active'));
    
    if (n >= totalMobileBanners) currentMobileBanner = 0;
    if (n < 0) currentMobileBanner = totalMobileBanners - 1;
    
    if (mobileBanners[currentMobileBanner]) {
        mobileBanners[currentMobileBanner].classList.add('active');
    }
}

// Auto slide mobile banners every 4 seconds on mobile
if (window.innerWidth <= 768 && totalMobileBanners > 1) {
    // Show first banner initially
    if (mobileBanners[0]) mobileBanners[0].classList.add('active');
    
    setInterval(function() {
        currentMobileBanner++;
        showMobileBanner(currentMobileBanner);
    }, 4000);
}

// Theme toggle function
function toggleTheme() {
    document.body.classList.toggle('light-theme');
}

// Close mobile menu when clicking menu items
document.addEventListener('click', function(event) {
    if (event.target.classList.contains('nav-link') || event.target.classList.contains('dropdown-item')) {
        if (window.innerWidth <= 768) {
            closeMobileMenu();
        }
    }
});

// Also hide on window load as fallback
window.addEventListener('load', function() {
    const loadingScreen = document.getElementById('loadingScreen');
    if (loadingScreen) {
        loadingScreen.style.opacity = '0';
        setTimeout(function() {
            loadingScreen.style.display = 'none';
        }, 300);
    }
});
</script>

<!-- Winner Messages Generator -->
<script src="assets/js/winner-messages.js?v=<?php echo pm_asset_version('assets/js/winner-messages.js'); ?>" defer></script>

<!-- Responsive Banner Slider -->
<script src="assets/js/responsive-banner-slider.js?v=<?php echo pm_asset_version('assets/js/responsive-banner-slider.js'); ?>" defer></script>

<!-- Page Specific JavaScript -->
<?php if (isset($additionalJS)): ?>
    <?php foreach($additionalJS as $js): ?>
        <script src="<?php echo $js; ?>?v=<?php echo pm_asset_version($js); ?>" defer></script>
    <?php endforeach; ?>
<?php endif; ?>

</body>
</html>