import MediaLibraryInstance from "./MediaLibraryInstance";

export default function InitLibraryButtons(wrap) {
    if (document.querySelector('#media-library-app')) {

        const btns = wrap.querySelectorAll('[data-action="open-library"]')
        btns.forEach((el) => {
            el.addEventListener('click', (e) => {
                e.preventDefault();
                const mediaTypesStr = el.getAttribute('data-action-payload');
                MediaLibraryInstance().open(el, {
                    mediaTypes: mediaTypesStr.split(',')
                });
            });
        });
        const unlinkBtns = wrap.querySelectorAll('[data-action="library-unlink"]')
        unlinkBtns.forEach((el) => {
            el.addEventListener('click', (e) => {
                e.preventDefault();
                MediaLibraryInstance().unlink(el);
            });
        });
    }
}
