<?php $pageTitle = 'Test: ' . e($test['title']); ?>
<div class="mb-3"><a href="<?= base_url('admin/tests') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Tests</a></div>
<div class="row g-4">
    <div class="col-lg-4">
        <div class="card-cix mb-4">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-laptop-code text-orange me-2"></i> Test Details</h5></div>
            <p><strong>Title:</strong> <?= e($test['title']) ?></p>
            <p><strong>Type:</strong> <span class="badge-cix badge-submitted"><?= strtoupper($test['test_type']) ?></span></p>
            <p><strong>Course:</strong> <?= e($test['course_title'] ?? '-') ?></p>
            <p><strong>Duration:</strong> <?= (int)$test['duration_minutes'] ?> minutes</p>
            <p><strong>Pass Mark:</strong> <?= (int)$test['pass_mark'] ?>%</p>
            <p><strong>Max Attempts:</strong> <?= (int)$test['max_attempts'] ?></p>
            <p><strong>Randomize Q:</strong> <?= $test['randomize_questions'] ? 'Yes' : 'No' ?></p>
            <p><strong>Randomize A:</strong> <?= $test['randomize_answers'] ? 'Yes' : 'No' ?></p>
            <p><strong>Status:</strong> <span class="badge-cix <?= $test['is_published'] ? 'badge-active' : 'badge-pending' ?>"><?= $test['is_published'] ? 'Published' : 'Draft' ?></span></p>
            <div class="mt-2">
                <a href="<?= base_url('admin/test-edit/' . $test['id']) ?>" class="btn-cix btn-cix-primary btn-cix-sm"><i class="fas fa-edit"></i> Edit</a>
                <a href="<?= base_url('admin/test-sections/' . $test['id']) ?>" class="btn-cix btn-cix-outline btn-cix-sm"><i class="fas fa-layer-group"></i> Sections</a>
            </div>
        </div>
    </div>
    <div class="col-lg-8">
        <div class="card-cix mb-4">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-layer-group text-orange me-2"></i> Sections</h5></div>
            <?php if (empty($sections)): ?>
                <p class="text-secondary p-3">No sections configured. <a href="<?= base_url('admin/test-sections/' . $test['id']) ?>">Add sections</a></p>
            <?php else: ?>
                <div class="table-responsive"><table class="table-cix"><thead><tr><th>Section</th><th>Bank</th><th>Questions</th><th>Difficulty</th></tr></thead>
                <tbody><?php foreach ($sections as $s): ?>
                <tr><td><?= e($s['title']) ?></td><td class="text-secondary"><?= e($s['bank_name'] ?? '-') ?></td><td><?= (int)$s['question_count'] ?></td><td><?= ucfirst(e($s['difficulty_filter'])) ?></td></tr>
                <?php endforeach; ?></tbody></table></div>
            <?php endif; ?>
        </div>
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-users text-orange me-2"></i> Recent Attempts (<?= count($attempts) ?>)</h5></div>
            <?php if (empty($attempts)): ?>
                <p class="text-secondary p-3">No attempts yet.</p>
            <?php else: ?>
                <div class="table-responsive"><table class="table-cix"><thead><tr><th>Student</th><th>Score</th><th>Status</th><th>Date</th></tr></thead>
                <tbody><?php foreach ($attempts as $a): ?>
                <tr><td><?= e($a['first_name'] . ' ' . $a['last_name']) ?> <small class="text-secondary">(<?= e($a['student_number']) ?>)</small></td>
                <td class="fw-bold" style="color:var(--secondary)"><?= e($a['score']) ?>%</td>
                <td><span class="badge-cix <?= $a['passed'] ? 'badge-active' : 'badge-rejected' ?>"><?= $a['passed'] ? 'Passed' : 'Failed' ?></span></td>
                <td class="text-secondary small"><?= e($a['created_at']) ?></td></tr>
                <?php endforeach; ?></tbody></table></div>
            <?php endif; ?>
        </div>
    </div>
</div>
