<?php
global $zon, $site_url;
$user_ip = $_SERVER['REMOTE_ADDR'];
$data = [];
if (isset($zon['page'][1])) {
    $game_name = urldecode(str_replace("-", " ", $zon['page'][1]));
    $data = dataBy("SELECT * FROM zon_games WHERE game_name='$game_name'")[0];
    $game_id = $data['id'];
}

if(empty($data)) {
    echo "<script>window.location.href = '/404'</script>";
}


ini_set('display_errors', 0);
error_reporting(E_ALL);

?>
<script>
    poki = {
        game_id: <?= $data['id'] ?>,
        game_name: "<?= $data['game_name'] ?>",
        url: "<?= $site_url ?>"
    }

</script>

<div class="thank-you-popup">
    Thank you 😊
</div>

<div class="report-popup shadow-lg">
    <div class="header flex justify-between items-center gap-2">
        <div class="left flex items-center gap-2">
            <div class="symbol flex justify-center items-center h-10 w-10 rounded-full">
                <svg width="20px" height="20px" stroke-width="1.1" viewBox="0 0 24 24" fill="none"
                    xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                    <path
                        d="M5 15L5.95039 4.54568C5.97849 4.23663 6.23761 4 6.54793 4H20.343C20.6958 4 20.9725 4.30295 20.9405 4.65432L20.0496 14.4543C20.0215 14.7634 19.7624 15 19.4521 15H5ZM5 15L4.4 21"
                        stroke="#000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
                    </path>
                </svg>
            </div>
            <div class="text">
                <div class="font-bold text-xs text-gray-500 uppercase">WHAT BUG DID YOU FIND IN</div>
                <div class="font-bold text-lg text-black capitalize">
                    <?= $data['game_name'] ?>?
                </div>
            </div>
        </div>
        <div class="close-popup">
            <button onclick="this.parentNode.parentNode.parentNode.classList.remove('active')"
                class="h-10 w-10 flex justify-center items-center active:scale-1.1 rounded-full hover:bg-gray-200">
                <svg width="20px" height="20px" stroke-width="1.1" viewBox="0 0 24 24" fill="none"
                    xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                    <path
                        d="M6.75827 17.2426L12.0009 12M17.2435 6.75736L12.0009 12M12.0009 12L6.75827 6.75736M12.0009 12L17.2435 17.2426"
                        stroke="#000" style="stroke: var(--theme-color);" stroke-width="3" stroke-linecap="round"
                        stroke-linejoin="round"></path>
                </svg>
            </button>
        </div>
    </div>
    <div class="body">
        <textarea id="report_textarea" class="text-sm"
            placeholder="Help us understand the bug you found... and please only share info on the bug itself"></textarea>

        <svg style="position: absolute; bottom: 0; left: 0" width="176" height="88" viewBox="0 0 176 88" fill="none"
            xmlns="http://www.w3.org/2000/svg">
            <path
                d="m109.1 128.5 14 118.9-42.2-37-8.3 23.2-30.4-22.3-55.5 66.6 4.2-90.2-75.3 15.7 74.4-77-14.2-112.2 50.4 32.5L52 26.3l23 31.1 67.7-31.1-33.7 102.2Z"
                fill="#FFD100" />
            <path d="m26.2 46.7 25.9-20.4v37L26.2 46.8Z" fill="#FFC500" />
            <path d="M75 57.5 52.1 26.3v37l4.2 2.8L75 57.5Z" fill="#FFED85" />
            <path d="m56.3 128.5-40 25 25.3-80.7 14.7 55.7Z" fill="#FF9E00" />
            <path d="m41.6 72.8 101.2-46.5-86.5 102.2-14.7-55.7Z" fill="#FFAF00" />
            <path d="m-24.2 14.2 80.5 52-14.7 6.6-65.8-58.6Z" fill="#FFDC00" />
            <path d="m41.6 72.8-126 130.6 100.8-49.9 25.2-80.7Z" fill="#FFC500" />
        </svg>

        <div class="flex justify-between">
            <div></div>
            <button
                class="mt-6 bg-[var(--theme-color)] px-6 py-2 send-report text-white hover:px-8 font-bold rounded-full">Send</button>
        </div>

    </div>
