import 'admin-lte/plugins/select2/js/select2.full.min';
import 'admin-lte/plugins/select2/css/select2.min.css';
import 'admin-lte/plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css';

export default () => {
    $('select:not(.no-select2)').each(function () {
        let select = $(this);
        let isCustomContent = select.find('[data-html]').length > 0;

        select.addClass('select2');
        select.select2({
            width: '100%',
            theme: 'bootstrap4',
            escapeMarkup: function (markup) {
                return markup;
            },
            templateResult: function (data) {
                return isCustomContent ? data.element ? data.element.getAttribute('data-html') : data.text : data.text;
            },
            templateSelection: function (data) {
                return isCustomContent ? data.element.getAttribute('data-html') : data.text;
            },
        });
    });
};
