<div class="px-3 pt-2 mb-3">
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead class="table-light">
                <th class="w-px-80"></th>
                <th>Pelanggan</th>
            </thead>
            <tbody>
                <?php 
                    $toko   = $this -> session -> mart_toko; 
                    $active = $input['active'];
                    $limit  = $input['limit'];
                    $cari   = $input['cari'];
                    $where  = "nama LIKE '%$cari%'";

                    $this -> db -> where($where);
                    $total_data = $this -> db -> get('pelanggan') -> num_rows();      
                    $offset     = $limit * ($active - 1);
                    $max_page   = ceil(($total_data / $limit) + 1);
                    
                    $this -> db -> where($where);
                    $this -> db -> limit($limit, $offset);
                    $this -> db -> order_by('nama');
                    $get        = $this -> db -> get('pelanggan') -> result();

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

                    if($get) :
                        foreach($get as $item) :
                ?>
                    
                    <tr>
                        <td class="text-center">
                            <button class="btn border select_plg" 
                                    data-id="<?= $item -> id ?>"
                                    data-nama="<?= $item -> nama ?>"
                            >
                                <i class="fa fa-plus"></i>
                            </button>
                        </td>
                        <td>
                            <?= $item -> nama ?>
                        </td>
                    </tr>

                <?php endforeach ?>
                <?php endif ?>

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

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