<?php
$currentOffset = (int) $this->uri->segment(3);
$no = $currentOffset + 1;
?>
<div class="jenis-results">
  <div class="table-responsive jenis-desktop-table">
    <table class="table table-striped table-mailcard">
      <thead>
        <tr>
          <th class="text-center" style="width:60px">No</th>
          <th>Uraian</th>
          <th>No. Akun</th>
          <th class="text-right" style="min-width:220px">Status | Aksi</th>
        </tr>
      </thead>
      <tbody>
        <?php if (!empty($result)) { ?>
          <?php foreach ($result as $row) { ?>
            <?php
            $isAktif = ($row['pub'] === 'Y');
            $aktif = $isAktif
              ? '<i class="fa fa-check-circle text-white" title="Aktif"></i>'
              : '<i class="fa fa-minus-circle text-danger" title="Nonaktif"></i>';
            $akunLabel = getIdAkunPendapatan($row['id_akun']);

            if ((int) $row['id_jenis'] === 1) {
              $edit_jenis = "<a class='btn-sm text-warning' href='#'>{$row['jenis_cetakan']}</a>";
              $edit_btn = "<a class='btn btn-secondary btn-sm text-white' href='#'><i class='fa fa-edit'></i> Edit</a>";
              $hapus = "<a class='btn btn-secondary btn-sm text-white' href='#'><i class='fa fa-trash'></i> Hapus</a>";
            } else {
              $edit_jenis = "<a class='btn-sm jenis text-info' title='Edit Data' data-id='{$row['id_jenis']}' href='#'>{$row['jenis_cetakan']}</a>";
              $edit_btn = "<a class='btn btn-info btn-sm jenis text-white' title='Edit Data' data-id='{$row['id_jenis']}' href='#'><i class='fa fa-edit'></i> Edit</a>";
              $hapus = "<a class='btn btn-danger btn-sm text-white' data-id='{$row['id_jenis']}' data-toggle='modal' data-target='#confirm-delete' href='#'><i class='fa fa-trash'></i> Hapus</a>";
            }
            ?>
            <tr>
              <td class="text-center"><?= $no; ?></td>
              <td class="pl-1"><?= $edit_jenis; ?></td>
              <td class="pl-1"><?= $akunLabel; ?></td>
              <td class="text-right">
                <div class="btn-group btn-group-sm" role="group">
                  <button type="button" class="btn btn-info btn-sm" data-id="<?= $row['id_jenis']; ?>">
                    <span class="icon text-white"><?= $aktif; ?></span>
                  </button>
                  <?= $edit_btn; ?>
                  <?= $hapus; ?>
                </div>
              </td>
            </tr>
            <?php $no++; ?>
          <?php } ?>
        <?php } else { ?>
          <tr>
            <td colspan="4">Data belum ada</td>
          </tr>
        <?php } ?>
      </tbody>
    </table>
  </div>

  <div class="jenis-mobile-list">
    <?php if (!empty($result)) { ?>
      <?php
      $mobileNo = $currentOffset + 1;
      foreach ($result as $row) {
        $isAktif = ($row['pub'] === 'Y');
        $statusClass = $isAktif ? 'is-active' : 'is-inactive';
        $statusLabel = $isAktif ? 'Aktif' : 'Nonaktif';
        $akunLabel = getIdAkunPendapatan($row['id_akun']);

        if ((int) $row['id_jenis'] === 1) {
          $mobileTitle = "<a class='jenis-mobile-title is-locked' href='#'>{$row['jenis_cetakan']}</a>";
          $mobileEdit = "<a class='btn btn-secondary btn-sm text-white' href='#'><i class='fa fa-edit'></i> Edit</a>";
          $mobileDelete = "<a class='btn btn-secondary btn-sm text-white' href='#'><i class='fa fa-trash'></i> Hapus</a>";
        } else {
          $mobileTitle = "<a class='jenis-mobile-title jenis' title='Edit Data' data-id='{$row['id_jenis']}' href='#'>{$row['jenis_cetakan']}</a>";
          $mobileEdit = "<a class='btn btn-info btn-sm jenis text-white' title='Edit Data' data-id='{$row['id_jenis']}' href='#'><i class='fa fa-edit'></i> Edit</a>";
          $mobileDelete = "<a class='btn btn-danger btn-sm text-white' data-id='{$row['id_jenis']}' data-toggle='modal' data-target='#confirm-delete' href='#'><i class='fa fa-trash'></i> Hapus</a>";
        }
      ?>
        <article class="jenis-mobile-card">
          <div class="jenis-mobile-index"><?= $mobileNo; ?></div>
          <div class="jenis-mobile-content">
            <?= $mobileTitle; ?>
            <p class="jenis-mobile-account">No. Akun: <?= $akunLabel; ?></p>
          </div>
          <div class="jenis-mobile-actions">
            <?= $mobileEdit; ?>
            <?= $mobileDelete; ?>
          </div>
          <button
            type="button"
            class="jenis-mobile-status <?= $statusClass; ?>"
            title="Status: <?= $statusLabel; ?>"
            aria-label="Status: <?= $statusLabel; ?>"
          >
            <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
          </button>
        </article>
        <?php $mobileNo++; ?>
      <?php } ?>
    <?php } else { ?>
      <div class="jenis-mobile-empty">Data belum ada</div>
    <?php } ?>
  </div>

  <nav aria-label="Page navigation" class="jenis-pagination-wrap">
    <?php echo $this->ajax_pagination->create_links(); ?>
  </nav>
</div>
