<?php include "koneksi.php"; ?>

<!DOCTYPE html>
<html>
<head>
  <title>Dashboard Admin | BK 57 CARE</title>

  <!-- AdminLTE -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">

  <!-- DataTables -->
  <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap4.min.css">
</head>

<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">

  <!-- 🔝 Navbar -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <span class="navbar-brand font-weight-bold">BK 57 CARE</span>
  </nav>

  <!-- 📌 Sidebar -->
  <aside class="main-sidebar sidebar-dark-primary elevation-4">
    <a href="#" class="brand-link text-center">
      <span class="brand-text font-weight-light">Admin Panel</span>
    </a>

    <div class="sidebar">
      <nav>
        <ul class="nav nav-pills nav-sidebar flex-column">
          <li class="nav-item">
            <a href="#" class="nav-link active">
              <i class="nav-icon fas fa-home"></i>
              <p>Pengaduan</p> 
            </a>
          </li>
           <li class="nav-item">
            <a href="dashboard_admin.php" class="nav-link">
              <i class="nav-icon fas fa-home"></i>
              <p>Kembali</p> 
            </a>
          </li>
  </aside>

  <!-- 📊 Content -->
  <div class="content-wrapper p-3">

    <div class="container-fluid">

      <h4 class="mb-4">Dashboard Pengaduan</h4>

      <!-- 🔢 Statistik -->
      <div class="row">

        <?php
        $total = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM pengaduan"));
        ?>

        <div class="col-md-4">
          <div class="card bg-primary text-white">
            <div class="card-body text-center">
              <h3><?php echo $total; ?></h3>
              <p>Total Pengaduan</p>
            </div>
          </div>
        </div>

      </div>

      <!-- 📋 Table -->
      <div class="card mt-4">
        <div class="card-header">
          <h5>Data Pengaduan</h5>
        </div>

        <div class="card-body">

          <a href="export_pengaduan.php" class="btn btn-success mb-3">
            Export Excel
          </a>

          <table id="tabel" class="table table-bordered table-hover">
            <thead class="bg-light">
              <tr>
                <th>Nama</th>
                <th>Kelas</th>
                <th>Konsentrasi</th>
                <th>Masalah</th>
                <th>Tanggal</th>
              </tr>
            </thead>

<tbody>
<?php
$data = mysqli_query($koneksi, "SELECT * FROM pengaduan ORDER BY tanggal DESC");

$last_tanggal = "";
$warna = ["#728186", "#ffffff"];
$index = 0;

while ($d = mysqli_fetch_array($data)) {

  // ambil tanggal saja (tanpa jam)
  $tgl = date('Y-m-d', strtotime($d['tanggal']));

  // kalau tanggal berubah → tampilkan header + ganti warna
  if ($last_tanggal != $tgl) {
    $index++;
    $last_tanggal = $tgl;
  }

  $bg = $warna[$index % 2];

  echo "<tr style='background:$bg'>
    <td>$d[nama]</td>
    <td>$d[kelas]</td>
    <td>$d[konsentrasikeahlian]</td>
    <td>$d[masalah]</td>
    <td>$d[tanggal]</td>
  </tr>";
}

?>
</tbody>
          </table>

        </div>
      </div>

    </div>
  </div>

</div>

<!-- JS -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/js/adminlte.min.js"></script>

<!-- DataTables -->
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap4.min.js"></script>

<script>
$(document).ready(function() {
  $('#tabel').DataTable();
});
</script>

</body>
</html>