async function qtyIncrease(elem)
{
    let id = $(elem).attr('data-id')
    let action = $(elem).attr('action-id')
    let qty = $('#qty'+id).val()
    let new_qty = Number(qty)+1 ;
    $('#qty'+id).val(new_qty)
    $('#qty'+id).attr('count-id',new_qty)

    await $.ajax
    ({
        url : action,
        type: 'PUT',
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        data: 'id='+id+'&count='+new_qty,
        success:function(data)
        {
            toasterSuccess(data.message);
        }
        ,error:function(data)
        {
            if (typeof data.responseJSON.errors == 'object')
            {
                toasterError(Object.values(data.responseJSON.errors)[0]);
            }
            else
            {
                toasterError(data.responseJSON.errors);
            }
        }
    })

    calculate()
}
async function qtyDecrease(elem)
{
    let id = $(elem).attr('data-id')
    let action = $(elem).attr('action-id')
    let qty = $('#qty'+id).val()
    let new_qty = Number(qty)-1 ;
    if (qty > 1)
    {
        $('#qty'+id).val(new_qty)
        $('#qty' + id).attr('count-id', new_qty)

        await $.ajax
        ({
            url : action,
            type: 'PUT',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            data: 'id='+id+'&count='+new_qty,
            success:function(data)
            {
                toasterSuccess(data.message);
            }
            ,error:function(data)
            {
                if (typeof data.responseJSON.errors == 'object')
                {
                    toasterError(Object.values(data.responseJSON.errors)[0]);
                }
                else
                {
                    toasterError(data.responseJSON.errors);
                }
            }
        })

        calculate()
    }
}

async function deleteCart(elem)
{
    let url = $(elem).attr('action-id');
    await $.ajax({
        url : url,
        type: 'DELETE',
        data: {
            "_token": $('meta[name="csrf-token"]').attr('content'),
        }
    })
    calculate()
    $(elem).closest('.cart_card_row').hide(1000)
    setTimeout(
        function()
        {
            $(elem).closest('.cart_card_row').remove()
        }, 1100);
}
