@foreach($carts as $row)
    <div class="product_row">
        <div class="row align-items-center">
            <div class="col-lg-5 col-12">
                <div class="prod_item">
                    <div class="img">
                        <img src="{{$row->product->image}}" alt="">
                    </div>
                    <div class="inf">
                        {{-- <p> {{(getCurrentLocale() == 'en' ? $row->product->name : $row->product->name_localized)}} </p> --}}
                        <p> {{($row->product->name)}} </p>
                        <h6 class="mt-2"> <span class="txt"> {{ number_format($row->product->price,2) }} {{__('web.sar')}} </span> </h6>
                    </div>
                </div>
            </div>
            <div class="col-lg-2 col-5">
                <div class="add-more">
                    <span class="qt-minus" data-id="{{route('cart.update',$row->id)}}"><i class="fas fa-minus"></i></span>
                    <input type="text" class="qt border-0" value="{{$row->count}}">
                    <span class="qt-plus" data-id="{{route('cart.update',$row->id)}}"><i class="fas fa-plus"></i></span>
                </div>
            </div>
            <div class="col-lg-3 offset-lg-1 col-4">
                <h6> <span class="txt"> {{number_format($row->product->price * $row->count,2)}} {{__('web.sar')}} </span> </h6>
            </div>
            <div class="col-lg-1 col-2 text-end">
                <span onclick="deleteCart(this)" data-id="{{route('cart.destroy',$row->id)}}" class="cls"><i class="fal fa-trash"></i></span>
            </div>
        </div>
    </div>
@endforeach


    <script>
        // Increment button click event
        $(".qt-plus").click(function() {
            var value = parseInt($(this).siblings(".qt").val()); // Get the current value
            let url = $(this).attr('data-id')
            let item = $(this).siblings(".qt")
            $.ajax
            ({
                url : url,
                type: "PUT",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: 'count='+(value+1),
                dataType:'json',
                success:function(data)
                {
                    item.val(value + 1); // Increment the value and set it
                    toasterSuccess(data.message);
                    calculate()
                    getCartCount()
                }
                ,error:function(data)
                {
                    toasterError(Object.values(data.responseJSON.errors)[0]);
                }
            })
        });

        // Decrement button click event
        $(".qt-minus").click(function() {
            var value = parseInt($(this).siblings(".qt").val()); // Get the current value
            if (value > 1) {
                let url = $(this).attr('data-id')
                let item = $(this).siblings(".qt")

                $.ajax
                ({
                    url : url,
                    type: "PUT",
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    data: 'count='+(value-1),
                    dataType:'json',
                    success:function(data)
                    {
                        item.val(value - 1); // Decrement the value and set it
                        toasterSuccess(data.message);
                        calculate()
                        getCartCount()
                    }
                    ,error:function(data)
                    {
                        toasterError(Object.values(data.responseJSON.errors)[0]);
                    }
                })
            }
        });

    </script>
