let editfunc = (pageid) => {
    let editbtn = document.getElementById('divedit-' + pageid);
    let divbtn = document.getElementById('div-' + pageid);
    let inputbtn = document.getElementById('input-' + pageid);

    if(editbtn.classList.contains('d-block')){
        editbtn.classList.remove('d-block');
        editbtn.classList.add('d-none');
    }

    if(divbtn.classList.contains('d-none')){
        divbtn.classList.remove('d-none');
        divbtn.classList.add('d-block');
    }
    inputbtn.disabled = false;

}

let savefunc = (pageid) => {
    let amount = document.getElementById("input-" + pageid);

    Swal.fire({
        title: 'Memuatkan...',
        allowEscapeKey : false,
        allowOutsideClick: false,
        didOpen: function () {
            Swal.showLoading();
        }
    });

    $.ajax({
        url : updateurl,
        method : 'PUT',
        data : {
            "amount" : amount.value,
            "id" : pageid,
            "_token": $('meta[name="csrf-token"]').attr('content')
        },
        success:function(response){
            if(response == 0){
                Swal.fire({ 
                    icon: 'error',
                    title: 'Perubahan Nilai Perubatan Tidak Berjaya!',
                });
                return false;
            }

            Swal.fire({ 
                icon: 'success',
                title: 'Perubahan Nilai Perubatan Berjaya!',
                showCancelButton: false,
                confirmButtonText: "Okay!",
                allowEscapeKey: false,
                allowOutsideClick: false
            }).then((result) => {
                if (result.isConfirmed) {
                  window.location.reload();
                } 
              });

        }
    });

    
    // let editbtn = document.getElementById('editButton-' + pageid);
    // let divbtn = document.getElementById('div-' + pageid);

    // if(editbtn.classList.contains('d-block')){
    //     editbtn.classList.remove('d-block');
    //     editbtn.classList.add('d-none');
    // }

    // if(divbtn.classList.contains('d-none')){
    //     divbtn.classList.remove('d-none');
    //     divbtn.classList.add('d-block');
    // }
}

let cancelfunc = (pageid) => {
    let editbtn = document.getElementById('divedit-' + pageid);
    let divbtn = document.getElementById('div-' + pageid);
    let inputbtn = document.getElementById('input-' + pageid);

    if(editbtn.classList.contains('d-none')){
        editbtn.classList.remove('d-none');
        editbtn.classList.add('d-block');
    }

    if(divbtn.classList.contains('d-block')){
        divbtn.classList.remove('d-block');
        divbtn.classList.add('d-none');
    }

    inputbtn.disabled = true;
}