<?php include_once 'header.php'; ?>

<section class="container mx-auto p-3">
    <nav class="flex mb-1 lg:mb-2">
        <ol class="flex items-center pb-1 overflow-x-scroll whitespace-nowrap opacity-scroll">
            <li class="inline-flex items-end pr-1">
                <a class="text-xs border-b border-transparent hover:lg:border-primary transition-all duration-200 ease-in-out undefined" href="home">Beranda</a>
            </li>
            <li class="inline-flex items-end pr-1 group">
                <div class="flex items-center">
                    <svg width="17" height="17" viewbox="0 0 24 24" fill="var(--base)" xmlns="http://www.w3.org/2000/svg" size="17">
                        <path d="m15 12 .354-.354.353.354-.353.354L15 12ZM9.354 5.646l6 6-.708.708-6-6 .708-.708Zm6 6.708-6 6-.708-.708 6-6 .708.708Z" fill="var(--base)"></path>
                    </svg><a class="text-xs pl-1 border-b border-transparent hover:lg:border-primary transition-all duration-200 ease-in-out group-last:text-primary undefined" href="slot">Slot</a>
                </div>
            </li>
        </ol>
    </nav>
    <div class="lg:flex w-full">
        <div class="w-full lg:w-80 lg:pr-3 grid lg:inline-block grid-rows-2 grid-flow-col gap-x-2 md:gap-x-2 gap-y-3 md:gap-y-4 py-2 lg:pt-0 lg:mb-3 overflow-x-scroll lg:overflow-x-hidden overflow-y-hidden whitespace-nowrap lg:whitespace-normal opacity-scroll">
         
        <!-- Daftar Provider Slot -->
        <?php
        $query_provider = "SELECT * FROM tb_provider WHERE type = 'SL' AND status = 1 ORDER BY cuid ASC";
        $result_provider = mysqli_query($koneksi, $query_provider);

        while ($row_provider = mysqli_fetch_assoc($result_provider)) {
            $nama_provider = $row_provider['providername'];
            $gambar_provider = $row_provider['slug'];
            $status_provider = $row_provider['status'];
            $provider_id = $row_provider['providerid'];
        ?>
            <a href="slot?provider=<?php echo urlencode($row_provider['slug']); ?>" class="w-20 md:w-24 lg:w-full max-h-[70px] md:max-h-28 min-w-max py-2 lg:px-3 md:py-4 lg:py-3 lg:mb-3 inline-block lg:flex lg:items-center rounded-md lg:overflow-hidden transition-all duration-300 ease-in-out bg-background-secondary lg:hover:bg-background-tertiary relative cursor-pointer group <?php echo ($status_provider == 'aktif') ? 'border border-primary lg:bg-background-tertiary' : ''; ?>">
                <?php if ($status_provider == 'baru' || $status_provider == 'promo' || in_array($provider_id, ['PR', 'PG', 'HB'])) { ?>
                    <div class="absolute h-[15px] lg:h-[20px] right-3 lg:right-0 left-3 lg:left-auto -top-2 lg:top-4 lg:bottom-4 overflow-hidden">
                        <span class="flex justify-center px-2 lg:pl-5 mb-1 text-center rounded-full lg:rounded-none transition-all duration-300 ease-in-out" style="background-color: <?php echo ($status_provider == 'baru') ? 'rgb(73, 212, 169)' : 'rgb(59, 165, 244)'; ?>;">
                            <div>
                                <span class="block uppercase text-[10px] md:text-xs font-semibold h-[15px] lg:h-[20px] lg:leading-[20px] text-black">
                                    <?php 
                                    if (in_array($provider_id, ['PRAGMATIC', 'PGSOFT', 'HABANERO'])) {
                                        echo 'PROMO';
                                    } else {
                                        echo $status_provider;
                                    }
                                    ?>
                                </span>
                            </div>
                            <span class="false hidden lg:block absolute -left-2 rotate-45 top-0 bottom-0 h-5 w-5 transition-all duration-300 ease-in-out bg-background-secondary group-hover:bg-background-tertiary"></span>
                        </span>
                    </div>
                <?php } ?>
                <figure class="w-7 md:w-9 lg:w-auto md:h-auto lg:h-7 mx-auto lg:mx-0">
                    <img alt="<?php echo $nama_provider; ?>" loading="lazy" width="0" height="0" decoding="async" data-nimg="1" class="rounded-lg w-full h-full mt-1 lg:mt-0" src="/uploads/provider/slots/<?php echo $gambar_provider; ?>" style="color: transparent;">
                </figure>
                <p class="text-[10px] lg:text-sm mt-1 lg:mt-0 text-center lg:pl-2"><?php echo $nama_provider; ?></p>
            </a>
        <?php
        }
        ?>

        </div>

        <?php
        // Ambil Data Provider
        $provider_slug = isset($_GET['provider']) ? $_GET['provider'] : 'pragmatic';
        $provider_data = mysqli_query($koneksi, "SELECT * FROM tb_provider WHERE slug = '$provider_slug' AND type = 'SL'");
        $provider_row = mysqli_fetch_assoc($provider_data);
        ?>

        <div class="lg:inline-block lg:w-full">
            <div class="hidden lg:flex justify-between pl-3 mb-4">
                <div class="flex items-center">
                    <p class="text-xs"><?php echo $provider_row['providername']; ?></p>
                </div>
                <div class="relative flex items-center w-96">
                    <span class="absolute left-1 cursor-pointer bg-background-secondary px-2">
                        <svg width="20" height="20" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <circle cx="11" cy="11" r="6" stroke="var(--base)"></circle>
                            <path d="M11 8a3 3 0 0 0-3 3M20 20l-3-3" stroke="var(--base)" stroke-linecap="round"></path>
                        </svg>
                    </span>
                    <input type="text" placeholder="Cari Game atau Vendor" class="bg-background-secondary w-full text-sm rounded-md py-2 pl-10 pr-2 mx-1 focus:outline-none">
                </div>
            </div>

            <div class="lg:pl-3 grid grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 md:gap-4 lg:gap-5">
                <?php
                $games = mysqli_query($koneksi, "
SELECT * FROM tb_gamelist 
WHERE provider = '{$provider_row['providerid']}' 
AND datatype = 'SL'
ORDER BY FIELD(gamename,
'Wild Bandito',
'Wild Bounty Showdown',
'Lucky Neko',
'Mahjong Wins',
'Mahjong Wins 2',
'Gates of Olympus Dice',
'Gates of Olympus X-mas 1000',
'Gates of Olympus Dice 1000',
'Gates of Gatot Kaca',
'Gates of Hades',
'Games in Olympus',
'Gates of LeoVegas 1000',
'Fortune Ace Super Scatter',
'Mahjong Wins 3 Black Scatter',
'Gates of Olympus 1000',
'Starlight Princess',
'Gates of Gatot Kaca 1000',
'Gates of Olympus',
'Starlight Princess 1000',
'Sweet Bonanza Super Scatter',
'Mahjong Ways',
'Mahjong Ways 2',
'Starlight Princess Super Scatter',
'Gates of Gatot Kaca Super Scatter',
'Gates of Sneaker Super Scatter',
'Gates of Olympus Super Scatter',
'Mahjong Wins Super Scatter'
) DESC
");
                while ($data_games = mysqli_fetch_array($games)) {
                    $angka_rtp = rand($isi_1_rtp_web, $isi_2_rtp_web);
                    $gambar_games = $data_games['image'];
                    $nama_games = $data_games['gamename']; 
                    $game_code = $data_games['gameid'];
                    $provider = $data_games['provider'];
                    
                    if ($angka_rtp < 30) {
                        $warna_rtp = "red";
                    } else if ($angka_rtp < 70) {
                        $warna_rtp = "yellow";
                    } else {
                        $warna_rtp = "green";
                    }
                ?>
                    <div class="relative">
                        <div class="relative z-10 rounded-xl overflow-hidden cursor-pointer group">
                            <!-- HOT Badge -->
                            <div class="absolute top-1 left-1 z-10 h-8 lg:h-9 overflow-hidden">
                                <div>
                                    <span class="text-[9px] text-center px-1 mb-1 rounded-full block font-semibold text-white" style="background-color: rgb(238, 0, 0); animation-delay: -1s;">HOT</span>
                                </div>
                            </div>

                            <!-- Game Image with link -->
                            <div class="relative group">
                                <figure class="w-full overflow-hidden aspect-square">
                                    <img alt="<?php echo $nama_games; ?>-<?php echo $provider_row['providername']; ?>" fetchpriority="high" width="300" height="300" decoding="async" data-nimg="1" class="rounded-xl w-full h-full object-cover" src="<?php echo $gambar_games; ?>" alt="<?php echo $nama_games; ?>" style="color: transparent;">
                                </figure>
                                <!-- Mobile and Desktop Play Game Button -->
                                <div class="absolute inset-0 flex items-center justify-center bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity duration-300 ease-in-out">
                                    <?php
                                    if (isset($_SESSION['id_anggota'])) {
                                        // Pengguna sudah login
                                        $href = "PlayGame.php?game_code=" . $game_code . '&p='.$provider;
                                    } else {
                                        // Pengguna belum login
                                        $href = "javascript:registerPopup({ content:'" . htmlspecialchars($isi_1_popup_teks_belum_login_web, ENT_QUOTES, 'UTF-8') . "' });";
                                    }
                                    ?>
                                    <a href="<?php echo $href; ?>" class="text-xs rounded-full py-2 px-6 justify-center bg-primary hover:brightness-90 transition-all duration-300 ease-in-out">Main Game</a>
                                </div>
                            </div>
                            <p class="text-[11px] md:text-xs mt-1 lg:mt-2 truncate"><?php echo $nama_games; ?></p>
                            <div class="progress-container">
                                <p class="percent-txt"><?php echo $angka_rtp; ?>%</p>
                                <div id="percent-bar" class="percent-bar <?php echo $warna_rtp; ?>" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="<?php echo $angka_rtp; ?>" style="width: <?php echo $angka_rtp; ?>%;"></div>
                            </div>
                        </div>
                    </div>
                <?php
                }
                ?>
            </div>

            <div class="w-full">
                <div class="flex justify-center my-5 lg:mt-8">
                    <span class="text-[10px] text-center font-medium bg-background-secondary px-3 py-2 rounded-lg">Semua game telah ditampilkan</span>
                </div>
            </div>
        </div>
        <style>
            :root {
                --primary: hsl(223 97.5% 52.7%);
            }

            .progress-container {
                position: relative;
                height: 20px;
                width: 100%;
            }

            .percent-txt {
                font-size: 12px;
                font-weight: bold;
                color: #fff;
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                z-index: 15;
            }

            .percent-bar {
                height: 100%;
                border-radius: 5px;
                background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
                background-size: 1rem 1rem;
                display: flex;
                justify-content: center;
                align-items: center;
                color: #fff;
                text-align: center;
                white-space: nowrap;
                transition: width 0.6s ease;
                -webkit-animation: progress-bar-stripes 1s linear infinite;
                animation: progress-bar-stripes 1s linear infinite;
                z-index: 10;
            }

            @-webkit-keyframes progress-bar-stripes {
                0% {
                    background-position: 1rem 0;
                }

                100% {
                    background-position: 0 0;
                }
            }

            @keyframes progress-bar-stripes {
                0% {
                    background-position: 1rem 0;
                }

                100% {
                    background-position: 0 0;
                }
            }

            .percent-bar.red {
                background-color: #ff4d4d;
            }

            .percent-bar.yellow {
                background-color: #ffcc00;
            }

            .percent-bar.green {
                background-color: #4CAF50;
            }
        </style>
</section>
<?php include_once 'footer.php'; ?>