<?xml version="1.0" encoding="UTF-8"?>
<root>
    <default>
        <includes>
            <!--
                Path to css and js files into plugins folder.
                If your files are not in plugins folder, use absolute paths.
            -->
            <css>
                <file>slimselect/slimselect.min.css</file>
                <file>slimselect/themes/%FRAMEWORK%.min.css</file>
            </css>
            <js>
                <file>slimselect/slimselect.min.js</file>
                <file>dompurify/purify.min.js</file>
            </js>
        </includes>
        <js_code><![CDATA[    if (typeof(slimSelects) === "undefined") {
        window.slimSelects = [];
        var addable = function(value) {
            return {
                text: DOMPurify.sanitize(value),
                value: DOMPurify.sanitize(value)
            }
        };
        window.getSlimIconTag = function(iconData) {
            const clazz = iconData.split(' ');
            let iconClazz = [],
                iconText = '',
                iconTag = '';
            if (clazz[0] === 'material-icons') {
                for (let index = 0; index < clazz.length; index++) {
                    if (index === 1) {
                        iconText = clazz[index];
                    } else {
                        iconClazz.push(clazz[index]);
                    }
                }
                iconTag = '<i class="' + iconClazz.join(' ') + '">' + iconText + '</i>';
            } else {
                iconTag = '<i class="' + iconData + '"></i>';
            }

            return iconTag;
        };
    }

    document.querySelectorAll("%selector%").forEach(el => {
        if (!el.classList.contains('ss-loaded')) {
            el.classList.add('ss-loaded');
            let selectId                = el.getAttribute('id'),
                dataAttr                = el.dataset,
                dataPlaceholder         = dataAttr.placeholder === undefined?null:dataAttr.placeholder,
                dataAllowDeselect       = dataAttr.allowDeselect === undefined?true:dataAttr.allowDeselect !== 'false',
                dataAllowDeselectOption = dataAttr.allowDeselectOption === undefined?true:dataAttr.allowDeselectOption !== 'false',
                dataDeselectLabel       = dataAttr.deselectLabel === undefined?'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 460.775 460.775" width=".75em" height=".5em" fill="#3F6078" xml:space="preserve"> <path d="M285.08,230.397L456.218,59.27c6.076-6.077,6.076-15.911,0-21.986L423.511,4.565c-2.913-2.911-6.866-4.55-10.992-4.55  c-4.127,0-8.08,1.639-10.993,4.55l-171.138,171.14L59.25,4.565c-2.913-2.911-6.866-4.55-10.993-4.55  c-4.126,0-8.08,1.639-10.992,4.55L4.558,37.284c-6.077,6.075-6.077,15.909,0,21.986l171.138,171.128L4.575,401.505  c-6.074,6.077-6.074,15.911,0,21.986l32.709,32.719c2.911,2.911,6.865,4.55,10.992,4.55c4.127,0,8.08-1.639,10.994-4.55  l171.117-171.12l171.118,171.12c2.913,2.911,6.866,4.55,10.993,4.55c4.128,0,8.081-1.639,10.992-4.55l32.709-32.719  c6.074-6.075,6.074-15.909,0-21.986L285.08,230.397z"/></svg>':dataAttr.deselectLabel,
                dataAddable             = dataAttr.addable === undefined?false:addable,
                dataLimit               = dataAttr.limit === undefined?0:dataAttr.limit,
                dataShowSearch          = dataAttr.showSearch === undefined?true:dataAttr.showSearch !== 'false',
                dataSearchText          = dataAttr.searchText === undefined?'No Results':dataAttr.searchText,
                dataSearchPlaceholder   = dataAttr.searchPlaceholder === undefined?'Search ...':dataAttr.searchPlaceholder,
                dataSearchFocus         = dataAttr.searchFocus === undefined?false:dataAttr.searchFocus !== 'false',
                dataSearchHighlight     = dataAttr.searchHighlight === undefined?true:dataAttr.searchHighlight === 'true',
                dataCloseOnSelect       = dataAttr.closeOnSelect === undefined?true:dataAttr.closeOnSelect === 'true',
                dataShowContent         = dataAttr.showContent === undefined?'auto':dataAttr.showContent,
                dataAddToBody           = dataAttr.addToBody === undefined?true:dataAttr.addToBody !== 'false',
                dataSelectByGroup       = dataAttr.selectByGroup === undefined?false:dataAttr.selectByGroup !== 'false',
                dataHideSelectedOption  = dataAttr.hideSelectedOption === undefined?false:dataAttr.hideSelectedOption !== 'false';

            let slm = new SlimSelect({
                select              : document.getElementById(selectId),
                placeholder         : dataPlaceholder,
                allowDeselect       : dataAllowDeselect,
                allowDeselectOption : dataAllowDeselectOption,
                deselectLabel       : dataDeselectLabel,
                addable             : dataAddable,
                limit               : dataLimit,
                showSearch          : dataShowSearch,
                searchText          : dataSearchText,
                searchPlaceholder   : dataSearchPlaceholder,
                searchFocus         : dataSearchFocus,
                searchHighlight     : dataSearchHighlight,
                closeOnSelect       : dataCloseOnSelect,
                showContent         : dataShowContent,
                addToBody           : dataAddToBody,
                selectByGroup       : dataSelectByGroup,
                hideSelectedOption  : dataHideSelectedOption
            });

            if (el.dataset.flagSize !== undefined) {
                let flagSize = el.dataset.flagSize.toString();
                var link = document.createElement('link');
                link.type = 'text/css';
                link.rel = 'stylesheet';
                link.href = '%pluginsUrl%countries/world-flags-sprite/stylesheets/flags' + flagSize + '.min.css';
                document.head.appendChild(link);

                document.querySelector('.ss-content.' + slm.config.id).classList.add('f' + flagSize);
                slm.setData(slm.data.data);
            }

            var hasOptionsData = false;
            slm.data.data.forEach(d => {
                if (d.options === undefined) {
                    if (d.data && d.data.icon !== undefined) {
                        const iconTag = getSlimIconTag(d.data.icon);
                        d.innerHTML = iconTag + d.text;
                        hasOptionsData = true;
                    } else if (d.data && d.data.html !== undefined) {
                        d.innerHTML = d.data.html;
                        hasOptionsData = true;
                    }
                } else {
                    d.options.forEach(opt => {
                        if (opt.data && opt.data.icon !== undefined) {
                            const iconTag = getSlimIconTag(opt.data.icon);
                            opt.innerHTML = iconTag + opt.text;
                            hasOptionsData = true;
                        } else if (opt.data && opt.data.html !== undefined) {
                            opt.innerHTML = opt.data.html;
                            hasOptionsData = true;
                        }
                    });
                }
            });
            if (hasOptionsData) {
                slm.setData(slm.data.data);
            }
            window.slimSelects[selectId] = slm;
        }
    });]]>
        </js_code>
    </default>
</root>
