import Tooltip from "bootstrap/js/src/tooltip";
import Dropdown from "bootstrap/js/src/dropdown";
import Collapse from "bootstrap/js/src/collapse";
import Modal from "bootstrap/js/src/modal";

export default function () {
    applyBootstrapPlugin('[data-bs-toggle="tooltip"]', Tooltip, 'Tooltip');
    applyBootstrapPlugin('[data-bs-toggle="dropdown"]', Dropdown, 'Dropdown');
    applyBootstrapPlugin('[data-bs-toggle="collapse"]', Collapse, 'Collapse');
    applyBootstrapPlugin('div.modal', Modal, 'Modal');
}

function applyBootstrapPlugin(selector, plugin, name) {
    let els = document.querySelectorAll(selector);
    els.forEach((el) => {
        let key = 'aaBootstrap' + name;
        el[key] = new plugin(el);
    });
}