<?php $pageTitle = 'Create Test'; ?>
<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="card-cix">
    <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-laptop-code text-orange me-2"></i> New Test</h5></div>
    <?php if (!empty($error)): ?><div class="alert-cix alert-cix-error"><?= $error ?></div><?php endif; ?>
    <form method="POST" action="<?= base_url('admin/test-create') ?>">
        <?= csrf_field() ?>
        <div class="row g-3">
            <div class="col-md-8"><div class="form-group-cix"><label class="form-label-cix">Title *</label><input type="text" name="title" class="form-control-cix" required></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Type</label><select name="test_type" class="form-control-cix"><option value="quiz">Quiz</option><option value="cbt">CBT</option><option value="final_exam">Final Exam</option></select></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Course *</label><select name="course_id" class="form-control-cix" required><option value="">Select...</option><?php foreach ($courses as $c): ?><option value="<?= $c['id'] ?>"><?= e($c['title']) ?></option><?php endforeach; ?></select></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Duration (min)</label><input type="number" name="duration_minutes" class="form-control-cix" value="60"></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Pass Mark (%)</label><input type="number" name="pass_mark" class="form-control-cix" value="50"></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Max Attempts</label><input type="number" name="max_attempts" class="form-control-cix" value="3"></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Questions Per Test</label><input type="number" name="questions_per_test" class="form-control-cix" value="20"></div></div>
            <div class="col-md-4"><div class="form-check"><input class="form-check-input" type="checkbox" name="randomize_questions" value="1" checked><label class="form-check-label text-secondary">Randomize Questions</label></div></div>
            <div class="col-md-4"><div class="form-check"><input class="form-check-input" type="checkbox" name="randomize_answers" value="1" checked><label class="form-check-label text-secondary">Randomize Answers</label></div></div>
            <div class="col-md-4"><div class="form-check"><input class="form-check-input" type="checkbox" name="is_published"><label class="form-check-label text-secondary">Publish</label></div></div>
            <div class="col-12"><div class="form-group-cix"><label class="form-label-cix">Description</label><textarea name="description" class="form-control-cix" rows="3"></textarea></div></div>
        </div>
        <button type="submit" class="btn-cix btn-cix-accent mt-3"><i class="fas fa-save"></i> Create Test</button>
    </form>
</div>
