<?php $pageTitle = 'Test Sections'; ?>
<div class="mb-3"><a href="<?= base_url('admin/test-view/' . $test['id']) ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Test</a></div>
<div class="row g-4">
    <div class="col-lg-5">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-plus-circle text-orange me-2"></i> Add Section</h5></div>
            <form method="POST" action="<?= base_url('admin/test-sections/' . $test['id']) ?>">
                <?= csrf_field() ?>
                <div class="form-group-cix"><label class="form-label-cix">Section Title *</label><input type="text" name="section_title" class="form-control-cix" required></div>
                <div class="form-group-cix"><label class="form-label-cix">Question Bank *</label><select name="bank_id" class="form-control-cix" required><option value="">Select bank...</option><?php foreach ($banks as $b): ?><option value="<?= $b['id'] ?>"><?= e($b['name']) ?></option><?php endforeach; ?></select></div>
                <div class="row g-2">
                    <div class="col-6"><div class="form-group-cix"><label class="form-label-cix">Questions</label><input type="number" name="question_count" class="form-control-cix" value="10"></div></div>
                    <div class="col-6"><div class="form-group-cix"><label class="form-label-cix">Difficulty</label><select name="difficulty_filter" class="form-control-cix"><option value="all">All</option><option value="easy">Easy</option><option value="medium">Medium</option><option value="hard">Hard</option></select></div></div>
                </div>
                <div class="form-group-cix"><label class="form-label-cix">Sort Order</label><input type="number" name="sort_order" class="form-control-cix" value="0"></div>
                <button type="submit" class="btn-cix btn-cix-accent"><i class="fas fa-plus"></i> Add Section</button>
            </form>
        </div>
    </div>
    <div class="col-lg-7">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-layer-group text-orange me-2"></i> Current Sections</h5></div>
            <?php if (empty($sections)): ?>
                <div class="empty-state"><i class="fas fa-layer-group"></i><h5>No Sections</h5><p>Add sections to define which question banks and how many questions to pull from.</p></div>
            <?php else: ?>
                <?php foreach ($sections as $i => $s): ?>
                <div style="padding:1rem;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;">
                    <div>
                        <strong><?= ($i + 1) . '. ' . e($s['title']) ?></strong>
                        <br><small class="text-secondary">Bank: <?= e($s['bank_name'] ?? 'None') ?> | Questions: <?= (int)$s['question_count'] ?> | Difficulty: <?= ucfirst(e($s['difficulty_filter'])) ?></small>
                    </div>
                    <span class="badge-cix badge-submitted">Sort: <?= (int)$s['sort_order'] ?></span>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
</div>
