<?php
session_start();
require_once(__DIR__ . "/../../config/db.php");
include(__DIR__ . "/../layouts/header.php");

$provider_code = "microgaming";

$getProvider = "SELECT * FROM provider WHERE provider_code = :provider_code AND status = 1";
$stmt = $db->prepare($getProvider);
$stmt->bindParam(':provider_code', $provider_code, PDO::PARAM_STR);
$stmt->execute();
$provider = $stmt->fetch(PDO::FETCH_ASSOC);

if ($provider) {
    $provider_id = $provider['provider_id'];

    $getGamelist = "SELECT * FROM gamelist WHERE game_status = 1 AND game_provider = :provider_id ORDER BY top DESC, id ASC";
    $stmt = $db->prepare($getGamelist);
    $stmt->bindParam(':provider_id', $provider_id, PDO::PARAM_INT);
    $stmt->execute();
    $gamelist = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>

    <link href="/Content/zelma-v2-beta-mobile-css" rel="stylesheet"/>
    <link href="/Content/Theme/zelma-v2-beta-mobile-<?= $config['theme']; ?>-css" rel="stylesheet"/>
    
</head>
<body data-online-id="ieMfKSE6HwtuUuG0k9xIh0peSoPwiCF2AS/dC5W7L6Totas4mp8Zjg=="
      data-route="slots/pragmatic" style="--expand-icon-src: url(//d33egg70nrp50s.cloudfront.net/Images/icons/expand.gif?v=20241125);
      --collapse-icon-src: url(//d33egg70nrp50s.cloudfront.net/Images/icons/collapse.gif?v=20241125);
      --play-icon-src: url(//d33egg70nrp50s.cloudfront.net/Images/icons/play.png?v=20241125);
      --desktop-icon-src: url(//d33egg70nrp50s.cloudfront.net/Images/icons/desktop-white.png?v=20241125);
      --jquery-ui-444444-src: url(//d33egg70nrp50s.cloudfront.net/Images/jquery-ui/ui-icons_444444_256x240.png?v=20241125);
      --jquery-ui-555555-src: url(//d33egg70nrp50s.cloudfront.net/Images/jquery-ui/ui-icons_555555_256x240.png?v=20241125);
      --jquery-ui-ffffff-src: url(//d33egg70nrp50s.cloudfront.net/Images/jquery-ui/ui-icons_ffffff_256x240.png?v=20241125);
      --jquery-ui-777620-src: url(//d33egg70nrp50s.cloudfront.net/Images/jquery-ui/ui-icons_777620_256x240.png?v=20241125);
      --jquery-ui-cc0000-src: url(//d33egg70nrp50s.cloudfront.net/Images/jquery-ui/ui-icons_cc0000_256x240.png?v=20241125);
      --jquery-ui-777777-src: url(//d33egg70nrp50s.cloudfront.net/Images/jquery-ui/ui-icons_777777_256x240.png?v=20241125);">


<?php include(__DIR__ . "/../layouts/navbar.php"); ?>

        <div class="slots-games-container">
            <div class="games-filter-section">
                <div class="name-filter">
                    <div class="title">
                        <?= htmlspecialchars($provider['provider_name'], ENT_QUOTES, 'UTF-8'); ?>
                    </div>
                    <input type="text" id="filter_input" placeholder="Cari Permainan">
                </div>
            </div>
            <div class="bigger-game-list">
                <ul id="game_list" data-is-logged-in="true" style="--star-on-icon: url(//d33egg70nrp50s.cloudfront.net/Images/icons/star-on.svg?v=20241125); --star-off-icon: url(//d33egg70nrp50s.cloudfront.net/Images/icons/star-off.svg?v=20241125);">
                    
                    <?php
                    if ($provider) {
                      if (!empty($gamelist)) {
                        foreach ($gamelist as $game) {
                          $game_code = $game['game_code'];
                    
                          if (isset($_SESSION['user_id'])) {
                            $extplayer = $user['extplayer'];
                            $playUrl = "/open-game?user_code=$extplayer&provider_code=$provider_code&game_code=$game_code";
                          } else {
                            $playUrl = "/mobile/login";
                          }
                          
                          $angka_rtp = mt_rand(20, 100) ?? 0;
                          $warna_rtp = ($angka_rtp < 45) ? "low" : (($angka_rtp < 70) ? "medium" : "high");

                    ?>
                    <li class="game-item" data-game="<?= $game['game_name']; ?>" style="order: 55;">
                        <?php if (isset($_SESSION['user_id'])): ?>
                        <input type="checkbox" data-provider="<?= $provider_code; ?>" value="<?= $game['game_code']; ?>" id="<?= $game['game_code']; ?>" class="favourite-game-btn">
                        <label for="<?= $game['game_code']; ?>"></label>
                        <?php endif; ?>
                        <label class="inner-game-item">
                            <input type="radio" name="game-list-radio-button">
                            <div class="wrapper-container">
                                <img src="//aura9aming.github.io/assets/img/provider/MG/<?= $game['game_code']; ?>.png" alt="<?= $game['game_name']; ?>">
                                <!--<div class="rtp-container">-->
                                <!--    <span class="rtp-title">RTP</span>-->
                                <!--    <div class="rtp-progress">-->
                                <!--        <div class="rtp-progress-bar" data-rtp="<?= $warna_rtp; ?>" style="width: <?= $angka_rtp; ?>%;"></div>-->
                                <!--    </div>-->
                                <!--    <span class="rtp-percentage"><?= $angka_rtp; ?>%</span>-->
                                <!--</div>-->
                                <span class="link-container">
                                    <a class="play-now" data-game="<?= $game['game_name']; ?>" href="javascript:openNewTab('<?= $playUrl; ?>', 'Slots')">MAIN</a>
                                </span>
                            </div>
                            <div class="game-name"><?= $game['game_name']; ?></div>
                        </label>
                    </li>
                    <?php
                      }
                    } else {
                        echo "<li class='no-games'>No games found.</li>";
                      }
                    } else {
                      echo "<li class='no-provider'>Provider not found.</li>";
                    }
                    ?>
                </ul>
            </div>
        </div>

<?php
include(__DIR__.'/../layouts/footer.php');
include(__DIR__.'/../layouts/sidebar.php');
?>

<div id="popup_modal" class="modal popup-modal" role="dialog" data-title="" aria-label="Popup Modal">
    <div class="modal-dialog">
        <div class="modal-content" style="--desktop-popup-alert-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/<?= $config['theme']; ?>/desktop/layout/popup/alert.png?v=20241125);;--desktop-popup-notification-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/<?= $config['theme']; ?>/desktop/layout/popup/notification.png?v=20241125);;--mobile-popup-alert-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/<?= $config['theme']; ?>/mobile/layout/popup/alert.png?v=20241125);;--mobile-popup-notification-src: url(//d33egg70nrp50s.cloudfront.net/Images/v-zelma-v2-beta/<?= $config['theme']; ?>/mobile/layout/popup/notification.png?v=20241125);;--event-giveaway-popper-src: url(//d33egg70nrp50s.cloudfront.net/Images/giveaway/popper.png?v=20241125);">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="popup_modal_title">
                    
                </h4>
            </div>
            <div class="modal-body" id="popup_modal_body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="popup_modal_dismiss_button">
                    OK
                </button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal" id="popup_modal_cancel_button" style="display: none">
                    Tidak
                </button>
                <button type="button" class="btn btn-primary" id="popup_modal_confirm_button" style="display: none">
                    Ya
                </button>
            </div>
        </div>
    </div>
</div>


<script src='/bundles/zelma-v2-beta-mobile-js' defer></script>
    
    <script src='/bundles/Slots/zelma-v2-beta-mobile-js' defer></script>


        <script>
            window.addEventListener('DOMContentLoaded', () => {
                initializeSlotGames({
                    directoryPath: '//d33egg70nrp50s.cloudfront.net/Images/providers/',
                    provider: 'PP',
                    translations: {
                        playNow: 'MAIN',
                        demo: 'COBA',
                    }
                });
            });
        </script>

<script>
document.addEventListener("DOMContentLoaded", function () {
    const searchInput = document.getElementById("filter_input");
    const gameList = document.getElementById("game_list").getElementsByTagName("li");

    searchInput.addEventListener("keyup", function () {
        let filter = searchInput.value.toLowerCase();

        Array.from(gameList).forEach(function (gameItem) {
            let gameName = gameItem.querySelector(".game-name").textContent.toLowerCase();
            if (gameName.includes(filter)) {
                gameItem.style.display = "";
            } else {
                gameItem.style.display = "none";
            }
        });
    });
});
</script>

        <script type="text/javascript">
        navigator.serviceWorker.getRegistrations().then(registrations => {
            for (const registration of registrations) {
                registration.unregister();
            }
        });
    </script>

    <div class="search-popup-container" id="search_popup_container"></div>

    <script src='/bundles/reserve-js?v=8ZkoZ3svUa1mm3fUna_DT0LFrjbAHZVOgr4xzLxrZZ81' defer></script>

</body>
</html>
