// first function to execute when the manage admin page loads
function fetchTheUsers(){
    $.ajax({
        'url': base_url+"/api/fetchAdmins",
        'method': "GET",
        'headers':{
            "Authorization": "Bearer "+sessionStorage.getItem('auth-token')
        },
        'contentType': 'application/json'
    }).done( function(data) {
        console.log(data)
        // sessionStorage.setItem('request-detail', data.requests);
        if(data.success){
            //let hk = data.drivers
            $('.lds-hourglass').addClass('doNotShow')
            $('#dataTable').DataTable({
                "aaData": data.admins,
                "ordering":false,
                "columns": [
                    {
                        "data": "id",
                        "render": function ( data, type, row, meta ) {
                            return "<p>00"+data+"</p>";
                        }
                    },
                    { "data": "firstname" },
                    { "data": "lastname" },
                    { "data": "email" },
                    { "data": "phone_number"},
                    /*{
                     sortable: false,
                     "data": "delivery_status",
                     "render": function ( data, type, row, meta ) {
                     var status = ((parseInt(data)+1)/4)*100;
                     return "<div class='h5 mb-0 mr-3 font-weight-bold text-gray-800 progress-today-text'>"+status+"%</div>\
                     <div class='progress progress-sm mr-2'>\
                     <div class='progress-bar bg-info percentage-progress-today' role='progressbar' style='width: "+status+"%' aria-valuenow='"+status+"' aria-valuemin='0' aria-valuemax='100'></div>\
                     </div>";
                     }
                     },*/
                    {
                        "data": "role",
                        "render": function (data, type, row, meta) {
                            return data;
                        }
                    },

                    {
                        sortable: false,
                        "data": "action",
                        "render": function ( data, type, row, meta) {
                            let id = JSON.parse(sessionStorage.getItem('auth-user')).id;
                            return "<button class='btn btn-sm btn-success editDriver' data-id='"+data.id+"'>Edit</button>"+ (data.active == 1 ? "<button class='btn btn-sm btn-danger banDriver' data-id='"+data.id+"' "+(id === data.id ? 'disabled':'')+">Ban</button>":" <button class='btn btn-sm btn-warning unbanDriver' data-id='"+data.id+"' "+(id === data.id ? 'disabled':'')+">UnBan</button>");
                        }
                    }
                ]
            })
        }

    })
}
$(document).ready(function() {
    //$(document).find('.lds-hourglass').removeClass('.doNotShow')
    fetchTheUsers();
});


