﻿$(document).ready(function () {
    // Remove product link click event
    $('.remove_product').click(function (e) {
        e.preventDefault(); // Prevent default link behavior
        aler(SepetId)
        var SepetId = $(this).closest('tr').data('product-id');
        var url = '/sepet/SepettenSil'; // Your URL to delete product
        aler(SepetId)
        // AJAX request
        $.ajax({
            type: 'POST',
            url: url,
            data: { SepetId: SepetId }, // Send product ID as data
            success: function (response) {
                // Handle success response
                // Satırı yavaşça gizle
                $(this).closest('tr').fadeOut('slow', function () {
                    $(this).remove(); // Satırı kalıcı olarak kaldır
                });
            },
            error: function (xhr, status, error) {
                // Handle error response
                console.error(error);
                alert('Ürünü silerken bir hata oluştu.');
            }
        });
    });
    function sepettensil(SepetId) {
        var url = '/sepet/SepettenSil'; // Your URL to delete product
        aler(SepetId)
        // AJAX request
        $.ajax({
            type: 'POST',
            url: url,
            data: { SepetId: SepetId }, // Send product ID as data
            success: function (response) {
                // Handle success response
                // Satırı yavaşça gizle
                $(this).closest('tr').fadeOut('slow', function () {
                    $(this).remove(); // Satırı kalıcı olarak kaldır
                });
            },
            error: function (xhr, status, error) {
                // Handle error response
                console.error(error);
                alert('Ürünü silerken bir hata oluştu.');
            }
        });
    }
});