$(document).ready(function(){
    $('#toastSuccessBtn').click(function(){
       let id = $("#appointmentId").val();
       let _token = $("[name='_token']").val();
       let data = {id,_token};
       window.canCloseLoading = false;
       $('#modalLoading').modal('show');
        $.ajax({
            url: "close-appointment",
            method: 'POST',
            data: JSON.stringify(data),
            dataType: 'JSON',
            contentType:"application/json",
            success:function(response)
            {
                if((response)&&(response.opstatus == 0)){
                    $('#toastSuccess').toast('show');
                    $('#modalAppointment').modal("hide");
                    let timer = setTimeout(() => {
                        window.canCloseLoading = true;
                        window.location.href="view-appointments";
                        clearTimeout(timer); 
                    }, 2000);
                }else{
                    $('#toastError').toast('show');
                    $('#modalAppointment').modal("hide");
                }
            },
            error: function(response) {
                $('#toastError').toast('show');
                $('#modalAppointment').modal("hide");
                $('#modalLoading').modal('hide');
                window.canCloseLoading = true;
            }
    });
    });


    $('#btnDeleteModal').click(function(){
        let id = $("#appointmentId").val();
        let _token = $("[name='_token']").val();
        let data = {id,_token};
        window.canCloseLoading = false;
        $('#modalLoading').modal('show');
         $.ajax({
             url: "delete-appointment",
             method: 'POST',
             data: JSON.stringify(data),
             dataType: 'JSON',
             contentType:"application/json",
             success:function(response)
             {
                 if((response)&&(response.opstatus == 0)){
                     $('#toastSuccess').toast('show');
                     $('#modalDelete').modal("hide");
                     let timer = setTimeout(() => {
                         window.canCloseLoading = true;
                         window.location.href="view-appointments";
                         clearTimeout(timer); 
                     }, 2000);
                 }else{
                     $('#toastError').toast('show');
                     $('#modalDelete').modal("hide");
                 }
             },
             error: function(response) {
                 $('#toastError').toast('show');
                 $('#modalDelete').modal("hide");
                 $('#modalLoading').modal('hide');
                 window.canCloseLoading = true;
             }
     });
     });
});