<?php global $zon, $site_url, $socket;

if (isset($_GET) && isset($_GET['token'])) {
    $token = mysqli_real_escape_string($socket, $_GET['token']);
    if (mysqli_query($socket, "DELETE FROM zon_comments WHERE id=$token")) {
        echo "<script>window.location.href = '?'</script>";
    }
}

?>
<div class="zon-game-container">

    <?php if ($zon['page'][1] == 'comments') { ?>
        <h1 class="text-3xl mb-8 mt-3 block page-heading">Your Comments</h1>
        <div class="mt-2">
            <?php
            if (getUserComments($zon['user']['id'])) {
                foreach (getUserComments($zon['user']['id']) as $comment) {
                    ?>
                    <div class="comment-card mb-6 w-full">
                        <div class="flex w-full items-center gap-4">
                            <img class="w-20 h-8 rounded-full"
                                src="<?php echo $site_url . 'static/img/' . $comment['user_pic'] ?>" />
                            <div class="uc-meta">
                                <div class="flex gap-4">
                                    <span class="font-semibold ">
                                        <?= $comment['username'] ?>
                                    </span>
                                    <a class="text-red-600 text-sm" href="?token=<?= $comment['id'] ?>">Delete</a>
                                </div>
                                <p class="text-xs " style="color: var(--zon-muted-color);">
                                    <?= $comment['date'] ?>
                                </p>
                                <p>
                                    <?= $comment['subject'] ?>
                                </p>
                            </div>
                        </div>
                    </div>
                <?php }
            } else {
                echo "You haven't commented in any games yet.";
            } ?>
        </div>
    <?php }
    ?>
    <?php if ($zon['page'][1] == 'likes') { ?>
        <h1 class="text-3xl mb-8 mt-3 block page-heading">Your Liked Games</h1>
        <div class="game__grid home__game__grid">
            <?php
            if (getUserGame($zon['user']['id'])) {
                foreach (getUserGame($zon['user']['id']) as $game) { ?>
                    <div class="game new__badges wow <?php echo $zon['config']['animate_class'] ?>">
                        <a href="<?= $site_url . 'game/' . makeSlug($game['game_name']) . '/' . $game['id'] ?>" class="game__thumb">
                            <img src="<?= $game['game_image_url'] ?>" alt="<?= $game['game_name'] ?>" />
                        </a>
                        <a href="<?= $site_url . 'game/' . makeSlug($game['game_name']) . '/' . $game['id'] ?>" class="game_name">
                            <?= $game['game_name'] ?>
                        </a>
                    </div>
                <?php }
            } else {
                echo "You haven't liked any games yet";
            } ?>
        </div>
    <?php } ?>

    <?php if ($zon['page'][1] == 'settings') { ?>
        <h1 class="text-3xl mb-8 mt-3 block page-heading">Your Settings</h1>
        <div class="form-start">
            <form id="update-info" method="post" class="update-info-form w-[400px] ">
                <div class="input-group mb-4">
                    <label for="" class="mb-2 transition duration-300  block font-medium">Profile Pic</label>
                    <img class="w-20 mb-2" src="<?php echo $site_url ?>static/img/<?php echo $zon['user']['user_pic'] ?>" />
                    <input name="avatar_img" type="file"
                        class="hover:border-[var(--zon-theme-color)] focus:outline-[var(--zon-theme-color)] px-4 w-full py-4 bg-transparent border border-[var(--zon-comment-input-b-color)] " />
                </div>
                <div class="input-group mb-4">
                    <label for="" class="mb-2 transition duration-300  block font-medium">Full Name</label>
                    <input required name="name" value="<?php echo $zon['user']['name'] ?>" type="text"
                        class="hover:border-[var(--zon-theme-color)] focus:outline-[var(--zon-theme-color)] px-4 w-full py-4 bg-transparent border border-[var(--zon-comment-input-b-color)] " />
                </div>
                <div class="input-group mb-4">
                    <label for="" class="mb-2 transition duration-300  block font-medium">Email</label>
                    <input required name="email" value="<?php echo $zon['user']['email'] ?>" type="email"
                        class="px-4 w-full py-4 hover:border-[var(--zon-theme-color)] focus:outline-[var(--zon-theme-color)]  bg-transparent border border-[var(--zon-comment-input-b-color)] " />
                </div>
                <div class="input-group mb-4">
                    <label for="" class="mb-2 transition duration-300  block font-medium">Username</label>
                    <input required name="username" value="<?php echo $zon['user']['username'] ?>" type="username"
                        class="px-4 w-full py-4 hover:border-[var(--zon-theme-color)] focus:outline-[var(--zon-theme-color)]  bg-transparent border border-[var(--zon-comment-input-b-color)] " />
                </div>
                <div class="input-group mb-4">
                    <label for="" class="mb-2 transition duration-300  block font-medium">New password</label>
                    <input name="new_password" placeholder="#######" type="password"
                        class="px-4 w-full py-4 hover:border-[var(--zon-theme-color)] focus:outline-[var(--zon-theme-color)]  bg-transparent border border-[var(--zon-comment-input-b-color)] " />
                </div>
                <input type="hidden" name="change_settings" value="<?php echo $zon['user']['id'] ?>" />
                <button type="submit"
                    class="w-full disabled:opacity-70 capitalize rounded-lg mt-3 py-3 text-white bg-[var(--zon-theme-color)] px-4">Update
                    profile</button>
            </form>
        </div>
    <?php } ?>
</div>