<?php
/**
 * Dashboard foot — closes <main>, includes modals, loads JS.
 *
 * Usage: require at end of every dashboard page.
 * Set $extraJs = ['dashboard', 'campaigns'] before including for extra scripts.
 */
$extraJs = $extraJs ?? [];
?>
    </main>
</div>

<?php require __DIR__ . '/modals.php'; ?>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
    // Global toast helper
    window.Toast = Swal.mixin({
        toast: true, position: 'top-end', showConfirmButton: false,
        timer: 3500, timerProgressBar: true,
        didOpen: t => { t.onmouseenter = Swal.stopTimer; t.onmouseleave = Swal.resumeTimer; }
    });
    // CSRF helper for fetch
    window.csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '';
    window.api = async function(url, opts = {}) {
        opts.headers = Object.assign({ 'X-CSRF-Token': window.csrfToken, 'Accept': 'application/json' }, opts.headers || {});
        const res = await fetch(url, opts);
        return res.json();
    };
</script>
<script src="/assets/js/main.js"></script>
<script src="/assets/js/modals.js"></script>
<?php foreach ($extraJs as $js): ?>
<script src="/assets/js/<?= e($js) ?>.js"></script>
<?php endforeach; ?>
</body>
</html>
