window.addEventListener('acceptModal', event => {
    $("#accept").modal('show');
    const { id, user_id, amount } = event.detail
    $("#user_id").val(user_id)
    $("#withdraw_id").val(id)
    $("#amount").val(amount)
})
window.addEventListener('declineModal', event => {
    $("#decline").modal('show');
    $("#wd_id").val(event.detail.id)
})
$(document).ready(function () {
    $(document).on('click', '.request_accept', function (e) {
        e.preventDefault()
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('input[name="_token"]').val()
            },
            url : acceptReqUrl,
            method : "post",
            data : {
                'payment_method' : $("#payment_method").val(),
                'user_id' : $("#user_id").val(),
                'withdraw_id' : $("#withdraw_id").val(),
                'amount' : $("#amount").val()
            },
            success : function (data) {
                ajaxSuccessFunc("#accept", data)
            },
            error : function (error) {
                ajaxErrorFunc("#accept", error)
            }
        })
    })

    $(document).on('click', '.decline', function () {
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('input[name="_token"]').val()
            },
            url : reqDecline,
            method : "post",
            data : {
                'withdraw_id' : $("#wd_id").val()
            },
            success : function (data) {
                ajaxSuccessFunc("#decline", data)
            },
            error : function (error) {
                ajaxErrorFunc("#decline", error)
            }
        })
    })
})