(function () {
    function patchLegacyAttributes(root) {
        root.querySelectorAll('[data-toggle]').forEach(function (el) {
            var legacy = el.getAttribute('data-toggle');
            if (legacy && !el.hasAttribute('data-bs-toggle')) {
                el.setAttribute('data-bs-toggle', legacy);
            }
        });

        root.querySelectorAll('[data-target]').forEach(function (el) {
            if (!el.hasAttribute('data-bs-target')) {
                el.setAttribute('data-bs-target', el.getAttribute('data-target'));
            }
        });

        root.querySelectorAll('.dropdown-menu-right').forEach(function (el) {
            el.classList.add('dropdown-menu-end');
        });
    }

    document.addEventListener('DOMContentLoaded', function () {
        patchLegacyAttributes(document);

        if (window.bootstrap && window.bootstrap.Dropdown) {
            document.querySelectorAll('[data-bs-toggle="dropdown"]').forEach(function (el) {
                window.bootstrap.Dropdown.getOrCreateInstance(el);
            });
        }
    });
})();
