</div> <!-- main-content -->
</div> <!-- wrapper -->

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<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/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
window.CSRF_TOKEN = document.querySelector('meta[name="csrf-token"]')?.content || '';

if (window.jQuery) {
    $.ajaxSetup({
        beforeSend: function (xhr, settings) {
            const method = (settings.type || settings.method || 'GET').toUpperCase();
            if (!['GET', 'HEAD', 'OPTIONS'].includes(method) && window.CSRF_TOKEN) {
                xhr.setRequestHeader('X-CSRF-Token', window.CSRF_TOKEN);
            }
        }
    });
}
if (window.fetch && window.CSRF_TOKEN) {
    const nativeFetch = window.fetch.bind(window);
    window.fetch = function (resource, options) {
        const init = options || {};
        const method = (init.method || 'GET').toUpperCase();
        if (!['GET', 'HEAD', 'OPTIONS'].includes(method)) {
            const headers = new Headers(init.headers || {});
            headers.set('X-CSRF-Token', window.CSRF_TOKEN);
            init.headers = headers;
        }
    return nativeFetch(resource, init);
    };
}
(function ($) {
    var _html = $.fn.html, _val = $.fn.val, _busy = false;
    $.fn.html = function () {
        var r = _html.apply(this, arguments);
        if (!_busy && this.is('select') && this.data('select2')) {
            _busy = true;
            this.trigger('change.select2');
            _busy = false;
        }
        return r;
    };
    $.fn.val = function () {
        var r = _val.apply(this, arguments);
        if (!_busy && arguments.length && this.is('select') && this.data('select2')) {
            _busy = true;
            this.trigger('change.select2');
            _busy = false;
        }
        return r;
    };
})(jQuery);
$('body').on('focusin', function (e) {
    if ($(e.target).closest('.select2-dropdown').length) { e.stopPropagation(); }
});
$(function () {
    $('select').not('.no-select2').each(function () {
        var $sel = $(this);
        $sel.select2({
            theme: 'bootstrap-5',
            minimumResultsForSearch: 0,
            dropdownParent: $sel.closest('.modal, .offcanvas, form, body')
        });
    });
});
</script>
<?php $notificationsJsPath = __DIR__ . '/../../assets/js/notifications.js'; ?>
<script src="assets/js/notifications.js?v=<?= file_exists($notificationsJsPath) ? filemtime($notificationsJsPath) : time() ?>"></script>

<?php if (isset($page_js)): ?>
    <?php $pageJsPath = __DIR__ . '/../../assets/js/' . $page_js; ?>
    <script src="assets/js/<?= $page_js ?>?v=<?= file_exists($pageJsPath) ? filemtime($pageJsPath) : time() ?>"></script>
<?php endif; ?>
<?php if (isset($page_extra_js)): ?>
    <?php $pageExtraJsPath = __DIR__ . '/../../assets/js/' . $page_extra_js; ?>
    <script src="assets/js/<?= $page_extra_js ?>?v=<?= file_exists($pageExtraJsPath) ? filemtime($pageExtraJsPath) : time() ?>"></script>
<?php endif; ?>

</body>
</html>
