<script>

$(document).ready(function() {
    
        $(document).on("click", ".approveEditRequest", function(e) {
            e.preventDefault();
            Swal.fire({
            title: '<%= i18n.__("confirmApproveProviderEditRequest") %>',
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '<%= i18n.__("confirm") %>',
            confirmButtonClass: 'btn btn-primary',
            cancelButtonText: '<%= i18n.__("cancel") %>',
            cancelButtonClass: 'btn btn-danger ml-1',
            buttonsStyling: false,
            }).then((result) => {
            if (result.value) {

                let id = $(this).attr("id");
                $.ajax({
                type: "POST",
                url: $(this).data("route"),
                data: {},
                success: function(msg) {
                    Swal.fire({
                    position: "top-start",
                    type: "success",
                    title: '<%= i18n.__("approveEditRequestSuccessfully") %>',
                    showConfirmButton: false,
                    timer: 1500,
                    confirmButtonClass: "btn btn-primary",
                    buttonsStyling: false,
                    }).then(() => {
                    window.location.href = "/dashboard/providers/editRequests";
                    });
                    $("#tr" + id).animate(
                    {
                        opacity: 0.25,
                        height: "toggle",
                    },
                    function() {
                        $("#tr" + id).remove();
                    }
                    );
                },
                error: function(err) {
                    Swal.fire({
                    position: "top-start",
                    type: "error",
                    title: `${err?.responseJSON?.message || err.responseJSON ||err.message}`,
                    showConfirmButton: false,
                    timer: 1500,
                    confirmButtonClass: "btn btn-primary",
                    buttonsStyling: false,
                    });
                },
                });
                
            }
            });
        });


        $(document).on("click", ".rejectEditRequest", function(e) {
        e.preventDefault();
            Swal.fire({
            title: '<%= i18n.__("confirmRejectProviderEditRequest") %>',
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '<%= i18n.__("confirm") %>',
            confirmButtonClass: 'btn btn-primary',
            cancelButtonText: '<%= i18n.__("cancel") %>',
            cancelButtonClass: 'btn btn-danger ml-1',
            buttonsStyling: false,
            }).then((result) => {
            if (result.value) {
                let id = $(this).attr("id");
                $.ajax({
                type: "POST",
                url: $(this).data("route"),
                data: {},
                success: function(msg) {
                    Swal.fire({
                    position: "top-start",
                    type: "success",
                    title: '<%= i18n.__("rejectEditRequestSuccessfully") %>',
                    showConfirmButton: false,
                    timer: 1500,
                    confirmButtonClass: "btn btn-primary",
                    buttonsStyling: false,
                    }).then(() => {
                    window.location.href = "/dashboard/providers/editRequests";
                    });
                    $("#tr" + id).animate(
                    {
                        opacity: 0.25,
                        height: "toggle",
                    },
                    function() {
                        $("#tr" + id).remove();
                    }
                    );
                },
                error: function(err) {
                    Swal.fire({
                    position: "top-start",
                    type: "error",
                    title: `${err?.responseJSON?.message || err.responseJSON ||err.message}`,
                    showConfirmButton: false,
                    timer: 1500,
                    confirmButtonClass: "btn btn-primary",
                    buttonsStyling: false,
                    });
                },
                });
            }
            });
        });
    });


</script>
