<script>
    {literal}
    var Filter = function() {
        var sorting = function () {

            let paramsArray = [], categoryQuery = '', minQuery = '', maxQuery ='';

            // var target = $('.get-product');
            const target = document.querySelector('.get-project')

            const sortSelectContainer = new CustomSelect(".select-sort_js");
            sortSelectContainer.init((element => {
                console.log(element.value)
	            if (document.querySelector('.get-project')) {
                    target.setAttribute('data-company-id', element.value);
                }

                window.location.assign('{/literal}{if isset($section.url)}{$SITE_URL}{$section.url}{/if}{literal}?c=' + element.value);
            }));





            $(document).on('click', '.filter_btn', function () {

                // let paramsArray = [], categoryQuery = '', minQuery = '', maxQuery ='';

                let categoryList = $("input[name=cat]:checked").map(function() {
                    return $(this).val();
                }).get().join(",")

                let min = $("input[name=min]").val();
                let max = $("input[name=max]").val();


                if (categoryList != '') {
                    categoryQuery = createParamList(categoryList, 'cid');
                }

                if (min != ''){
                    minQuery = createParamList(min, 'min');
                }
                if (max != '') {
                    maxQuery = createParamList(max, 'max');
                }


                if (categoryQuery) {
                    paramsArray.push(categoryQuery);
                }
                if (minQuery) {
                    paramsArray.push(minQuery);
                }
                if (maxQuery) {
                    paramsArray.push(maxQuery);
                }

                window.location.assign('{/literal}{if isset($section.url)}{$SITE_URL}{$section.url}{/if}{literal}?' + paramsArray.join('&'));
                // window.location.assign('{/literal}{if isset($section.url)}{$section.url}{/if}{literal}?' + paramsArray.join('&') + '{/literal}{if isset($query)}&query={$query}{/if}{literal}');
            });

            // const filterSelectContainer = document.querySelector('.filter__select-container')
            // filterSelectContainer.addEventListener('click', (e) => {
            //     let target = e.target.closest('.select-custom__list-item')
			//
            //     if (target) {
            //         let sort = target.getAttribute('data-value')
                    // console.log(optionValue)
            //        $.post('{/literal}{$GLOBAL_URL}{literal}/ajax-sort', { sort: sort }, function() {
            //             window.location.reload();
            //         });
            //     }
            // })


            function createParamList(str, prefix)
            {
                return prefix + '=' + str;
            }
        }


        // Возврат объектов, назначенных модулю
        return {
            init: function() {
                sorting();
            }
        }

    }();

    // Инициализировать модуль
    document.addEventListener('DOMContentLoaded', function() {
        Filter.init();
    });
    {/literal}
</script>