<?php include app()->basePath('app/Views/partials/header.php'); ?>

<section class="panel">
    <p class="eyebrow">Avaliacao</p>
    <h1>Teste final: <?= e($course['title']) ?></h1>
    <p>Crie perguntas objectivas para validar se o aluno atingiu os resultados do curso.</p>

    <div class="actions">
        <a class="ghost-button" href="/manage/courses/edit?id=<?= e((string) $course['id']) ?>">Regras do certificado</a>
        <a class="ghost-button" href="/manage/courses/content?id=<?= e((string) $course['id']) ?>">Conteudo</a>
    </div>

    <div class="detail-grid">
        <section class="sub-panel">
            <h2>Perguntas</h2>
            <?php if (!$questions): ?>
                <p>Ainda nao ha perguntas. Adicione pelo menos uma para activar o teste.</p>
            <?php endif; ?>
            <div class="question-list">
                <?php foreach ($questions as $question): ?>
                    <article class="question-card">
                        <div class="question-head">
                            <strong><?= e((string) $question['position']) ?>. <?= e($question['question']) ?></strong>
                            <span class="badge"><?= e((string) $question['points']) ?> ponto(s)</span>
                        </div>
                        <span class="muted">Resposta correcta: <?= e($question['correct_answer']) ?></span>
                        <ul class="plain-list">
                            <?php foreach ($question['options'] as $option): ?>
                                <li><?= e($option) ?></li>
                            <?php endforeach; ?>
                        </ul>
                        <form method="post" action="/manage/courses/assessment/questions/delete">
                            <?= csrf_field() ?>
                            <input type="hidden" name="course_id" value="<?= e((string) $course['id']) ?>">
                            <input type="hidden" name="question_id" value="<?= e((string) $question['id']) ?>">
                            <button class="mini-button danger" type="submit">Apagar pergunta</button>
                        </form>
                    </article>
                <?php endforeach; ?>
            </div>
        </section>

        <aside class="sub-panel">
            <h2>Nova pergunta</h2>
            <form class="form" method="post" action="/manage/courses/assessment/questions/store">
                <?= csrf_field() ?>
                <input type="hidden" name="course_id" value="<?= e((string) $course['id']) ?>">
                <label>
                    Pergunta
                    <textarea name="question" rows="3" required></textarea>
                </label>
                <label>
                    Tipo
                    <select name="type">
                        <option value="multiple_choice">Escolha multipla</option>
                        <option value="true_false">Verdadeiro/Falso</option>
                    </select>
                </label>
                <label>
                    Opcoes
                    <textarea name="options" rows="5" placeholder="Uma opcao por linha. Para verdadeiro/falso pode deixar vazio."></textarea>
                </label>
                <label>
                    Resposta correcta
                    <input name="correct_answer" placeholder="Deve ser igual a uma das opcoes" required>
                </label>
                <label>
                    Pontos
                    <input name="points" type="number" min="1" value="1">
                </label>
                <button class="button" type="submit">Adicionar pergunta</button>
            </form>
        </aside>
    </div>
</section>

<?php include app()->basePath('app/Views/partials/footer.php'); ?>
