<?php
require_once __DIR__.'/../includes/db.php';
require_once __DIR__.'/../includes/auth.php';
include __DIR__.'/../includes/header.php';

$jenis = $_GET['jenis'] ?? '';
if(!$jenis) die('Jenis surat tidak valid');

$data = $mysqli->query("
SELECT p.*, i.nama_lengkap
FROM pengajuan_penghasilan_ortu p
JOIN infografis i ON p.warga_id=i.id
ORDER BY p.status='pending' DESC

");
?>

<div class="card" style="padding:18px">
<h2>📄 Pengajuan Surat: <?= strtoupper(str_replace('_',' ',$jenis)) ?></h2>

<table class="table" style="margin-top:14px">
<thead>
<tr>
  <th>Nama Warga</th>
  <th>Tanggal</th>
  <th>Status</th>
  <th>Aksi</th>
</tr>
</thead>
<tbody>

<?php while($r=$data->fetch_assoc()): ?>
<tr>
  <td><?= esc($r['nama_lengkap']) ?></td>
  <td><?= $r['tanggal_pengajuan'] ?></td>
  <td>
    <b style="color:<?= $r['status']=='pending'?'#b91c1c':'#15803d' ?>">
      <?= strtoupper($r['status']) ?>
    </b>
  </td>
  <td>
    <?php if($r['status']=='pending'): ?>
      <a class="btn small primary"
         href="acc_<?= $jenis ?>.php?id=<?= $r['id'] ?>">
         ACC
      </a>
    <?php else: ?>
      <span class="badge">Selesai</span>
    <?php endif; ?>
  </td>
</tr>
<?php endwhile; ?>

</tbody>
</table>

<a href="pengajuan_surat_menu.php" class="btn" style="margin-top:14px">
← Kembali
</a>
</div>

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