</div>
<div class="m-grid-start home game-page">
    <?= LoadFile('navbar/content') ?>
    <style>
        @media screen and (max-width: 600px) {
            .gameplay-container {
                overflow: hidden;
                background-color: transparent !important;
                background-image: url('<?= $data['game_image_url'] ?>') !important;
            }
        }
    </style>
    <div class="gameplay-container on-mobile mx-2">
        <button onclick="open_fullscreen()" class="back-button hidden" id="draggable">
            <img draggable="false" src="<?= $site_url ?>static/img/logo/<?= $zon['config']['site_logo_sm'] ?>"
                alt="<?= $data['game_name'] ?>" width="30" />
        </button>
        <div class="play-frame hidden">
            <div class="play-button">
                <button onclick="open_fullscreen()">
                    <svg width="20px" height="20px" stroke-width="1.1" viewBox="0 0 24 24" fill="none"
                        xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                        <path
                            d="M6.90588 4.53682C6.50592 4.2998 6 4.58808 6 5.05299V18.947C6 19.4119 6.50592 19.7002 6.90588 19.4632L18.629 12.5162C19.0211 12.2838 19.0211 11.7162 18.629 11.4838L6.90588 4.53682Z"
                            stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"></path>
                    </svg>
                </button>
                <div class="game-name font-bold capitalize text-lg mt-3">
                    Play now
                </div>
            </div>
        </div>
        <iframe id="game" src="<?= $data['game_url'] ?>" frameborder="0"></iframe>
        <div class="game-details py-2 px-2">
            <div class="flex justify-between items-center">
                <div class="left">
                    <div class="flex gap-2 items-center">
                        <img src="<?= $data['game_image_url'] ?>" class="h-10 w-10 rounded-md" />
                        <div class="text">
                            <h4 class="text-md font-bold">
                                <?= $data['game_name'] ?>
                            </h4>
                            <a href="<?= $site_url . strtolower(str_replace(' ', '-', $data['game_category'])) ?>"
                                class="text-sm text-gray-500 capitalize">
                                <?= $data['game_category'] ?> Games
                            </a>
                        </div>
                    </div>
                </div>
                <!-- after full screen content of game details -->
                <div class="game-basic-info">
                    <div class="flex gap-2 items-center">
                        <img src="<?= $data['game_image_url'] ?>" class="h-10 w-10 rounded-md" />
                        <div class="text">
                            <h4 class="text-md font-bold">
                                <?= $data['game_name'] ?>
                            </h4>
                            <p class="text-sm text-gray-500 capitalize">
                                <?= $data['game_category'] ?> Games
                            </p>
                        </div>
                    </div>
                </div>
                <a href="<?= $site_url ?>" class="logo">
                    <img src="<?= $site_url ?>static/img/logo/<?= $zon['config']['site_logo_light'] ?>"
                        alt="<?= $zon['config']['site_name'] ?>" width="80" />
                </a>
                <div class="minimize">
                    <div class="icon-group">
                        <button onclick="open_fullscreen()">
                            <svg width="24" height="24" viewBox="0 0 48 48" fill="none"
                                xmlns="http://www.w3.org/2000/svg">
                                <path style="stroke-width: 6;" d="M33 6V15H42" stroke="#fff" stroke-width="6"
                                    stroke-linecap="round" stroke-linejoin="round" />
                                <path style="stroke-width: 6;" d="M15 6V15H6" stroke="#fff" stroke-width="6"
                                    stroke-linecap="round" stroke-linejoin="round" />
                                <path style="stroke-width: 6;" d="M15 42V33H6" stroke="#fff" stroke-width="6"
                                    stroke-linecap="round" stroke-linejoin="round" />
                                <path style="stroke-width: 6;" d="M33 42V33H41.8995" stroke="#fff" stroke-width="6"
                                    stroke-linecap="round" stroke-linejoin="round" />
                            </svg>
                        </button>
                        <label for="">minimize</label>
                    </div>
                </div>
                <div class="right flex gap-5">
                    <div class="icon-group">
                        <button id="Like" tooltip="Like"
                            class="<?= num_rows(T_ZON_LIKES, "game_id=$game_id && user_ip='$user_ip'") > 0 ? 'active' : '' ?>">
                            <svg width="20px" height="20px" stroke-width="1.1" viewBox="0 0 24 24" fill="none"
                                xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                                <path
                                    d="M16.4724 20H4.1C3.76863 20 3.5 19.7314 3.5 19.4V9.6C3.5 9.26863 3.76863 9 4.1 9H6.86762C7.57015 9 8.22116 8.6314 8.5826 8.02899L11.293 3.51161C11.8779 2.53688 13.2554 2.44422 13.9655 3.33186C14.3002 3.75025 14.4081 4.30635 14.2541 4.81956L13.2317 8.22759C13.1162 8.61256 13.4045 9 13.8064 9H18.3815C19.7002 9 20.658 10.254 20.311 11.5262L18.4019 18.5262C18.1646 19.3964 17.3743 20 16.4724 20Z"
                                    stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"></path>
                                <path d="M7 20L7 9" stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"
                                    stroke-linejoin="round"></path>
                            </svg>
                        </button>
                        <label id="Like_Count">
                            <?= formatNumber(count(dataBy("SELECT * FROM zon_likes WHERE game_id=$game_id"))) ?>
                        </label>
                    </div>
                    <div class="icon-group">
                        <button id="Dislike" tooltip="Dislike"
                            class="<?= num_rows(T_ZON_DISLIKES, "game_id=$game_id && user_ip='$user_ip'") > 0 ? 'active' : '' ?>">
                            <svg width="20px" height="20px" stroke-width="1.1" viewBox="0 0 24 24" fill="none"
                                xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                                <path
                                    d="M16.4724 3.5H4.1C3.76863 3.5 3.5 3.76863 3.5 4.1V13.9C3.5 14.2314 3.76863 14.5 4.1 14.5H6.86762C7.57015 14.5 8.22116 14.8686 8.5826 15.471L11.293 19.9884C11.8779 20.9631 13.2554 21.0558 13.9655 20.1681C14.3002 19.7497 14.4081 19.1937 14.2541 18.6804L13.2317 15.2724C13.1162 14.8874 13.4045 14.5 13.8064 14.5H18.3815C19.7002 14.5 20.658 13.246 20.311 11.9738L18.4019 4.97376C18.1646 4.10364 17.3743 3.5 16.4724 3.5Z"
                                    stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"></path>
                                <path d="M7 14.5L7 3.5" stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"
                                    stroke-linejoin="round"></path>
                            </svg>
                        </button>
                        <label id="Dislike_Count">
                            <?= formatNumber(count(dataBy("SELECT * FROM zon_unlikes WHERE game_id=$game_id"))) ?>
                        </label>
                    </div>

                    <div class="more-option flex gap-4">
                        <div onclick="document.querySelector('.report-popup').classList.toggle('active')"
                            class="icon-group">
                            <button tooltip="Report a bug">
                                <svg width="20px" height="20px" stroke-width="1.1" viewBox="0 0 24 24" fill="none"
                                    xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                                    <path
                                        d="M5 15L5.95039 4.54568C5.97849 4.23663 6.23761 4 6.54793 4H20.343C20.6958 4 20.9725 4.30295 20.9405 4.65432L20.0496 14.4543C20.0215 14.7634 19.7624 15 19.4521 15H5ZM5 15L4.4 21"
                                        stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"
                                        stroke-linejoin="round">
                                    </path>
                                </svg>
                            </button>
                            <label class="opacity-0" for="">Report</label>
                        </div>

                        <div id="full_screen" onclick="open_fullscreen()" class="icon-group">
                            <button tooltip="Full screen">
                                <svg width="24" height="24" viewBox="0 0 48 48" fill="none"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path d="M33 6H42V15" stroke="#ffffff" style="stroke-width: 6;" stroke-width="9"
                                        stroke-linecap="round" stroke-linejoin="round" />
                                    <path d="M42 33V42H33" stroke="#ffffff" style="stroke-width: 6;" stroke-width="9"
                                        stroke-linecap="round" stroke-linejoin="round" />
                                    <path d="M15 42H6V33" stroke="#ffffff" style="stroke-width: 6;" stroke-width="9"
                                        stroke-linecap="round" stroke-linejoin="round" />
                                    <path d="M6 15V6H15" stroke="#ffffff" style="stroke-width: 6;" stroke-width="9"
                                        stroke-linecap="round" stroke-linejoin="round" />
                                </svg>
                            </button>
                            <label class="opacity-0" for="">full screen</label>
                        </div>
                    </div>

                    <div onclick="document.querySelector('.more-option').classList.toggle('active')"
                        class="icon-group more-opt-button hidden">
                        <button tooltip="More options" class="fill">
                            <svg width="20px" height="20px" viewBox="0 0 24 24" stroke-width="1.1" fill="none"
                                xmlns="http://www.w3.org/2000/svg" color="#8c8c8c">
                                <path
                                    d="M12 12.5C12.2761 12.5 12.5 12.2761 12.5 12C12.5 11.7239 12.2761 11.5 12 11.5C11.7239 11.5 11.5 11.7239 11.5 12C11.5 12.2761 11.7239 12.5 12 12.5Z"
                                    fill="#8c8c8c" stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"
                                    stroke-linejoin="round"></path>
                                <path
                                    d="M12 20.5C12.2761 20.5 12.5 20.2761 12.5 20C12.5 19.7239 12.2761 19.5 12 19.5C11.7239 19.5 11.5 19.7239 11.5 20C11.5 20.2761 11.7239 20.5 12 20.5Z"
                                    fill="#8c8c8c" stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"
                                    stroke-linejoin="round"></path>
                                <path
                                    d="M12 4.5C12.2761 4.5 12.5 4.27614 12.5 4C12.5 3.72386 12.2761 3.5 12 3.5C11.7239 3.5 11.5 3.72386 11.5 4C11.5 4.27614 11.7239 4.5 12 4.5Z"
                                    fill="#8c8c8c" stroke="#8c8c8c" stroke-width="1.1" stroke-linecap="round"
                                    stroke-linejoin="round"></path>
                            </svg>
                        </button>
                        <label class="opacity-0" for="">options</label>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
    $game_name = $data['game_name'];
    $game_category = $data['game_category'];
    foreach (dataBy("SELECT * FROM zon_games ORDER BY id ASC LIMIT 219") as $game) { ?>
        <div data-card-size="<?= $game['game_card_size'] == 'md' ? 'md' : '' ?>"
            data-game-f="<?= $game['is_featured'] == 1 ? 'Yes' : 'No' ?>"
            class="m-game-card wow <?php echo $zon['config']['animate_class'] ?>">
            <a class="m-game-link" href="<?= $site_url ?>g/<?= makeSlug($game['game_name']) ?>">
                <picture style="background-image: url('<?= $game['game_image_url'] ?>')" class="m-game-thumbnail">
                    <div class="m-game-details">
                        <p>
                            <?= $game['game_name'] ?>
                        </p>
                    </div>
                </picture>
            </a>
        </div>
    <?php } ?>
