var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
define(["require", "exports", "jquery", "select2", "select2/dist/js/i18n/uk", "select2/dist/js/i18n/ru"], function (require, exports, jquery_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.initSelect2Search = exports.initSelect2 = exports.Select2 = void 0;
    jquery_1 = __importDefault(jquery_1);
    //import 'cci-ui/css/limitless.select2.css';
    function Select2(element, props) {
        (0, jquery_1.default)(element)
            .select2(props);
    }
    exports.Select2 = Select2;
    function initSelect2(language = process.env.LANG || 'uk') {
        Select2('.select2-init', {
            width: '100%',
            language: language
        });
        Select2('.select2-init-simple', {
            minimumResultsForSearch: Infinity,
            width: '100%',
            language: language
        });
    }
    exports.initSelect2 = initSelect2;
    function initSelect2Search() {
        (0, jquery_1.default)('[data-toggle="select2-search"]')
            .on('click', (ev) => {
            ev.preventDefault();
            const el = (0, jquery_1.default)(ev.currentTarget);
            const target = el.attr('data-target');
            const text = el.attr('data-text');
            const select2 = (0, jquery_1.default)(target);
            let searchField;
            if (select2.attr('multiple') != null) {
                searchField = select2.data('select2')
                    .$selection
                    .find('input');
            }
            else {
                searchField = select2.data('select2')
                    .$dropdown
                    .find('input');
            }
            select2.on('select2:open', () => {
                select2.off('select2:open');
                searchField.val(text)
                    .keyup();
                setTimeout(function () {
                    searchField.keyup();
                }, 10);
            });
            if (select2.hasClass('select2-hidden-accessible')) {
                select2.select2('open');
            }
        });
    }
    exports.initSelect2Search = initSelect2Search;
    document.addEventListener('DOMContentLoaded', () => {
        initSelect2();
        initSelect2Search();
    });
});
