</main>

    <!-- Footer Ad -->
    <?php if (isset($settings['enable_ads']) && $settings['enable_ads'] == '1' && isset($settings['footer_ad']) && !empty($settings['footer_ad'])): ?>
    <div class="ad-container footer-ad">
        <?= $settings['footer_ad'] ?>
    </div>
    <?php endif; ?>

    <!-- Footer -->
    <footer class="bg-dark border-t border-gray-800 py-8">
        <div class="container mx-auto px-4">
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
                <div>
                    <h3 class="text-lg font-semibold mb-4">About Us</h3>
                    <p class="text-gray-300 mb-4"><?= htmlspecialchars($footerDescription) ?></p>
                    <div class="flex space-x-4">
                        <a href="#" class="text-gray-300 hover:text-primary">
                            <i class="fab fa-facebook-f"></i>
                        </a>
                        <a href="#" class="text-gray-300 hover:text-primary">
                            <i class="fab fa-twitter"></i>
                        </a>
                        <a href="#" class="text-gray-300 hover:text-primary">
                            <i class="fab fa-instagram"></i>
                        </a>
                        <a href="#" class="text-gray-300 hover:text-primary">
                            <i class="fab fa-youtube"></i>
                        </a>
                    </div>
                </div>

                <div>
                    <h3 class="text-lg font-semibold mb-4">Quick Links</h3>
                    <ul class="space-y-2">
                        <?php
                        // Display footer menu if available
                        $footerMenu = $menuModel->getMenuByLocation('footer');
                        if ($footerMenu && !empty($menuModel->getMenuItems($footerMenu['id']))) {
                            $footerMenuItems = $menuModel->getMenuItems($footerMenu['id']);
                            foreach ($footerMenuItems as $item) {
                                echo '<li><a href="' . htmlspecialchars($item['url']) . '" class="text-gray-300 hover:text-primary"';
                                if ($item['target'] === '_blank') {
                                    echo ' target="_blank"';
                                }
                                echo '>';
                                if (!empty($item['icon'])) {
                                    echo '<i class="' . htmlspecialchars($item['icon']) . ' mr-2"></i>';
                                }
                                echo htmlspecialchars($item['title']) . '</a></li>';
                            }
                        } else {
                            // Default links if no menu is set
                            echo '<li><a href="/" class="text-gray-300 hover:text-primary">Home</a></li>';
                            echo '<li><a href="/categories" class="text-gray-300 hover:text-primary">Categories</a></li>';
                            echo '<li><a href="/blog" class="text-gray-300 hover:text-primary">Blog</a></li>';
                            echo '<li><a href="/search" class="text-gray-300 hover:text-primary">Search</a></li>';
                        }
                        ?>
                    </ul>
                </div>

                <div>
                    <h3 class="text-lg font-semibold mb-4">Popular Categories</h3>
                    <ul class="space-y-2">
                        <?php foreach (array_slice($popularCategories, 0, 5) as $category): ?>
                        <li>
                            <a href="/category/<?= $category['slug'] ?>" class="text-gray-300 hover:text-primary">
                                <?= htmlspecialchars($category['name']) ?>
                            </a>
                        </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            </div>

            <div class="mt-8 pt-6 border-t border-gray-800 text-center">
                <p class="text-sm">&copy; <?= date('Y') ?> <?= htmlspecialchars($siteTitle ?? 'Moowin Casino') ?>. All Rights Reserved.</p>
            </div>
        </div>
    </footer>

    <script>
        // Only initialize user dropdown if not already handled in header
        if (typeof window.headerScriptsLoaded === 'undefined') {
            // User dropdown toggle
            const userDropdown = document.getElementById('userDropdown');
            if (userDropdown) {
                const dropdownMenu = userDropdown.querySelector('.dropdown-menu');
                userDropdown.addEventListener('click', (e) => {
                    if (e.target.closest('a')) return; // Don't toggle if clicking on a link
                    dropdownMenu.classList.toggle('hidden');
                });

                // Close dropdown when clicking outside
                document.addEventListener('click', (e) => {
                    if (!userDropdown.contains(e.target)) {
                        dropdownMenu.classList.add('hidden');
                    }
                });
            }
        }
    </script>

    <!-- View Transitions API Support -->
    <script src="/public/js/view-transitions.js"></script>

    <!-- Custom JavaScript -->
    <?php if (isset($customJs) && is_array($customJs)): ?>
        <?php foreach ($customJs as $jsFile): ?>
            <script src="<?= htmlspecialchars($jsFile) ?>"></script>
        <?php endforeach; ?>
    <?php endif; ?>

    <!-- Body End Code -->
    <?php if (isset($settings['body_end_code']) && !empty($settings['body_end_code'])): ?>
        <?= $settings['body_end_code'] ?>
    <?php endif; ?>

    <!-- Cookie Banner -->
    <?php if (isset($settings['enable_cookie_banner']) && $settings['enable_cookie_banner'] == '1'): ?>
        <?php include_once __DIR__ . '/cookie-banner.php'; ?>
    <?php endif; ?>
</body>
</html>
