<!-- ================= PAGE HEADER ================= -->
<div class="page-breadcrumb">
    <div class="row">
        <div class="col-5 align-self-center">
            <h4 class="page-title">Bonus</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 Bonus</a></li>
                        <li class="breadcrumb-item active" aria-current="page">Menu Bonus</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>

<!-- ================= CONTENT ================= -->
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">

            <div class="card">
                <div class="card-body">
                    <h4 class="card-title">Daftar Bonus</h4>
                </div>

                <div class="table-responsive">
                    <table id="zero_config" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Username</th>
                                <th>Bonus</th>
                                <th>Nominal</th>
                                <th>Status</th>
                                <th>Tanggal</th>
                                <th>Aksi</th>
                            </tr>
                        </thead>

                        <tbody>
                        <?php
                        $query = mysqli_query($koneksi, "
                        SELECT 
                            t.id,
                            t.nominal,
                            t.status,
                            t.tanggal,
                            u.username,
                            b.judul
                        FROM tb_bonus t
                        JOIN tb_user u 
                            ON u.extplayer = t.id_user
                        JOIN tb_promosi b 
                            ON b.id = t.id_bonus
                        WHERE t.status = 'Selesai'
                          AND u.refferal IS NOT NULL
                          AND u.refferal <> ''
                        ORDER BY t.id DESC
                    ");
                        $no = 1;
                        while ($data = mysqli_fetch_assoc($query)) :
                        ?>
                            <tr>
                                <td><?= $no++; ?></td>
                                <td><?= htmlspecialchars($data['username']); ?></td>
                                <td><?= htmlspecialchars($data['judul']); ?></td>
                                <td>Rp. <?= number_format($data['nominal'], 0, ',', '.'); ?></td>

                                <!-- STATUS -->
                                <td>
                                    <?php
                                    if ($data['status'] == 'Pending') {
                                        echo '<span class="badge badge-warning">Pending</span>';
                                    } elseif ($data['status'] == 'Selesai') {
                                        echo '<span class="badge badge-success">Selesai</span>';
                                    } else {
                                        echo '<span class="badge badge-danger">Batal</span>';
                                    }
                                    ?>
                                </td>

                                <!-- TANGGAL -->
                                <td><?= date('d-m-Y H:i', strtotime($data['tanggal'])); ?></td>

                                <!-- AKSI -->
                                <td>
                                    <?php if ($data['status'] == 'Pending') : ?>

                                        <a href="?page=konfirmasi_bonus&id=<?= $data['id']; ?>"
                                           class="btn btn-success btn-sm mb-1"
                                           onclick="return confirm('Konfirmasi bonus?\nBonus akan masuk ke saldo user!')">
                                            Konfirmasi
                                        </a>

                                        <a href="?page=batalkan_bonus&id=<?= $data['id']; ?>"
                                           class="btn btn-danger btn-sm"
                                           onclick="return confirm('Batalkan bonus?\nBonus akan dihapus dan tidak masuk saldo!')">
                                            Batalkan
                                        </a>

                                    <?php else : ?>
                                        <span class="text-muted">-</span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endwhile; ?>
                        </tbody>

                    </table>
                </div>
            </div>

        </div>
    </div>
</div>