<?php 
    $get    = $this -> db -> get('toko') -> result();
    $idtoko = $this -> session -> mart_toko;
    
    foreach($get as $item) :
        $bg = $item -> id == $idtoko ? 'bg-light' : null;
        $label = $item -> cabang == 1 ? 'Pusat' : 'Cabang'; 
?>

<div class="card border with-icon <?= $bg ?>">
    <div class="card-body">
        <a  href="javascript:ubah_toko('<?= $item -> id ?>')" 
            class="text-decoration-none text-dark d-block"
        >
            <h5 class="mb-0">
                <strong>
                    <?= $item -> nama ?>
                </strong>
            </h5>
            <small>
                <strong class="text-primary">
                    <?= $label ?>
                </strong>
            </small>
            
            <p class="mb-0 mt-2">
                <?= $item -> alamat ?>
            </p>

        </a>
        <div class="mt-2">
            <?php if($item -> id == $idtoko) : ?>
                <small>
                    <i class="fa fa-dot-circle me-1 text-success"></i>
                    Toko Aktif
                </small>
            <?php else: ?>
                <button class="badge text-bg-light border" onclick="masuk_toko('<?= $item -> id ?>')">
                    Masuk
                </button>
                <?php if($item -> cabang == 2) : ?>
                    <button class="badge text-bg-danger" onclick="hapus_toko('<?= $item -> id ?>', '<?= $item -> nama ?>')">
                        Hapus
                    </button>
                <?php endif ?>
            <?php endif ?>
        </div>
    </div>
</div>

<?php endforeach ?>
