<?php

require "functions.php";

$query = "SELECT * FROM provider_permainan";

if (isset($_POST["cari"])) {
    $query = cari_permainan($_POST["nama_permainan"]);
    $data_permainan = $query;
    cek_waktu($data_permainan);
} else {
    $data_permainan = query($query);
    cek_waktu($data_permainan);
}

if (isset($_GET["Id"])) {
    $provider_terpilih = $_GET["Id"];
    foreach ($array_provider as $provider) {
        if ($provider_terpilih == $provider["Provider"]) {
            $nama_provider = $provider["Nama_Provider"];
            $nama_gambar = $provider["Nama_Gambar"];
            $gambar_brand = $provider["Gambar_Brand"];
        }
    }
} else {
    $provider_terpilih = "Pragmatic_Play";
    foreach ($array_provider as $provider) {
        if ($provider_terpilih == $provider["Provider"]) {
            $nama_provider = $provider["Nama_Provider"];
            $nama_gambar = $provider["Nama_Gambar"];
            $gambar_brand = $provider["Gambar_Brand"];
        }
    }
}

// Untuk Menghitung RTP Dari Terbesar Sampai Terkecil //

// $array_baru = [];
// $data_permainan_baru = [];

// foreach ($data_permainan as $data) {
//     $array_baru[] = $data["RTP"];
// }

// rsort($array_baru);

// foreach ($array_baru as $angka) {
//     foreach($data_permainan as $data) {
//         if (!in_array($data, $data_permainan_baru)) {
//             if ($angka == $data["RTP"]) {
//                 $data_permainan_baru[] = $data;
//             }
//         }
//     }
// }

// $data_permainan = $data_permainan_baru;

// -------------------------------------------------- //

$maksimal_provider_per_halaman = 4;
$jumlah_provider = count($array_provider);
$jumlah_halaman = ceil($jumlah_provider / $maksimal_provider_per_halaman);

$array_prov_baru = [];

$b = 0;

