<div class="main-content">
  <div class="container-fluid" style="margin-top: 50px;">
    <div class="row mb-4">
      <div class="col-12 d-flex justify-content-between align-items-center">
        <h2><i class="bi bi-building me-2"></i>Daftar UNOR</h2>
        <div>
          <a href="<?= base_url('import_unor') ?>" class="btn btn-primary">Impor Excel</a>
          <a href="<?= base_url('unor/export_excel') ?>" class="btn btn-success">Ekspor Excel</a>
        </div>
      </div>
    </div>

    <!-- Filter Pencarian -->
    <div class="card mb-4">
      <div class="card-header bg-primary text-white">
        <i class="bi bi-search me-2"></i> Filter Pencarian
      </div>
      <div class="card-body">
        <?= form_open('unor', ['method' => 'GET']) ?>
          <div class="row g-3">
            <div class="col-md-4">
              <label>Nama UNOR / Induk</label>
              <input type="text" name="search" class="form-control" value="<?= htmlspecialchars($this->input->get('search')) ?>" placeholder="Cari...">
            </div>
            <div class="col-md-4">
              <label>UNOR Induk</label>
              <select name="unor_induk_id" class="form-control">
                <option value="">-- Semua --</option>
                <?php foreach ($unor_induk_list as $u): ?>
                  <option value="<?= htmlspecialchars($u->unor_induk_id) ?>" <?= $u->unor_induk_id == $this->input->get('unor_induk_id') ? 'selected' : '' ?>>
                    <?= htmlspecialchars($u->unor_induk_nama) ?>
                  </option>
                <?php endforeach; ?>
              </select>
            </div>
            <div class="col-md-4">
              <label>UNOR Mandiri</label>
              <select name="unor_mandiri" class="form-control">
                <option value="">-- Semua --</option>
                <option value="1" <?= $this->input->get('unor_mandiri') == '1' ? 'selected' : '' ?>>Mandiri</option>
                <option value="0" <?= $this->input->get('unor_mandiri') == '0' ? 'selected' : '' ?>>Non-Mandiri</option>
              </select>
            </div>
          </div>
          <div class="mt-3">
            <button type="submit" class="btn btn-primary">Cari</button>
            <a href="<?= base_url('unor') ?>" class="btn btn-secondary">Reset</a>
          </div>
        <?= form_close() ?>
      </div>
    </div>

    <!-- Tabel Data -->
    <div class="card">
      <div class="card-header bg-success text-white">
        <i class="bi bi-list me-2"></i> Hasil (<?= count($unor) ?> data)
      </div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>No</th>
                <th>UNOR ID</th>
                <th>Jenis</th>
                <th>Nama UNOR</th>
                <th>Mandiri</th>
                <th>UNOR Atasan</th>
                <th>UNOR Induk</th>
              </tr>
            </thead>
            <tbody>
              <?php $no = 1; foreach ($unor as $u): ?>
              <tr>
                <td><?= $no++ ?></td> <!-- Kolom No otomatis -->
                <td><?= htmlspecialchars($u->unor_id) ?></td>
                <td><?= htmlspecialchars($u->jenis) ?></td>
                <td><?= htmlspecialchars($u->nama) ?></td>
                <td><?= $u->unor_mandiri ? 'Ya' : 'Tidak' ?></td>
                <td><?= htmlspecialchars($u->unor_atasan_nama ?? '-') ?></td>
                <td><?= htmlspecialchars($u->unor_induk_nama ?? '-') ?></td>
              </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>