<?php /** @var array $test */ /** @var array $questions */ /** @var int $attemptId */ $pageTitle = 'Take Test: ' . e($test['title']); ?>
<div class="mb-3"><a href="<?= base_url('student/tests') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Tests</a></div>
<div class="test-header">
    <div><h5 class="mb-0"><?= e($test['title']) ?></h5><small class="text-secondary"><?= e($test['description'] ?? '') ?></small></div>
    <div class="text-center"><div id="testTimer" class="test-timer"><?= str_pad(floor($test['duration_minutes']), 2, '0', STR_PAD_LEFT) ?>:00</div><small class="text-secondary">Time Remaining</small></div>
</div>
<div id="tabWarning" class="alert-cix alert-cix-error mb-3" style="display:none"><i class="fas fa-exclamation-triangle"></i> Warning: You switched tabs. This activity is being logged.</div>
<form method="POST" action="<?= base_url('student/submit-test/' . $test['id']) ?>" id="testForm">
    <?= csrf_field() ?>
<div id="questionsContainer">
    <?php if (!empty($questions)): ?>
        <?php foreach ($questions as $i => $q): ?>
        <div class="question-card">
            <div class="question-number">Question <?= ($i + 1) ?> of <?= count($questions) ?></div>
            <p class="mb-3" style="font-size:1.05rem;"><?= e($q['question_text']) ?></p>
            <?php if ($q['question_type'] === 'multiple_choice' || $q['question_type'] === 'true_false'): ?>
                <?php foreach ($q['options'] as $opt): ?>
                <label class="option-label"><input type="radio" name="answers[<?= $q['id'] ?>]" value="<?= $opt['id'] ?>"><span><?= e($opt['option_text']) ?></span></label>
                <?php endforeach; ?>
            <?php elseif ($q['question_type'] === 'short_answer'): ?>
                <input type="text" name="answers[<?= $q['id'] ?>]" class="form-control-cix" placeholder="Type your answer...">
            <?php endif; ?>
        </div>
        <?php endforeach; ?>
    <?php endif; ?>
</div>
<div class="text-center mt-4 mb-5">
        <button type="submit" class="btn-cix btn-cix-accent btn-cix-lg" onclick="return confirm('Are you sure you want to submit? You cannot change your answers after submission.')"><i class="fas fa-paper-plane"></i> Submit Test</button>
</div>
<div id="testResult" class="card-cix" style="display:none"></div>
</form>
<script>
CBT.startTest(<?= (int)$attemptId ?>, <?= (int)$test['duration_minutes'] ?>);
</script>
