// alert(id);

loadElementsMhs()
function loadElementsMhs(clicksc){
    loaderPage(true)
    let isObject     = {}; 
    isObject.ipoly   = 1;
    isObject.nopeg   = id;
    

    var dtpr = $('#list_bimbingan').DataTable({
        serverSide	: true,
        destroy		: true,
        bFilter		: true,
        responsive	: true,
        searching   : true,
        pagingType  : 'full',
        lengthMenu  : [[1, 25, 50, -1], [1, 25, 50, "All"]],
        pageLength  : 25,
        ajax		: {
            url: baseURL + '/jsondata/listbimbingan',
            type: 'POST',
            // async: false,
            data : function (d) {         
                return $.extend( {}, d, {
                    iparam	    : cryptoEncrypt(PHRASE, isObject),
                });
            },
            dataSrc: function(response) {
                
                if(response.code == CODE_SUCCESS){
                    response = cryptoDecrypt(PHRASE, response.data);
                    // console.log(response.data.data);
                    var data = response.data.data;
                    
                    console.log(data)
                    return data;
                }else{
                    return response;
                }
               
            }
        },	
        columns: [
            { 'data': 'nim', 'sClass':'','sWidth':'10px'},
            { 'data': 'nim', 'sClass':''},
            { 'data': 'nama', 'sClass':''},
            { 'data': 'judul_laporan', 'sClass':''},
            { 'data': 'approve_proses_bimbingan', 'sClass':'text-center'},
            { 'data': '', 'sClass':'text-center','sWidth':'10px'}
        ],
        buttons: {            
            buttons: [
                {
                    extend: 'colvis',
                    className: 'btn btn-default'
                },
            ]
        },
        processing: true,
        stateSave: false,
        autoWidth: false,
        dom: '<"datatable-header"fBl><"datatable-scroll-wrap"t><"datatable-footer"ip>',
        language: {
            search: '<span>Filter:</span> _INPUT_',
            lengthMenu: '<span>Show:</span> _MENU_',
            processing: "<div class='table-loading'><img src='../../img/loadingtwo.gif' /></div>",

            paginate: { 'first': 'First', 'last': 'Last', 'next': '&rarr;', 'previous': '&larr;' }
        },
        columnDefs: [
            {
                width: '20px',
                targets: 0,
                visible: true
            },
            {   


                // render: function (data, type, row){
                //     // var $rowData = '<img src="/distro/assets/images/placeholder.jpg" alt="" class="img-rounded img-preview showAtt" style="cursor: pointer;">';
                //     let isIcon = ' icon-file-download2';

                //     var $rowData = '<div class="thumb img-rounded img-preview showAtt" style="width: 70px;">'+
                //         '<img src="/distro/assets/images/placeholder.jpg" alt="" class="img-rounded img-preview showAtt">'+
                //         '<div class="caption-overflow">'+
                //             '<span>'+
                //                 '<p  class="btn showAtt bg-success-400 btn-icon btn-lg" style="font-variant: all-petite-caps;background-color: #0e0e0e33 !important;border-color: #25252591 !important;">'+
                //                     '<i class="'+isIcon+'"></i> '
                //                 '</p>'+
                //             '</span>'+
                //         '</div>'+
                //     '</div>';

                //     return $rowData;
                // },
                // visible: true,
                // targets: 1,
            },  
            {   
                render: function (data, type, row){
                    console.log(row.approve_proses_bimbingan);
                    var $rowData = ``;
                    if(row.approve_proses_bimbingan == 1){
                        $rowData ='<span style="min-width: 70px" class="label label-success">Disetujui</span>';
                    } else {
                        $rowData ='<span style="min-width: 70px" class="label label-danger">Belum Disetujui</span>';
                    }
                    // if(row.statusvalid == "VALID"){
                    //     $rowData ='<span style="min-width: 70px" class="label label-success">'+row.statusvalid+'</span>';
                    // }else if(row.statusvalid == "MENUNGGU VALIDASI"){
                    //     $rowData = '<span style="min-width: 70px" class="label label-danger">'+row.statusvalid+'</span>';
                    // } else if(row.statusvalid == "BELUM UPLOAD"){
                    //     $rowData = '<span style="min-width: 70px" class="label label-danger">'+row.statusvalid+'</span>';
                    // }else if(row.statusvalid == "TIDAK VALID"){
                    //     $rowData = '<span style="min-width: 70px" class="label label-danger">'+row.statusvalid+'</span>';
                    // }
                    return $rowData;
                },
                visible: true,
                targets: 4,
            }, 
            {   
                render: function (data, type, row){
                    // console.log(row);
                    var $rowData = ``;

                    
                        $rowData = `<ul class="icons-list">
                                        <li class="dropdown">
                                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                                <i class="icon-menu9"></i>
                                            </a>

                                            <ul class="dropdown-menu dropdown-menu-right">
                                             
                                                <li class=""><a href="`+baseURL+`/dosen/bimbingan?nim=`+encodeURIComponent(btoa(row.nim))+`"><i class=" icon-file-eye2"></i> Proses Bimbingan </a></li>
                                                
                                            </ul>
                                        </li>
                                    </ul>`;
                    

                    return $rowData;
                },
                visible: true,
                targets: 5,
                className: 'dt-center'
            }, 
        ],
        fnRowCallback: function(nRow, aData, iDisplayIndex, iDisplayIndexFull){ 
            var index = iDisplayIndexFull + 1; 
            $('td:eq(0)', nRow).html('#'+index); 
            return  index;
        },
        drawCallback: function (settings) {
            // console.log(settings.json);
            
            var api  = this.api();
            var rows = api.rows({page:'current'}).nodes();
            var last = null;

            // console.log(rows)
            // Reverse last 3 dropdowns orientation
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');

            var that = this;
            var td ;
            var tr ;

            this.$('td').click( function () {
                td = this;
            });
            this.$('tr').click( function () {
                tr = this;
            });

            this.$('.showAtt').on('click', function(){

                var tr      = $(this).parents('tr')
                var aData   = dtpr.row( tr ).data();

                // loadAttachments(aData);

            });

            
        },
        fnInitComplete: function (oSettings, json) {
            var that = this;
            var td ;
            var tr ;

            this.$('td').click( function () {
                td = this;
            });
            this.$('tr').click( function () {
                tr = this;
            });

            

            $('#list_bimbingan input').bind('keyup', function (e) {
                return this.value;
            });

            setIFrameSize();

        }
    });

}

$(".btn-group-bimbingan").on("click", function(){
    // alert("a");
    window.location = baseURL + "/dosen/bimbingangroup"
});