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

$gestor_id = $_settings->userdata('id');
?>

<div class="row">

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

    <!-- En curso -->
    <div class="col-lg-4 col-md-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 gestor_id={$gestor_id}
                        AND status=1 AND delete_flag=0
                    ")->num_rows ?>
                </span>
            </div>
        </div>
    </div>

    <!-- En riesgo -->
    <div class="col-lg-4 col-md-6">
        <div class="info-box bg-gradient-light shadow">
            <span class="info-box-icon bg-danger"><i class="fas fa-exclamation-triangle"></i></span>
            <div class="info-box-content">
                <span class="info-box-text">En Riesgo</span>
                <span class="info-box-number">
                    <?= $conn->query("
                        SELECT id FROM project_list
                        WHERE gestor_id={$gestor_id}
                        AND status=1 AND avance < 50
                    ")->num_rows ?>
                </span>
            </div>
        </div>
    </div>

</div>
<?php
$id = $_settings->userdata('id');

$curso    = $conn->query("SELECT id FROM project_list WHERE gestor_id={$id} AND status=1")->num_rows;
$cerrados = $conn->query("SELECT id FROM project_list WHERE gestor_id={$id} AND status=2")->num_rows;
?>

<div class="card mt-4">
    <div class="card-header bg-info text-white">
        Mis Proyectos
    </div>
    <div class="card-body">
        <canvas id="gestorChart"></canvas>
    </div>
</div>

<script>
new Chart(document.getElementById('gestorChart'), {
    type: 'doughnut',
    data: {
        labels: ['En Curso', 'Cerrados'],
        datasets: [{
            data: [<?= $curso ?>, <?= $cerrados ?>]
        }]
    }
});
</script>

