<?php
if ($c['level'] == "superadmin") {
    ?>


    <div class="page-breadcrumb">
        <div class="row">
            <div class="col-5 align-self-center">
                <h4 class="page-title">Daftar Promosi</h4>
            </div>
            <div class="col-7 align-self-center">
                <div class="d-flex align-items-center justify-content-end">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="#">Daftar Promosi</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">Menu Daftar Promosi</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
    </div>

    <div class="container-fluid">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div style="float: right;">
                            <a href="?page=tambah_promosi" class="btn btn-primary">Tambah Data Promosi</a>
                        </div>
                        <h4 class="card-title">Daftar Promosi</h4>
                        
                    </div>
                    <div class="table-responsive">
                        <table id="zero_config" class="table table-striped table-bordered ">
                            <thead>
<thead>
<tr>
    <th>#</th>
    <th>Judul</th>
    <th>Type Bonus</th>
    <th>Minimal Deposit</th>
    <th>Bonus</th>
    <th>Persen</th>
    <th>Turnover</th>
    <th>Status</th>
    <th>Aksi</th>
</tr>
</thead>
                            </thead>
                            <tbody>
                                <?php
                                $query = mysqli_query($koneksi, "SELECT * FROM tb_promosi ");
                                $no = 1;
                                while ($data = mysqli_fetch_array($query)) {
                                    ?>
                                    
<tr>
    <th scope="row"><?php echo $no++; ?></th>

    <td><?php echo $data['judul']; ?></td>

    <!-- TYPE BONUS -->
    <td>
        <?php
        if ($data['type_bonus'] == 'new_member') {
            echo '<span class="badge badge-primary">New Member</span>';
        } elseif ($data['type_bonus'] == 'deposit') {
            echo '<span class="badge badge-success">Deposit</span>';
        } elseif ($data['type_bonus'] == 'cashback') {
            echo '<span class="badge badge-warning">Cashback</span>';
        } elseif ($data['type_bonus'] == 'event') {
            echo '<span class="badge badge-info">Event</span>';
        } else {
            echo '<span class="badge badge-secondary">Unknown</span>';
        }
        ?>
    </td>

    <td>Rp. <?php echo number_format($data['minimal_deposit'], 0, ',', '.'); ?></td>

    <td>Rp. <?php echo number_format($data['bonus'], 0, ',', '.'); ?></td>

    <td>
        <?php if ($data['persen'] > 0) { ?>
            <span class="badge badge-info"><?php echo $data['persen']; ?>%</span>
        <?php } else { ?>
            <span class="text-muted">-</span>
        <?php } ?>
    </td>

    <td>Rp. <?php echo number_format($data['turnover'], 0, ',', '.'); ?></td>

    <td>
        <span class="badge <?php echo ($data['status'] == 'active') ? 'badge-success' : 'badge-secondary'; ?>">
            <?php echo ucfirst($data['status']); ?>
        </span>
    </td>

    <td>
        <a href="?page=edit_promosi&id=<?php echo $data['id']; ?>" class="btn btn-warning btn-sm">
            Edit
        </a>
        <a href="?page=hapus_promosi&id=<?php echo $data['id']; ?>"
           class="btn btn-danger btn-sm"
           onclick="return confirm('Yakin hapus promosi ini?')">
            Hapus
        </a>
    </td>
</tr>
                                    
                                    <?php
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <?php
}else{
    ?>
    <script type="text/javascript">
        window.location = "?page=dashboard";
    </script>
    <?php
}
?>
