<?php 
    require_once 'includes/header.php';
    require_once 'db.connect.php';
    require_once 'helpers/func/helper.php';
    require_once 'helpers/classes/Question.php';
    require_once 'helpers/classes/User.php';
    require_once 'helpers/classes/Answer.php';
    

    if(!isset($_GET['id'])){
        print '<div class="container">
            <div class="row">
                <div class="col s12 l9">
                    <h3>403</h3>
                    <h4>Bad Request</h4>
                    <a href="/eduask"> Go Home </a>
                </div>
            </div>
        </div>';
    }else{
        $questionid = $_GET['id'];

        $question = new Question($conn);
        $user = new User($conn);

        $oneQuestion = json_decode($question->getByid($questionid));
        for ($i = 0; $i < count($oneQuestion); $i++){
            $id = $oneQuestion[$i]->id;
            $topic = $oneQuestion[$i]->topic;
            $question = $oneQuestion[$i]->question;
            $date = $oneQuestion[$i]->date;
            $user_id = $oneQuestion[$i]->user_id;
?>
         <div class="container">
        <div class="row">
            <div class="col s12 l9">
                <h4 class="question__title"><?php print $topic ?></h4>
                <div class="divider"></div>
                <div>
                    <p><?php print $question ?></p>
                    <br />
                    <span class="by">at: <?php print $date ?></span>
                    <?php
                        $oneUser = json_decode($user->getById($user_id));
                        for ($u = 0; $u < count($user); $u++){
                            print "<br><span class='by font10'> By <span class='display__username'>".$oneUser[$u]->username . "</span></span>";
                        }
                    ?>
                </div>
                <div class="divider"></div>

              <?php  require_once "includes/components/answer-list.php" ?>
            </div>

            <?php require_once 'includes/components/recent-questions.php'?>
        </div>
    </div>

<?php

        }
    }
    
?>    

   

<?php
    require_once 'includes/footer.php';
?>