{% put scripts %}

<script>
    getNewProducts('{{query}}', '{{limit}}');
    // console.log("qqq");
    function getNewProducts(query, limit) {
        console.log(query);
        $(document).ready(function () {
            $.ajax({
                url: `https://nurgul.com.tm/app/api/products?`+query+`{{activeLocale}}&limit=`+limit,
                type: 'GET',
                dataType: 'json',
                beforeSend: function () {
                    $('#products_{{id}}').hide();
                    $('#loader_{{id}}').show();
                },
                success: function (data, textStatus, xhr) {
                    $('#loader_{{id}}').hide(500);
                    $('#products_{{id}}').show(500);


                    // console.log(data.data);

                    var products = data.data;
                    for (var product of products) {
                        // console.log(product.hasOwnProperty('special_price'));
                        $('#products_{{id}}').append(productCard(product));
                    }
                },
                error: function (xhr, textStatus, errorThrown) {
                    console.log('Error in Operation');
                }
            });
        });
    }
</script>
{% endput %}

{%partial 'scripts/setModal' %}
{%partial 'scripts/prodCard' %}