$(document).ready(function(){

    //send();
    function send(){
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: baseURL + '/jsondata/isheader',
            data: {
                'de78qw4da6s5d4as'  : 'eqweqw64ee5q2s1dfqw9e',
            },
            success: function(result){
                
            }
        });

    }
});

loadDashboard();
function loadDashboard(){
    let isObject = {};
    isObject.param = null;
    // console.log(isObject)

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/loaddashboardadmin',
        // async: false,
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function(response){
            // console.log(response.code)
            $("tbody").empty();
            
            if(response.code == CODE_SUCCESS){
                let result  = cryptoDecrypt(PHRASE, response.data);
                console.log(result.data);
                let data    = result.data;
                let datas   = data[0];
                $("#totalmhs").html(datas.total_mahasiswa);
                $("#proses").html(datas.proses_kp);
                $("#gagal").html(datas.gagal_kp);
                $("#selesai").html(datas.selesai_kp);
                
            } else {
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  
            }
            
        },
        error: function(xhr) {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Galat",
                    text:  xhr.status+"-"+xhr.statusText+"<br> Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
}

console.log(nopeg)
if(nopeg != null){
    loadDashboarddosen(nopeg);
}


function loadDashboarddosen(nopeg){
    let isObject = {};
    isObject.param = nopeg;
    // console.log(isObject)

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/loaddashboarddosen',
        // async: false,
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function(response){
            // console.log(response.code)
            $("tbody").empty();
            
            if(response.code == CODE_SUCCESS){
                let result  = cryptoDecrypt(PHRASE, response.data);
                console.log(result.data);
                let data    = result.data;
                let datas   = data[0];
                $("#totalbimbingan").html(datas.jumlah_bimbingan);
                $("#jadwal").html(datas.jumlah_jadwal);
                $("#mhselesai").html(datas.mhs_gagal);
                $("#mhgagal").html(datas.mhs_selesai);
                
            } else {
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  
            }
            
        },
        error: function(xhr) {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Galat",
                    text:  xhr.status+"-"+xhr.statusText+"<br> Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
}

if(nim != null){
    loaddashboardmahasiswa(nim);
}


function loaddashboardmahasiswa(nim){
    let isObject = {};
    isObject.param = nim;
    // console.log(isObject)

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/loaddashboardmahasiswa',
        // async: false,
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function(response){
            // console.log(response.code)
            $("tbody").empty();
            
            if(response.code == CODE_SUCCESS){
                let result  = cryptoDecrypt(PHRASE, response.data);
                console.log(result.data);
                let data    = result.data;
                let datas   = data[0];
                $("#tenggat").html(datas.tenggat);
                $("#periode").html(datas.periode);
                $("#jadwal").html(datas.tanggal);
                
                    $("#nilai").html(datas.nilai_mutu);
                
                
            } else {
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  
            }
            
        },
        error: function(xhr) {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Galat",
                    text:  xhr.status+"-"+xhr.statusText+"<br> Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
}
