<?php $pageTitle = 'Modules - ' . e($course['title']); ?>
<div class="mb-3"><a href="<?= base_url('teacher/courses') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Courses</a></div>
<div class="card-cix mb-4">
    <h4><?= e($course['title']) ?></h4>
    <p class="text-secondary mb-0">Manage modules and lessons for this course</p>
</div>
<?php if (empty($modules)): ?>
    <div class="empty-state"><i class="fas fa-layer-group"></i><h5>No Modules</h5><p>Add your first module to get started.</p></div>
<?php else: ?>
    <?php foreach ($modules as $i => $mod): ?>
    <div class="card-cix mb-3">
        <div class="card-cix-header">
            <div class="card-cix-icon"><i class="fas fa-layer-group"></i></div>
            <div style="flex:1"><h5 class="mb-0">Module <?= ($i + 1) ?>: <?= e($mod['title']) ?></h5><small class="text-secondary"><?= e($mod['description'] ?? '') ?></small></div>
        </div>
        <?php
        $stmt = $pdo->prepare("SELECT * FROM lessons WHERE module_id = ? ORDER BY sort_order");
        $stmt->execute([$mod['id']]);
        $lessons = $stmt->fetchAll();
        ?>
        <?php foreach ($lessons as $lesson): ?>
        <div style="padding:0.5rem 1rem;border-top:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;">
            <span><i class="fas fa-file-alt text-secondary me-2"></i><?= e($lesson['title']) ?> <small class="text-secondary">(<?= ucfirst($lesson['lesson_type']) ?>)</small></span>
            <span class="badge-cix <?= $lesson['is_published'] ? 'badge-active' : 'badge-pending' ?>"><?= $lesson['is_published'] ? 'Published' : 'Draft' ?></span>
        </div>
        <?php endforeach; ?>
        <div style="padding:0.5rem 1rem;border-top:1px solid var(--border);">
            <a href="<?= base_url('teacher/lesson-create/' . $course['id'] . '/' . $mod['id']) ?>" class="btn-cix btn-cix-sm btn-cix-primary"><i class="fas fa-plus"></i> Add Lesson</a>
        </div>
    </div>
    <?php endforeach; ?>
<?php endif; ?>
