<div class="page-breadcrumb">
    <div class="row">
        <div class="col-5 align-self-center">
            <h4 class="page-title">Daftar Deposit</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 Deposit</a>
                        </li>
                        <li class="breadcrumb-item active" aria-current="page">Menu Daftar Deposit</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">
                    <h4 class="card-title">Daftar Deposit</h4>
                </div>
                <div class="table-responsive">
                    <table id="zero_config" class="table table-striped table-bordered ">
                            <thead>
                            <tr>
                                <th>#</th>
                                <th>Tanggal</th>
                                <th>Username</th>
                                <th>Metode Pembayaran</th>
                                <th>Pembayaran Dari</th>
                                <th>Jumlah</th>
                                <th>Bonus</th>
                                <th>Status Bonus</th>
                                <th>Bukti</th>
                                <th>Status</th>
                            </tr>
                            </thead>
                        <tbody>
<?php
 $query = mysqli_query($koneksi, "
    SELECT 
        t.id,
        t.tanggal,
        t.metode,
        t.total,
        t.status,
        t.gambar,
        u.username,
        bnk.nama_bank,
        tr.nominal AS bonus_nominal,
        tr.status AS status_bonus
    FROM tb_transaksi t
    JOIN tb_user u ON u.extplayer = t.id_user
    LEFT JOIN tb_bank bnk ON bnk.id_user = t.id_user
    LEFT JOIN tb_bonus tr 
        ON tr.id_user = t.id_user 
        AND DATE(tr.tanggal) = DATE(t.tanggal)
    WHERE t.transaksi = 'Top Up'
    ORDER BY t.id DESC
");

 $no = 1;
while ($data = mysqli_fetch_assoc($query)) {
    
    // Ambil nama gambar
    $nama_gambar = $data['gambar'];
    
    // Cek apakah ini bukan bonus system, dan gambar nya BENERAN ADA (bukan no-image.png atau kosong)
    $bukti_valid = ($data['metode'] != "Bonus System" && !empty($nama_gambar) && strtolower($nama_gambar) != 'no-image.png');
?>
<tr>
    <th><?php echo $no++; ?></th>
    <td><?php echo date('d-m-Y H:i', strtotime($data['tanggal'])); ?></td>
    <td><?php echo $data['username']; ?></td>
    <td><?php echo $data['metode']; ?></td>
    <td><?php echo $data['nama_bank'] ?? '-'; ?></td>
    <td>Rp. <?php echo number_format($data['total'], 0, ',', '.'); ?></td>

    <!-- BONUS -->
    <td>
        <?php
        if ($data['bonus_nominal']) {
            echo 'Rp. ' . number_format($data['bonus_nominal'], 0, ',', '.');
        } else {
            echo '-';
        }
        ?>
    </td>

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

    <!-- BUKTI TRANSFER (SUDAH DIFIX) -->
    <td>
        <?php if ($bukti_valid) { ?>
            <a href="../../uploads/bukti_transfer/<?php echo $nama_gambar; ?>" 
               class="btn btn-success btn-sm" target="_blank">
               Lihat Bukti
            </a>
        <?php } else { ?>
            <span class="text-danger" style="font-size: 12px;">
                <i class="fa fa-times-circle"></i> Tidak Ada
            </span>
        <?php } ?>
    </td>

    <!-- STATUS DEPOSIT -->
    <td>
        <?php
        if ($data['status'] == 'Sukses') {
            echo '<span class="badge badge-success">Sukses</span>';
        } elseif ($data['status'] == 'Pending') {
            echo '<span class="badge badge-warning">Pending</span>';
        } else {
            echo '<span class="badge badge-danger">Ditolak</span>';
        }
        ?>
    </td>
</tr>
<?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
/* =====================================
   MOBILE TABLE FIX - TETAP TABLE
   ===================================== */

/* Container table */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Table umum */
.table {
    min-width: 700px; /* paksa scroll horizontal */
    background: transparent;
}

/* Header */
.table thead th {
    background: #141414;
    color: #c9c9c9;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid #2a2a2a;
}

/* Body */
.table tbody td {
    font-size: 13px;
    color: #aaa;
    white-space: nowrap;
    border-top: 1px solid #1f1f1f;
}

/* Nominal / angka penting */
.table tbody td:nth-child(4),
.table tbody td strong {
    color: #f5c46b;
    font-weight: 600;
}

/* Hover */
.table tbody tr:hover {
    background: rgba(255,255,255,0.03);
}

/* Tombol */
.table .btn {
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
}

/* =========================
   MOBILE TWEAK
   ========================= */
@media (max-width: 768px) {

    .table {
        min-width: 720px;
    }

    .table thead th {
        font-size: 12px;
        padding: 10px 8px;
    }

    .table tbody td {
        font-size: 12px;
        padding: 10px 8px;
    }

    /* Scrollbar halus */
    .table-responsive::-webkit-scrollbar {
        height: 6px;
    }

    .table-responsive::-webkit-scrollbar-thumb {
        background: #444;
        border-radius: 10px;
    }
}

/* =====================================
   FIX WARNA HEADER TABLE (NYATU UI)
   ===================================== */

.table thead th {
    background: linear-gradient(
        to bottom,
        #1f2f3f,
        #1a2836
    );
    color: #cfd8e3;
    border-bottom: 1px solid #2e4053;
    border-right: 1px solid #253545;
    font-weight: 600;
}

/* Icon sort DataTable */
.table thead th i,
.table thead th::after,
.table thead th::before {
    color: #8fa3b8 !important;
}
</style>