<?php
require_once '../config.php';
$_settings->require_permission('projects','ver');
?>

<div class="row">

    <!-- Total proyectos -->
    <div class="col-lg-3 col-md-4 col-sm-6">
        <div class="info-box bg-gradient-light shadow">
            <span class="info-box-icon bg-primary"><i class="fas fa-folder"></i></span>
            <div class="info-box-content">
                <span class="info-box-text">Total Proyectos</span>
                <span class="info-box-number">
                    <?= $conn->query("SELECT id FROM project_list WHERE delete_flag=0")->num_rows ?>
                </span>
            </div>
        </div>
    </div>

    <!-- En curso -->
    <div class="col-lg-3 col-md-4 col-sm-6">
        <div class="info-box bg-gradient-light shadow">
            <span class="info-box-icon bg-info"><i class="fas fa-spinner"></i></span>
            <div class="info-box-content">
                <span class="info-box-text">En Curso</span>
                <span class="info-box-number">
                    <?= $conn->query("SELECT id FROM project_list WHERE status=1 AND delete_flag=0")->num_rows ?>
                </span>
            </div>
        </div>
    </div>

    <!-- Cerrados -->
    <div class="col-lg-3 col-md-4 col-sm-6">
        <div class="info-box bg-gradient-light shadow">
            <span class="info-box-icon bg-success"><i class="fas fa-check-circle"></i></span>
            <div class="info-box-content">
                <span class="info-box-text">Cerrados</span>
                <span class="info-box-number">
                    <?= $conn->query("SELECT id FROM project_list WHERE status=2 AND delete_flag=0")->num_rows ?>
                </span>
            </div>
        </div>
    </div>

    <!-- Empleados -->
    <div class="col-lg-3 col-md-4 col-sm-6">
        <div class="info-box bg-gradient-light shadow">
            <span class="info-box-icon bg-warning"><i class="fas fa-users"></i></span>
            <div class="info-box-content">
                <span class="info-box-text">Empleados</span>
                <span class="info-box-number">
                    <?= $conn->query("SELECT id FROM employee_list")->num_rows ?>
                </span>
            </div>
        </div>
    </div>

</div>

<?php
$nuevos   = $conn->query("SELECT id FROM project_list WHERE status=0 AND delete_flag=0")->num_rows;
$curso    = $conn->query("SELECT id FROM project_list WHERE status=1 AND delete_flag=0")->num_rows;
$cerrados = $conn->query("SELECT id FROM project_list WHERE status=2 AND delete_flag=0")->num_rows;
?>

<div class="card mt-4">
    <div class="card-header bg-dark text-white">
        Proyectos por Estado
    </div>
    <div class="card-body">
        <canvas id="adminChart"></canvas>
    </div>
</div>

<script>
const adminCtx = document.getElementById('adminChart');

new Chart(adminCtx, {
    type: 'bar',
    data: {
        labels: ['Nuevos', 'En Curso', 'Cerrados'],
        datasets: [{
            label: 'Cantidad de proyectos',
            data: [<?= $nuevos ?>, <?= $curso ?>, <?= $cerrados ?>]
        }]
    }
});
</script>

