$(document).ready(function() {
    setTimeout(() => {
        const id_colab = $('#id_colab').val();
       // console.log("id_colab final:", id_colab);
        cargarEstadisticas(id_colab); // ✅ ahora pasas el valor
    }, 50);
});

function cargarEstadisticas(id_colab, mes = null, anio = null) {
    const endpoints = [
        { url: "../../controller/dashboard.php?op=total_horas_colab", target: "#lbl_usuarios_1" },
        { url: "../../controller/dashboard.php?op=total_sessiones_colab", target: "#lbl_total_equipos_1" },
        { url: "../../controller/dashboard.php?op=total_sessiones_retencion", target: "#lbl_total_retencion" },
        { url: "../../controller/dashboard.php?op=total_a_recibir", target: "#lbl_total_a_recibir" },
    ];

    endpoints.forEach(function(item) {
        $.ajax({
            url: item.url,
            type: "GET",
            data: { 
                id_colab: id_colab,
                mes: mes,
                anio: anio
            },
            dataType: "json",
            success: function(data) {
                $(item.target).text(data.total || 0);
            },
            error: function() {
                $(item.target).text("0");
            }
        });
    });
}
/*function cargarEstadisticas(id_colab) { // ✅ recibe el valor
    const endpoints = [
        { url: "../../controller/dashboard.php?op=total_horas_colab", target: "#lbl_usuarios_1" },
        { url: "../../controller/dashboard.php?op=total_sessiones_colab", target: "#lbl_total_equipos_1" },
        { url: "../../controller/dashboard.php?op=total_sessiones_retencion", target: "#lbl_total_retencion" },
        { url: "../../controller/dashboard.php?op=total_a_recibir", target: "#lbl_total_a_recibir" },
    ];

    endpoints.forEach(function(item) {
        $.ajax({
            url: item.url,
            type: "GET",
            data: { id_colab: id_colab }, // ✅ valor correcto
            dataType: "json",
            success: function(data) {
                $(item.target).text(data.total || 0);
            },
            error: function() {
                $(item.target).text("0");
            }
        });
    });
}*/
