<?php
// Shared <body>‑end scripts loaded by every project SPA module.
// Requires $assetsUrl to be set.
$assetsUrl = $assetsUrl ?? '';
?>
<!-- Single source of truth (mirrors core/SystemTables.php) for telling
     platform/system tables apart from the user's business tables. -->
<script>
window.PP_SYSTEM = (function () {
    var data = <?= json_encode(\PpPhp\Core\SystemTables::forJs(), JSON_UNESCAPED_SLASHES) ?>;
    var known = {}; (data.tables || []).forEach(function (t) { known[t] = true; });
    var prefixes = data.prefixes || ['pp_'];
    function isSystem(name) {
        var n = String(name || '').toLowerCase().trim();
        if (!n) return false;
        for (var i = 0; i < prefixes.length; i++) { if (n.indexOf(prefixes[i]) === 0) return true; }
        return !!known[n];
    }
    return {
        tables: data.tables || [],
        prefixes: prefixes,
        isSystem: isSystem,
        isProject: function (name) { return !isSystem(name); }
    };
})();
</script>
<script src="<?= $assetsUrl ?>/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="<?= $assetsUrl ?>/sweetalert2/sweetalert2.min.js"></script>
<!-- Shared build-progress overlay (same step screen as the Finished module) so a
     build started from ANY SPA page looks identical. Loaded before project-shell.js
     (which drives the top-bar Build button) so window.PPBuildProgress is ready. -->
<link rel="stylesheet" href="<?= $assetsUrl ?>/css/build-progress.css?v=<?= (int) @filemtime((defined('BASE_PATH') ? constant('BASE_PATH') : dirname(__DIR__, 2)) . '/public/assets/css/build-progress.css') ?>">
<script src="<?= $assetsUrl ?>/js/build-progress.js?v=<?= (int) @filemtime((defined('BASE_PATH') ? constant('BASE_PATH') : dirname(__DIR__, 2)) . '/public/assets/js/build-progress.js') ?>"></script>
<script src="<?= $assetsUrl ?>/js/project-shell.js?v=<?= (int) @filemtime((defined('BASE_PATH') ? constant('BASE_PATH') : dirname(__DIR__, 2)) . '/public/assets/js/project-shell.js') ?>"></script>
<script src="<?= $assetsUrl ?>/js/pp.js"></script>

<!-- GrapesJS core and preset (~1.16 MB) — heavy; a module that doesn't use the
     visual builder can opt out by setting `$skipGrapes = true` before including this. -->
<?php if (empty($skipGrapes)): ?>
<script src="<?= $assetsUrl ?>/grapesjs/grapes.min.js"></script>
<script src="<?= $assetsUrl ?>/grapesjs/grapesjs-preset-webpage.min.js"></script>
<?php endif; ?>