<?php
include 'template/header.php';
?>

<?php if ($mobile): ?>
    <div style="margin-top: 50px;">
        <div>
            <img src="https://rajabotak.dataklmsad902.site/asset/images/banner-game-8.jpg?s=27767107f4b50a2ddf0ae70142beea98"
                style="width: 100%;">
        </div>
        <?php include "template/menu-outer.php" ?>

        <div style="width: 95%; margin: 0 auto 20px auto;">
            <div
                style="font-family: Teko-SemiBold; text-align: center; font-size: 24px; color: transparent !important; -webkit-background-clip: text; background-image: radial-gradient(ellipse farthest-corner at right bottom, #FEDB37 0%, #FDB931 8%, #9f7928 30%, #8A6E2F 40%, transparent 80%), radial-gradient(ellipse farthest-corner at left top, #e99c05 0%, #f4ae00 8%, #f8bf33 25%, #f8ce19 62.5%, #ffdc02 100%); padding: 10px 0;">
                SAMBUNG AYAM
                <hr
                    style="background: linear-gradient(#000 0 0) padding-box, linear-gradient(to left, #FEDB37, #8A6E2F) border-box; border-top: 2px solid transparent; margin: 0 auto; width: 70px;">
            </div>

            <ul style="list-style-type: none; padding: 0; margin-bottom: 0; display: flex; flex-wrap: wrap;">
                <?php
                $q = mysqli_query($koneksi, "SELECT * FROM tb_provider WHERE provider_type = 'AYAM'");

                while ($data = mysqli_fetch_assoc($q)):
                    $providerName = htmlspecialchars($data['provider_name']);
                    $providerImg = htmlspecialchars($data['provider_image']);
                    $slug = htmlspecialchars($data['slug']);
                    $code = $data['code'] ?? '';

                    if (empty($code)) {
                        $href = "?s=" . urlencode($slug);
                    } else {
                        $href = "play.php?game=" . urlencode($code) . "&provider=" . urlencode($slug);
                    }
                    ?>
                    <li onclick="window.location='<?= $href ?>'" style="display: inline-block; width: 50%; padding: 0 5px;">
                        <img src="<?= $providerImg ?>" alt="<?= $providerName ?>"
                            onerror="this.src='https://via.placeholder.com/300x150/667eea/ffffff?text=<?= urlencode($providerName) ?>'"
                            style="width: 100%; margin-bottom: 6px;">
                    </li>
                <?php endwhile; ?>
            </ul>
        </div>

    </div>
<?php else: ?>
    <div style="margin-top: 170px;">
        <div class="background-top" style="padding: 30px 0 50px 0;">

            <div style="width: 95%; margin: 0 auto; max-width: 1280px; padding-top: 20px;">
                <div
                    style="margin-bottom: 20px; color: var(--primary-color); font-family: Teko-SemiBold; font-size: 24px; text-align: center;">
                    SAMBUNG AYAM
                </div>

                <ul style="list-style-type: none; padding: 20px 0 0 0; margin: 0; display: flex; flex-wrap: wrap;">

                    <?php
                    $q = mysqli_query($koneksi, "SELECT * FROM tb_provider WHERE provider_type = 'AYAM'");

                    while ($data = mysqli_fetch_assoc($q)):
                        $providerName = htmlspecialchars($data['provider_name']);
                        $providerImg = htmlspecialchars($data['provider_image']);
                        $slug = htmlspecialchars($data['slug']);
                        $code = $data['code'] ?? '';

                        if (empty($code)) {
                            $href = "?s=" . urlencode($slug);
                        } else {
                            $href = "play.php?game=" . urlencode($code) . "&provider=" . urlencode($slug);
                        }
                        ?>
                        <li onclick="window.location='<?= $href ?>'"
                            style="display: inline-block; padding: 0 10px; width: 20%; margin-bottom: 20px; cursor: pointer;">
                            <img src="<?= $providerImg ?>" alt="<?= $providerName ?>" style="width: 100%; border-radius: 6px;">
                        </li>
                    <?php endwhile; ?>

                </ul>
            </div>
        </div>
    </div>
<?php endif; ?>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        const searchInput = document.querySelector(".search");
        const gameList = document.querySelectorAll("#game_list li");

        if (searchInput) {
            searchInput.addEventListener("keyup", function () {
                const keyword = this.value.toLowerCase();

                gameList.forEach(function (item) {
                    const title = item.innerText.toLowerCase();
                    item.style.display = title.includes(keyword) ? "inline-block" : "none";
                });
            });
        }
    });
</script>

<?php include 'template/footer.php' ?>