<script>
    {literal}

    var App = function() {

        const projects = "{/literal}{$SITE_URL}{literal}/api-projects";
        const products = "{/literal}{$SITE_URL}{literal}/api-products";
        const clients = "{/literal}{$SITE_URL}{literal}/api-clients";

        var _projectAction = function () {

            $(document).on('click', '.get-project', function() {
                var page = $(this).attr('data-page'), limit = $(this).attr('data-limit'), category = $(this).attr('data-category-id'), company = $(this).attr('data-company-id'), max = $(this).attr('data-max');
                page++;
                $.post(projects, { page: page, limit: limit, category: category, company: company }, function (response) {
                    console.log(response);
                    if (response.status === 200) {
                        $('.projects-list').append(response.data);

                    }
                }, 'json');

                $(this).attr('data-page', page);
                if (page == max) {
                    $(this).remove();
                }
            });
        }

        var _clientsAction = function () {

            $(document).on('click', '.get-clients', function() {
                var page = $(this).attr('data-page'), limit = $(this).attr('data-limit'), category = $(this).attr('data-category-id'), company = $(this).attr('data-company-id'), max = $(this).attr('data-max');
                page++;
                $.post(clients, { page: page, limit: limit, category: category, company: company }, function (response) {
                    console.log(response);
                    if (response.status === 200) {
                        $('.clients-list').append(response.data);

                    }
                }, 'json');

                $(this).attr('data-page', page);
                if (page == max) {
                    $(this).remove();
                }
            });
        }

        var _productAction = function () {

            $(document).on('click', '.get-product', function() {
                var page = $(this).attr('data-page'), limit = $(this).attr('data-limit'), category = $(this).attr('data-category-id'), max = $(this).attr('data-max');
	            let content =  $(".products-list-" + category);
                page++;
                $.post(products, { page: page, limit: limit, category: category }, function (response) {
                    console.log(response);
                    if (response.status === 200) {
                        console.log(content)
                        content.append(response.data);
                    }
                }, 'json');

                $(this).attr('data-page', page);
                if (page == max) {
                    $(this).remove();
                }
            });

        }



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

    }();

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