<?php
/**
 * Frontend Footer - COMPLETE FIXED VERSION
 * Digital Product Store
 */

// Get footer pages
$footer_pages = [];
try {
    $stmt = $pdo->query("SELECT * FROM pages WHERE is_active = 1 AND status = 'published' ORDER BY title LIMIT 5");
    $footer_pages = $stmt->fetchAll();
} catch (PDOException $e) {
    // Silently fail
}
?>
    </main>
    
    <!-- Footer -->
    <footer class="footer mt-5">
        <div class="container">
            <div class="row">
                <!-- About -->
                <div class="col-lg-4 col-md-6 mb-4">
                    <h5 class="mb-3"><?php echo get_setting('site_name', 'Digital Store'); ?></h5>
                    <p><?php echo get_setting('site_description', 'Your trusted source for premium digital products'); ?></p>
                    <div class="social-links">
                        <?php if (get_setting('facebook_url')): ?>
                        <a href="<?php echo get_setting('facebook_url'); ?>" target="_blank" class="me-3"><i class="fab fa-facebook fa-lg"></i></a>
                        <?php endif; ?>
                        <?php if (get_setting('twitter_url')): ?>
                        <a href="<?php echo get_setting('twitter_url'); ?>" target="_blank" class="me-3"><i class="fab fa-twitter fa-lg"></i></a>
                        <?php endif; ?>
                        <?php if (get_setting('instagram_url')): ?>
                        <a href="<?php echo get_setting('instagram_url'); ?>" target="_blank" class="me-3"><i class="fab fa-instagram fa-lg"></i></a>
                        <?php endif; ?>
                        <?php if (get_setting('youtube_url')): ?>
                        <a href="<?php echo get_setting('youtube_url'); ?>" target="_blank" class="me-3"><i class="fab fa-youtube fa-lg"></i></a>
                        <?php endif; ?>
                    </div>
                </div>
                
                <!-- Quick Links -->
                <div class="col-lg-2 col-md-6 mb-4">
                    <h5 class="mb-3">Quick Links</h5>
                    <ul class="list-unstyled">
                        <li class="mb-2"><a href="<?php echo BASE_URL; ?>/index.php">Home</a></li>
                        <li class="mb-2"><a href="<?php echo BASE_URL; ?>/products.php">Products</a></li>
                        <li class="mb-2"><a href="<?php echo BASE_URL; ?>/about.php">About Us</a></li>
                        <li class="mb-2"><a href="<?php echo BASE_URL; ?>/contact.php">Contact</a></li>
                    </ul>
                </div>
                
                <!-- Pages -->
                <div class="col-lg-2 col-md-6 mb-4">
                    <h5 class="mb-3">Information</h5>
                    <ul class="list-unstyled">
                        <?php foreach ($footer_pages as $page): ?>
                        <li class="mb-2"><a href="<?php echo BASE_URL; ?>/page.php?slug=<?php echo $page['slug']; ?>"><?php echo htmlspecialchars($page['title']); ?></a></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
                
                <!-- Contact -->
                <div class="col-lg-4 col-md-6 mb-4">
                    <h5 class="mb-3">Contact Us</h5>
                    <ul class="list-unstyled">
                        <?php if (get_setting('contact_email')): ?>
                        <li class="mb-2"><i class="fas fa-envelope me-2"></i><?php echo get_setting('contact_email'); ?></li>
                        <?php endif; ?>
                        <?php if (get_setting('contact_phone')): ?>
                        <li class="mb-2"><i class="fas fa-phone me-2"></i><?php echo get_setting('contact_phone'); ?></li>
                        <?php endif; ?>
                        <?php if (get_setting('contact_address')): ?>
                        <li class="mb-2"><i class="fas fa-map-marker-alt me-2"></i><?php echo get_setting('contact_address'); ?></li>
                        <?php endif; ?>
                    </ul>
                    
                    <!-- Newsletter -->
                    <h6 class="mb-2 mt-4">Subscribe to Newsletter</h6>
                    <form action="<?php echo BASE_URL; ?>/subscribe.php" method="POST">
                        <div class="input-group">
                            <input type="email" name="email" class="form-control" placeholder="Your email" required>
                            <button type="submit" class="btn btn-primary">Subscribe</button>
                        </div>
                    </form>
                </div>
            </div>
            
            <hr class="my-4">
            
            <div class="row align-items-center">
                <div class="col-md-6">
                    <p class="mb-0"><?php echo get_setting('footer_text', '© ' . date('Y') . ' Digital Store. All rights reserved.'); ?></p>
                </div>
                <div class="col-md-6 text-md-end">
                    <img src="https://via.placeholder.com/50x30?text=VISA" alt="Visa" class="me-2">
                    <img src="https://via.placeholder.com/50x30?text=MC" alt="MasterCard" class="me-2">
                    <img src="https://via.placeholder.com/50x30?text=PP" alt="PayPal" class="me-2">
                </div>
            </div>
        </div>
    </footer>
    
    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- Custom Scripts -->
    <script>
    // Auto-dismiss alerts after 5 seconds
    document.addEventListener('DOMContentLoaded', function() {
        setTimeout(function() {
            var alerts = document.querySelectorAll('.alert-dismissible');
            alerts.forEach(function(alert) {
                var bsAlert = new bootstrap.Alert(alert);
                bsAlert.close();
            });
        }, 5000);
    });
    </script>
</body>
</html>
<?php
// Flush output buffer
ob_end_flush();
