<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:20px">
  <div>
    <h2 style="font-size:1.2rem;font-weight:700">📦 Histori Bantuan</h2>
    <p class="text-muted text-sm"><?= e($ri['nama']) ?> · <?= count($data) ?> catatan penyaluran</p>
  </div>
  <a href="<?= APP_URL ?>/rumah-ibadah/bantuan/tambah" class="btn btn-success">➕ Catat Bantuan Baru</a>
</div>

<div class="filters-bar">
  <input type="text" id="search-b" class="form-control" placeholder="🔍 Cari nama warga, kategori..." style="max-width:280px">
</div>

<div class="card">
  <div class="card-body no-pad">
    <div class="table-wrap">
      <table id="tbl-b">
        <thead>
          <tr><th>Kode</th><th>Warga</th><th>Kategori</th><th>Jumlah</th><th>Tanggal</th><th>Status</th></tr>
        </thead>
        <tbody>
          <?php foreach($data as $b): ?>
          <tr>
            <td><code style="font-size:0.72rem;background:#f1f5f9;padding:1px 5px;border-radius:3px"><?= e($b['kode_bantuan']) ?></code></td>
            <td style="font-weight:600"><?= e($b['warga']) ?></td>
            <td><span class="badge badge-green"><?= e($b['kategori']) ?></span></td>
            <td class="text-sm">
              <?= $b['jumlah'] ? ($b['satuan']==='rupiah' ? formatRupiah($b['jumlah']) : number_format($b['jumlah']).' '.$b['satuan']) : '—' ?>
            </td>
            <td class="text-sm"><?= formatTanggal($b['tanggal_penyaluran']) ?></td>
            <td><span class="badge badge-green">✅ <?= ucfirst($b['status']) ?></span></td>
          </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    </div>
    <?php if(empty($data)): ?>
    <div class="empty-state">
      <div class="empty-state-icon">📭</div>
      <h3>Belum ada penyaluran</h3>
      <p>Mulai catat penyaluran bantuan pertama Anda</p>
      <a href="<?= APP_URL ?>/rumah-ibadah/bantuan/tambah" class="btn btn-success" style="margin-top:12px">➕ Catat Bantuan</a>
    </div>
    <?php endif; ?>
  </div>
</div>
<script>document.addEventListener('DOMContentLoaded',()=>App.initTableSearch('search-b','tbl-b'));</script>
