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

    if (isset($_GET['extplayer'])) {
        $extplayer = $_GET['extplayer'];

        $query = mysqli_query($koneksi, "SELECT username, nama_lengkap, roda_hadiah FROM tb_user WHERE extplayer = '".mysqli_real_escape_string($koneksi, $extplayer)."' LIMIT 1");
        if (mysqli_num_rows($query) > 0) {
            $data = mysqli_fetch_assoc($query);
            ?>
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-5 align-self-center">
                        <h4 class="page-title">Edit Roda Hadiah - <?php echo htmlspecialchars($data['username']); ?></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="?page=roda_hadiah">Roda Hadiah User</a></li>
                                    <li class="breadcrumb-item active" aria-current="page">Edit Roda Hadiah</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">Form Edit Roda Hadiah</h4>
                                <form action="?page=proses_edit_roda_hadiah" method="POST">
                                    <input type="hidden" name="extplayer" value="<?php echo htmlspecialchars($extplayer); ?>">


                                    <div class="form-group">
                                        <label>Roda Hadiah</label>
                                        <select class="form-control" name="roda_hadiah" required>
                                            <?php
                                            $options = [
                                                1000, 1000, 1000,
                                                5000, 5000,
                                                10000, 10000,
                                                20000, 20000,
                                                25000, 25000,
                                                50000, 50000,
                                                100000,
                                                277000,
                                                900000
                                            ];
                                            // unik dan sort agar pilihan tampil rapih (optional)
                                            $options = array_unique($options);
                                            sort($options);

                                            foreach ($options as $val) {
                                                $selected = ($val == $data['roda_hadiah']) ? "selected" : "";
                                                echo '<option value="'.$val.'" '.$selected.'>'.number_format($val).'</option>';
                                            }
                                            ?>
                                        </select>
                                    </div>

                                    <button type="submit" name="submit" class="btn btn-success">Simpan</button>
                                    <a href="?page=roda_hadiah" class="btn btn-dark">Kembali</a>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <?php
        } else {
            echo "<script>alert('User tidak ditemukan.');window.location='?page=roda_hadiah';</script>";
        }
    } else {
        echo "<script>window.location='?page=roda_hadiah';</script>";
    }

} else {
    echo "<script>window.location='?page=dashboard';</script>";
}
?>