<?php
    include_once("includes/header.php");
?>

<style>
   html, body {
	background-color: #121212;
	color: #fff;
   }
</style>

<div class="container">
    <div class="postFormContainer">
        <h1>What's going on!?</h1>
        <!-- form for posting something -->
        <form action="forms/post.php" method="post">
            <div class="postBodyContainer">
                <textarea name="postBodyInput" id="postBodyInput" rows="10" placeholder="What's up, Win!"></textarea>
            </div>
            <br><button type="submit" name="postSubmit">Post</button>
        </form>
    </div>
    <br>
    <div class="postsContainer">
        <h2><u>Your Posts</u></h2>
        <?php
            
            $stmt = $con->prepare("SELECT * FROM posts ORDER BY id DESC LIMIT 10");
            $stmt->execute();

            while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $post = new Post($con, $row);
                $postUrl = $post->getPostUrl();
                $postAuthor = $post->getPostAuthor();
                $postedDate = $post->getPublishedDate();
                $postContent = $Parsedown->text($post->getPostContent());

                $item = "<span id='content' style='font-size: 12px;'><b>" . $postAuthor . " · <span style='color: gray'>" . $postedDate . " GMT +7</b></span></span>
                         <p class='card-text'>" . $postContent . "</p>
                         <a href='status.php?url=$postUrl' class='text-decoration-none' style='font-size: 10px;'>View Post</a>
                         <form action='forms/delete.php' method='post'>
                            <button type='submit' name='deletePostSubmit'>Delete</button>
                         </form>
                         <hr>";
                
                echo $item;
            }
        ?>
    </div>
</div>

<?php
    include_once("includes/footer.php");
?>
