let asistencias = [];

function buscar() {
    let busqueda = "";

    $("#tblAsistenciaDocentes").DataTable().destroy();
    $("#tblAsistenciaDocentes").DataTable({
        iDisplayLength: 50,
        bStateSave: false,
        autoWidth: false,
        responsive: true,
        stateSave: true,
        columnDefs: [{
                orderable: false,
                width: '100px',
                targets: [8]
            }],
        dom: '<"datatable-header"fl><"datatable-scroll-wrap"t><"datatable-footer"ip>',
        "processing": true,
        "serverSide": false,
        "data": asistencias,
        "columns": [{"data": "fila"},
            {"data": "nombres"},
            {"data": "dni"},
            // {"data": "sede"},
            {"data": "area"},
            {"data": "cargo"},
            {
                "data": "fecha_asistencia",
                "className": 'text-center'
            },
            {
                "data": "hora_ingreso",
                "className": 'text-center'
            },
            {
                "data": "hora_salida",
                "className": 'text-center'
            },
            {
                "data": "observacion",
                "className": 'text-center',
                render: function (data) {
                    let label = '';
                    let obs = ['', 'AsistiÃ³', 'No marcÃ³', 'Falta con aviso', 'Falta sin aviso', 'Tardanza', 'Vacaciones', 'Feriado', 'LSGH', 'LCGH'];
                    debugger
                    switch (data) {
                        case "1"://AsistiÃ³
                            label = "label label-success";
                            break;
                        case "2"://No marco
                            label = 'label label-info';
                            break;
                        case "3"://'Falta con aviso'
                        case "4"://'Falta sin aviso'
                            label = 'label label-danger';
                            break;
                        case "5"://'Tardanza'
                            label = 'label label-warning';
                            break;
                        case "6"://'Vacaciones'
                        case "7"://'Feriado'
                        case "8"://'LSGH'
                        case "9"://'LCGH'
                            label = 'label label-primary';
                            break;
                        default:
                            label = 'label label-default';
                    }

                    debugger
                    console.log(label);

                    return `<span class="${label}" style="font-size: 12px">${obs[data]}</span>`;
                }
            }
        ],
        fnInitComplete: function (settings, data) {
            console.log(data);
        }
    });

}


//$("#dp").datepicker({
//    minDate: new Date(1900, 1 - 1, 1), maxDate: '-18Y',
//    dateFormat: 'dd/mm/yy',
//    defaultDate: new Date(1970, 1 - 1, 1),
//    changeMonth: true,
//    changeYear: true,
//    yearRange: '-110:-18',
//    onSelect: function () {
//        $(this).valid();
//    }
//});



//$("#dtpFechaInicio").datepicker('setDate', 'now');


$().ready(function () {
    console.log("awsdfasdf");
    defaultConfigDataTable();
    $('.selectpicker').selectpicker({
        style: 'btn-info',
        size: 4
    });


    $(".btn.dropdown-toggle.bs-placeholder").removeClass("btn-info");
    $(".btn.dropdown-toggle.bs-placeholder").css({
        border: "1px solid #ddd",
        backgroundColor: "#fff"
    });

    $("#dpFechaInicio").datepicker({
        minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
        dateFormat: 'dd/mm/yy',
        defaultDate: new Date(),
        changeMonth: true,
        changeYear: true,
        yearRange: '-18:+0',
        onSelect: function () {
//        $(this).valid();
        }
    });
    $("#dpFechaInicio").datepicker('setDate', 'now');

    $("#dpFechaFin").datepicker({
        minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
        dateFormat: 'dd/mm/yy',
        defaultDate: new Date(),
        changeMonth: true,
        changeYear: true,
        yearRange: '-18:+0',
        onSelect: function () {
//        $(this).valid();
        }
    });
    $("#dpFechaFin").datepicker('setDate', 'now');

    defaultConfigDatePicker();
});