for ($j = 0; $j < $jumlah_halaman; $j++) {
    $a = $maksimal_provider_per_halaman;
    while ($a > 0) {
        if ($b < $jumlah_provider) {
            $array_prov_baru[$j][] = $array_provider[$b];
        }

        $a--;
        $b++;
    }
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dewa89 : Situs Permainan nomor 1 di Dunia</title>
    <meta name="robots" content="index, follow">
    <meta name="description" content="RTP Khusus Dewa89, RTP paling terupdate dan paling gacor dengan jaminan pasti menang.">
    <meta name="keywords" content="Dewa89, Login Dewa89, Daftar Dewa89, Link Dewa89, Link Login Dewa89, Link Daftar Dewa89, Link alternatif Dewa89, Link RTP Dewa89, Dewa89 login, Dewa89 daftar, Scatter hitam, slot online, slot gacor, slot thailand">
    <meta property="og:site_name" content="Dewa89">
    <meta name="og:url" content="<?php print $link ?>">
    <meta name="og:title" content="Dewa89 : Situs Permainan terbaik di Dunia">
    <meta name="og:type" content="product">
    <meta property="og:description" content="RTP Khusus Dewa89, RTP paling terupdate dan paling gacor dengan jaminan pasti menang.">
    <meta property="og:image" content="https://api2-de8.imgnxb.com/images/VIJfWaw52ls/logo_e1e87d34-7f2f-4bda-8d0b-227879125585_1739792977857.png">
    <meta property="og:image:width" content="600">
    <meta property="og:image:height" content="600">
    <meta property="product:price:amount" content="20000">
    <meta property="product:price:currency" content="IDR">
    <meta property="product:availability" content="instock">
    <meta itemprop="name" content="Dewa89 : Situs Permainan nomor 1 di Dunia">
    <meta itemprop="url" content="<?php print $link ?>">
    <meta itemprop="description" content="RTP Khusus Dewa89, RTP paling terupdate dan paling gacor dengan jaminan pasti menang.">
    <!-- Bagian Ubah -->
    <link rel="stylesheet" href="<?php print $css; ?>">
    <link rel="shortcut icon" href="img/Logo_dewa.png">
</head>
<body onload="cp(2)">


    <div class="headervv">
        <img src="img/logo.gif" alt="">
    </div>

    <div class="marquee">
        <marquee behavior="" direction="">Selamat Datang Di DEWA89, menyediakan berbagai event dan bonus yang meriah!</marquee>
    </div>

    <div class="pilihan_provider">
        <div class="halaman" id="halaman_sebelumnya">
            <div class="tombol_halaman">
                <img src="Halaman Sebelumnya.png" alt="">
            </div>
        </div>
        
        <div class="list_provider" id="list_provider">

            <?php foreach ($array_prov_baru[0] as $provider) : ?>
                <?php if ($provider_terpilih == $provider["Provider"]) : ?>
                    <a>
                        <div class="provider_terpilih" id="provider_terpilih" onclick="pp('<?php print $provider['Provider'] ?>')">
                            <img src="https://img.viva88athenae.com//<?php print $provider["Gambar"] ?>" alt="">
                        </div>
                    </a>
                    <?php else : ?>
                        <a>
                            <div class="provider" onclick="pp('<?php print $provider['Provider'] ?>')">
                                <img src="https://img.viva88athenae.com//<?php print $provider["Gambar"] ?>" alt="">
                            </div>
                        </a>
                <?php endif; ?>
            <?php endforeach; ?>

        </div>
        
        <div class="halaman" id="halaman_selanjutnya">
            <div class="tombol_halaman">
                <img src="Halaman Selanjutnya.png" alt="">
            </div>
        </div>
    </div>
    
    <div id="con_a">
        <div class="judul_permainan">
            <h1><?php print $nama_provider; ?></h1>
        </div>
    </div>
    
    <div class="pencarian_permainan">
        <label for="keyword">Cari : </label>
        <input type="text" autocomplete="off" id="keyword">
    </div>
    
    <div id="con_b">
        <?php if ($data_permainan != null) : ?>
            <div class="provider_rtp" id="provider_rtp">
                <div class="rtp_list">
                
                <?php foreach ($data_permainan as $data) : ?>
                    <?php if ($provider_terpilih == $data["Provider"]) : ?>
                        <?php $pola = uraikan_teks_pola($data["Pola"]);  ?>
                        <div class="rtp">
                            <div class="gambar_rtp">
                                <img src="<?php print $nama_gambar; ?><?php print $data["Nama_Gambar"]; ?>" alt="" class="gambar">
                                <p><?php print $data["Nama_Permainan"]; ?></p>
                            </div>
        
                            <div class="pola_rtp">
                                <div class="pola">
                                    <div class="bagian_judul">
                                        <p>Pola Slot</p>
                                        <img src="https://img.viva88athenae.com/<?php print $gambar_brand ?>" alt="">
                                    </div>
        
                                    <div class="bagian_isi">
                                        <table>
                                            <?php $i = 0; ?>
                                            <?php while ($i < 3) : ?>
                                                <tr>
                                                    <td>
                                                        <p class="judul"><?php print $pola[$i][0]; ?></p>
                                                    </td>
        
                                                    <?php if ($provider_terpilih == "Pragmatic_Play") : ?>
                                                        
                                                        <td>
                                                            <?php if ($pola[$i][1] == "Off") : ?>
                                                                <p class="dot_merah">⍟</p>
                                                                <?php else : ?>
                                                                    <p class="dot_hijau">⍟</p>
                                                            <?php endif; ?>
                                                        </td>
        
                                                        <td>
                                                            <?php if ($pola[$i][1] == "Off") : ?>
                                                                <p class="dot_hijau">⍟</p>
                                                                <?php else : ?>
                                                                    <p class="dot_merah">⍟</p>
                                                            <?php endif; ?>
                                                        </td>
        
                                                        <td>
                                                            <?php if ($pola[0][1] == "Off") : ?>
                                                                <p class="dot_merah">⍟</p>
                                                                <?php else : ?>
                                                                    <p class="dot_hijau">⍟</p>
                                                            <?php endif; ?>
                                                        </td>
        
                                                        <?php else : ?>
                                                            <td class="kecil">
                                                                <?php if ($pola[$i][1] == "Off") : ?>
                                                                    <p class="dot_merah">Turbo</p><p class="dot_merah">⍟</p>
                                                                    <?php else : ?>
                                                                        <p class="dot_hijau">Turbo</p><p class="dot_hijau">⍟</p>
                                                                <?php endif; ?>
                                                            </td>
                                                    <?php endif; ?>
                                                </tr>
                                                <?php $i++; ?>
                                            <?php endwhile; ?>
                                        </table>
                                    </div>
        
                                    <div class="bagian_rtp">
                                        <div class="waktu">
                                            <p>Jam: <?php print $data["Jam_Sebelum"]; ?> - <?php print $data["Jam_Sesudah"]; ?></p>
                                        </div>
        
                                        <div class="percent">
                                            <p><?php print $data["RTP"]; ?>%</p>
                                            <?php if ($data["RTP"] > 75 && $data["RTP"] < 99) : ?>
                                                <div class="percent_bar great" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="<?php print $data["RTP"]; ?>" style="width: <?php print $data["RTP"]; ?>%;"></div>
                                                <?php elseif ($data["RTP"] == 99) : ?>
                                                    <div class="percent_bar super_great" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="<?php print $data["RTP"]; ?>" style="width: <?php print $data["RTP"]; ?>%;"></div>
                                                <?php else : ?>
                                                    <div class="percent_bar medium" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="<?php print $data["RTP"]; ?>" style="width: <?php print $data["RTP"]; ?>%;"></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endforeach; ?>
        
                </div>
            </div>
            <?php else : ?>
                <div class="permainan_tidak_ada">
                    <p>Permainan yang anda cari tidak tersedia, silahkan hubungi admin untuk menyediakan permainan yang anda cari, Terima Kasih.</p>
                </div>
        <?php endif; ?>
    </div>

<script src="<?php print $js; ?>"></script>
</body>
</html>
