<?php $pageTitle = 'Edit 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-edit text-orange me-2"></i> Edit 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-edit/' . $test['id']) ?>">
        <?= 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" value="<?= e($test['title']) ?>" required></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" disabled><?php foreach ($courses as $c): ?><option value="<?= $c['id'] ?>" <?= $test['course_id'] == $c['id'] ? 'selected' : '' ?>><?= e($c['title']) ?></option><?php endforeach; ?></select></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"><?= e($test['description'] ?? '') ?></textarea></div></div>
            <div class="col-md-3"><div class="form-group-cix"><label class="form-label-cix">Duration (min)</label><input type="number" name="duration_minutes" class="form-control-cix" value="<?= (int)$test['duration_minutes'] ?>"></div></div>
            <div class="col-md-3"><div class="form-group-cix"><label class="form-label-cix">Pass Mark (%)</label><input type="number" name="pass_mark" class="form-control-cix" value="<?= (int)$test['pass_mark'] ?>"></div></div>
            <div class="col-md-3"><div class="form-group-cix"><label class="form-label-cix">Max Attempts</label><input type="number" name="max_attempts" class="form-control-cix" value="<?= (int)$test['max_attempts'] ?>"></div></div>
            <div class="col-md-3"><div class="form-group-cix"><label class="form-label-cix">Questions/Test</label><input type="number" name="questions_per_test" class="form-control-cix" value="<?= (int)$test['questions_per_test'] ?>"></div></div>
            <div class="col-md-3"><div class="form-check"><input class="form-check-input" type="checkbox" name="randomize_questions" value="1" <?= $test['randomize_questions'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Randomize Questions</label></div></div>
            <div class="col-md-3"><div class="form-check"><input class="form-check-input" type="checkbox" name="randomize_answers" value="1" <?= $test['randomize_answers'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Randomize Answers</label></div></div>
            <div class="col-md-3"><div class="form-check"><input class="form-check-input" type="checkbox" name="certificate_trigger" value="1" <?= $test['certificate_trigger'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Certificate Trigger</label></div></div>
            <div class="col-md-3"><div class="form-check"><input class="form-check-input" type="checkbox" name="is_published" value="1" <?= $test['is_published'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Published</label></div></div>
        </div>
        <button type="submit" class="btn-cix btn-cix-accent mt-3"><i class="fas fa-save"></i> Update Test</button>
    </form>
</div>
