    </div> <!-- End .container-fluid -->
</main>

<?php
if (!defined('SECURE_ACCESS')) {
    header("HTTP/1.1 403 Forbidden");
    exit("Direct access not allowed.");
}
$prefix = $prefix ?? ((strpos($_SERVER['PHP_SELF'], '/admin/') !== false) ? '../' : '');
// Fetch system configurations if not already defined
if (!isset($configs)) {
    $configs = [];
    try {
        if (isset($pdo)) {
            $stmt = $pdo->query("SELECT key, value FROM system_settings");
            $configs = $stmt->fetchAll(PDO::FETCH_KEY_PAIR) ?: [];
        }
    } catch (PDOException $e) {
        // Ignore
    }
}
$site_name_val = !empty($configs['site_name']) ? $configs['site_name'] : 'EventPortal';
$footer_copyright = !empty($configs['footer_copyright_text']) ? $configs['footer_copyright_text'] : ('&copy; {year} <strong>' . htmlspecialchars($site_name_val) . '</strong>. All rights reserved.');
$footer_copyright = str_replace(['{year}', '[year]', '{{year}}'], date('Y'), $footer_copyright);
$footer_about = !empty($configs['footer_about_text']) ? $configs['footer_about_text'] : 'The premium event hosting and professional network development portal.';
$fb = $configs['footer_facebook_url'] ?? '';
$tw = $configs['footer_twitter_url'] ?? '';
$li = $configs['footer_linkedin_url'] ?? '';
$ig = $configs['footer_instagram_url'] ?? '';
?>

<footer class="footer mt-auto py-4 bg-white border-top shadow-sm">
    <div class="container-fluid px-md-5">
        <div class="row g-4">
            <div class="col-12 col-md-6 col-lg-4">
                <h6 class="fw-bold text-dark mb-2"><?php echo htmlspecialchars($configs['site_name'] ?? 'EventPortal'); ?></h6>
                <p class="text-secondary small mb-0" style="max-width: 320px;"><?php echo htmlspecialchars($footer_about); ?></p>
            </div>
            <div class="col-12 col-md-6 col-lg-4 d-flex flex-column align-items-md-center">
                <h6 class="fw-bold text-dark mb-2">Social Channels</h6>
                <div class="d-flex gap-3">
                    <?php if (!empty($fb)): ?>
                        <a href="<?php echo htmlspecialchars($fb); ?>" target="_blank" class="text-secondary hover-primary"><i class="bi bi-facebook fs-5"></i></a>
                    <?php endif; ?>
                    <?php if (!empty($tw)): ?>
                        <a href="<?php echo htmlspecialchars($tw); ?>" target="_blank" class="text-secondary hover-primary"><i class="bi bi-twitter fs-5"></i></a>
                    <?php endif; ?>
                    <?php if (!empty($li)): ?>
                        <a href="<?php echo htmlspecialchars($li); ?>" target="_blank" class="text-secondary hover-primary"><i class="bi bi-linkedin fs-5"></i></a>
                    <?php endif; ?>
                    <?php if (!empty($ig)): ?>
                        <a href="<?php echo htmlspecialchars($ig); ?>" target="_blank" class="text-secondary hover-primary"><i class="bi bi-instagram fs-5"></i></a>
                    <?php endif; ?>
                    <?php if (empty($fb) && empty($tw) && empty($li) && empty($ig)): ?>
                        <span class="text-muted small">No links configured</span>
                    <?php endif; ?>
                </div>
            </div>
            <div class="col-12 col-lg-4 d-flex flex-column align-items-lg-end justify-content-center">
                <div class="text-muted small text-lg-end">
                    <span><?php echo $footer_copyright; ?></span>
                </div>
                <div class="small mt-1 text-lg-end">
                    <a href="<?php echo $prefix; ?>terms" class="text-secondary text-decoration-none me-2">Terms of Service</a>
                    <span class="text-muted">|</span>
                    <a href="<?php echo $prefix; ?>privacy" class="text-secondary text-decoration-none mx-2">Privacy Policy</a>
                    <span class="text-muted">|</span>
                    <a href="<?php echo $prefix; ?>contact" class="text-secondary text-decoration-none ms-2">Contact Us</a>
                </div>
            </div>
        </div>
    </div>
</footer>

<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script>
function showToast(message) {
    let container = document.getElementById('toast-container');
    if (!container) {
        container = document.createElement('div');
        container.id = 'toast-container';
        container.className = 'position-fixed bottom-0 start-50 translate-middle-x p-3';
        container.style.zIndex = '9999';
        document.body.appendChild(container);
    }
    const toast = document.createElement('div');
    toast.className = 'toast align-items-center text-bg-success border-0 show';
    toast.role = 'alert';
    toast.ariaLive = 'assertive';
    toast.ariaAtomic = 'true';
    toast.innerHTML = `
        <div class="d-flex">
            <div class="toast-body fw-bold">
                <i class="bi bi-check-circle-fill me-2"></i>${message}
            </div>
            <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
    `;
    container.appendChild(toast);
    setTimeout(() => {
        toast.classList.remove('show');
        setTimeout(() => { toast.remove(); }, 500);
    }, 3000);
}

document.addEventListener("DOMContentLoaded", function() {
    const baseDir = (window.projectRoot || '') + '/';

    // Copy Sponsor Link handler
    const copySponsorBtns = document.querySelectorAll('.btn-copy-sponsor');
    copySponsorBtns.forEach(btn => {
        btn.addEventListener('click', function() {
            const username = this.getAttribute('data-username');
            const refUrl = window.location.origin + baseDir + 'register/ref/' + encodeURIComponent(username);
            navigator.clipboard.writeText(refUrl).then(() => {
                showToast("Sponsor referral link copied to clipboard!");
            });
        });
    });

    // Share Event with Referral Link handler
    const shareBtns = document.querySelectorAll('.btn-share-ref');
    shareBtns.forEach(btn => {
        btn.addEventListener('click', function(e) {
            e.stopPropagation();
            const eventTitle = this.getAttribute('data-title');
            const eventId = this.getAttribute('data-id');
            const sponsor = this.getAttribute('data-sponsor');
            
            const refUrl = window.location.origin + baseDir + 'register/ref/' + encodeURIComponent(sponsor);
            const eventUrl = window.location.origin + baseDir + 'public_event/' + eventId + '?ref=' + encodeURIComponent(sponsor);
            
            navigator.clipboard.writeText(eventUrl).then(() => {
                showToast("Event referral link copied to clipboard!");
            });
        });
    });
});
</script>

</body>
</html>
