<?php include'../includes/session.php';?>
<?php include'includes/header.php';?>
<?php include'includes/sidebar.php';?>
<?php include'includes/navbar.php';?>
<?php include'includes/functions.php';?>
<style>
.sideNav{height:118vh;}
.insider{
  padding-left: 260px;
}
@media(max-width: 992px){
  .sideNav{
    height: 128vh;
  }
  .insider{
    margin-top: -50px;
    padding-left: 15px!important;
    padding-right: 15px!important;
  }
}
.the-logo{
    margin-top: 0!important;
}

@media(max-width: 992px){
  .icon-card i{
    font-size: 46px;
  }
  .content-card h4{
    font-size: 20px;
  }
  .content-card span{
    font-size: 18px;
  }
}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<?php
if ($staffRole == 'class_teacher') {
    $clastd = "SELECT class FROM class_teacher WHERE staffId = ?";
    $thepdo = $pdo->prepare($clastd);
    $thepdo->execute([$staffId]);
    $classRow = $thepdo->fetch(PDO::FETCH_ASSOC);
    $myClass = $classRow['class'];

    // Get number of class
    $classNo = $pdo->query("SELECT COUNT(*) FROM student 
        WHERE class = '$myClass' AND session = '$current_session' 
        AND term = '$current_term'")->fetchColumn();

    // Get the result status
    $approRest = "SELECT status FROM result_approval 
                WHERE class = ? AND term = ? AND session = ?";
    $queryRest = $pdo->prepare($approRest);
    $queryRest->execute([$myClass, $current_term, $current_session]);
    $countProval = $queryRest->rowCount();
    $rowproval = $queryRest->fetch(PDO::FETCH_ASSOC);
    $provalStatus = $rowproval['status'];

    if ($countProval < 1) {
        $ca_color = 'warning-text';
        $sta_text = 'Not Submitted';
        $shtW = "NS"; // shorten words for not submitted;
        $theIcon = 'fa fa-minus-circle';
    }else
    if ($provalStatus =='Pending') {
        $ca_color = 'warning-text';
        $sta_text = 'Pending';
        $shtW = "PD"; // shorten words for Pending;
        $theIcon = 'fa fa-clock';

    }else if ($provalStatus == 'Rejected') {
        $ca_color = 'warning-text';
        $sta_text = 'Rejected';
        $shtW = "RJ"; // shorten words for rejected;
        $theIcon = 'fa fa-times-circle';
    }
    else{
        $ca_color = 'success-text';
        $sta_text = 'Approved';
        $shtW = "AP"; // shorten words for approved;
        $theIcon = 'fa fa-check-circle';
    }

}
// Number of subject
$totalSub = $pdo->query("SELECT COUNT(DISTINCT(subject)) FROM teacher_assignments
WHERE staffId = '$staffId' ")->fetchColumn();

// Number of class teaches
$clasNo = $pdo->query("SELECT COUNT(DISTINCT(class)) FROM teacher_assignments
WHERE staffId = '$staffId' ")->fetchColumn();

?>
<div class="insider" style="margin-top: -15px;">
    <div class="container">
        <span style="font-weight: bold;">Hi <?php echo $username;?>, Welcome.</span>
        <div class="all-cards">
            <div class="row row-cols-2">
                <?php
                if ($staffRole == 'class_teacher') {?>
                    <div class="col-lg-3 mt-3">
                        <a href="my-students.php">
                            <div class="single-card success">
                                <div class="content-card">
                                    <h4><?=$classNo?></h4>
                                    <span>My Students</span>
                                </div>
                                <div class="icon-card">
                                    <!-- <label>$</label> -->
                                    <i class="fa fa-users"></i>
                                </div>
                            </div>
                        </a>
                    </div>
                <?php }else{?>
                    <div class="col-lg-3 mt-3">
                        <a href="profile.php">
                            <div class="single-card success">
                                <div class="content-card">
                                    <h4>-</h4>
                                    <span>My Profile</span>
                                </div>
                                <div class="icon-card">
                                    <!-- <label>$</label> -->
                                    <i class="fa fa-user"></i>
                                </div>
                            </div>
                        </a>
                    </div>
                <?php }
                ?>

                <div class="col-lg-3 mt-3">
                    <a href="my-subjects.php">
                        <div class="single-card info">
                            <div class="content-card">
                                <h4><?=$totalSub?></h4>
                                <span>My Subject(s)</span>
                            </div>
                            <div class="icon-card">
                                <i class="fa fa-book"></i>
                            </div>
                        </div>
                    </a>
                </div>

                <div class="col-lg-3 mt-3">
                    <a href="#" onclick="openStd()">
                        <div class="single-card notifications">
                            <div class="content-card">
                                <h4><?=$clasNo?></h4>
                                <span>Class Teaches</span>
                            </div>
                            <div class="icon-card">
                                <i class="fa fa-hourglass-half"></i>
                            </div>
                        </div>
                    </a>
                </div>
                <?php
                if ($staffRole == 'class_teacher') {?>
                    <div class="col-lg-3 mt-3">
                        <a href="my_class_results.php">
                            <div class="single-card invoice">
                                <div class="content-card">
                                    <h4><?=$shtW?></h4>
                                    <span>Results Status</span>
                                </div>
                                <div class="icon-card">
                                    <i class="<?=$theIcon?>"></i>
                                </div>
                            </div>
                        </a>
                    </div>
                <?php }else{?>
                    <div class="col-lg-3 mt-3">
                        <a href="records_history.php">
                            <div class="single-card invoice">
                                <div class="content-card">
                                    <h4>-</h4>
                                    <span>Records</span>
                                </div>
                                <div class="icon-card">
                                    <i class="fa fa-pen"></i>
                                </div>
                            </div>
                        </a>
                    </div>
                <?php }
                ?>
                                
            </div>
        </div>
    </div>
    <!-- Chart Section -->
    <canvas id="salesChart" width="800" height="300"></canvas>

    <script>
      const ctx = document.getElementById('salesChart').getContext('2d');
      new Chart(ctx, {
        type: 'bar',
        data: {
          labels: ['Students', 'Subject', 'Pending', 'Graded', 'May'],
          datasets: [{
            label: 'Monthly Sales (₦)',
            data: [50000, 75000, 60000, 90000, 120000],
            backgroundColor: '#007bff'
          }]
        },
        options: {
          responsive: true,
          plugins: {
            legend: { display: false },
            title: {
              display: true,
              text: 'Summary Details Overview'
            }
          }
        }
      });

      function applyFilter() {
        alert("Filter logic can be added here based on selected fields.");
      }
    </script>
</div>





<?php include'includes/footer.php';?>