</div>

<div class="mx-2">
    <div class="m-category-grid">
        <?php foreach (getCategory() as $category) {
            $game = GameByCategoryWise($category['name'], 1)[0];
            ?>
            <a href="<?= $site_url . urlencode(makeSlug($category['name'])) ?>">
            <div class="m-category-card wow <?php echo $zon['config']['animate_class'] ?>">
                <img src="<?= $game['game_image_url'] ?>" alt="<?= $category['name'] ?>">
                <div class="text">
                        <?= $category['name'] ?>
                    <p>
                        <?php echo count(GameByCategoryWise($category['name'])) ?> Games
                    </p>
                </div>
            </div>
            </a>
        <?php } ?>
    </div>
</div>

<div class="mx-2" style="visibility: hidden;">
<div class="html-content bg-white mt-10 p-6">
<div class="flex gap-2 mt-2 mb-2">
<a href="<?= $site_url ?>" class="text-sm brdcm-style">Game</a>
<div style="margin-top: 2px;"><svg width="16px" height="16px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.5 5L11.7929 11.2929C12.1834 11.6834 12.1834 12.3166 11.7929 12.7071L5.5 19" stroke="#054a91" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13.5 5L19.7929 11.2929C20.1834 11.6834 20.1834 12.3166 19.7929 12.7071L13.5 19" stroke="#054a91" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg></div>
<a href="<?= $site_url . strtolower(str_replace(' ', '-', $data['game_category'])) ?>" class="text-sm brdcm-style"><?= $data['game_category'] ?> Games</a>
</div>
<h2 class="text-md font-bold">
<?= $data['game_name'] ?>
</h2>
<div class="html-content">
<?= $data['game_description'] ?>
</div>
</div>
</div>