<div class="table-responsive mt-3 mb-4 px-3">
    <table class="table table-bordered">
        <thead>
            <tr class="table-light">
                <th class=" text-center"></th>
                <th>Nama supplier</th>
            </tr>
        </thead>
        <tbody id="load">
            <?php 
                $cari       = $input['cari'];
                $limit      = $input['limit'];
                $active     = $input['active'];

                $this -> db -> like('nama', $cari);
                $total_data = $this -> db -> get('supplier') -> num_rows();

                $offset     = $limit * ($active - 1);
                $max_page   = ceil(($total_data / $limit) + 1);

                $pagination = [
                    'active'     => $active,
                    'max_page'   => $max_page,
                ];

                $this -> db -> like('nama', $cari);
                $this -> db -> limit($limit, $offset);
                $this -> db -> order_by('id', 'DESC');
                $data = $this -> db -> get('supplier') -> result();

                if($data) :
                    foreach($data as $item) : 
            ?>

            <tr>
                <td class="text-center w-px-50">
                    <button class="fa fa-ellipsis-v btn_detail_item" data-bs-toggle="dropdown"></button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><h6 class="dropdown-header">Aksi</h6></li>
                        <li>
                            <button class="dropdown-item py-2 text-warning" onclick="edit('<?= $item -> id ?>')">
                                <i class="fa fa-edit me-2"></i>
                                Edit
                            </button>
                        </li>
                        <li>
                            <button class="dropdown-item py-2 text-danger" onclick="hps('<?= $item -> id ?>', '<?= $item -> nama ?>')">
                                <i class="fa fa-trash me-2"></i>
                                Hapus
                            </button>
                        </li>
                    </ul>
                </td>
                <td>
                    <?= $item -> nama ?>
                    <div>
                        <small class="text-muted">
                            <span>ID: <?= $item -> id ?></span>
                            <span class="mx-1"> | </span>
                            <span>No Telp: <?= $item -> nohp ?></span>
                            <span class="mx-1"> | </span>
                            <span>Alamat: <?= $item -> alamat ?></span>
                        </small>
                    </div>
                </td>
            </tr>

            <?php endforeach ?>                  
            <?php endif ?>  
            
            <?php if(!empty($cari) && count($data) == 0) : ?>
                <tr>
                    <td colspan="2">
                        <div class="text-center">
                            Data tidak ditemukan
                        </div>
                    </td>
                </tr>       
            <?php elseif(count($data) == 0) : ?>  
                    <tr>
                        <td colspan="2">
                            <div class="text-center">
                                Belum ada data
                            </div>
                        </td>
                    </tr>       
            <?php endif ?>  
            
        </tbody>
    </table>
</div>

<?= $this -> app -> pagination($pagination) ?>
