<?php $pageTitle = 'Modules'; ?>
<div class="mb-3"><a href="<?= base_url('admin/courses') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Courses</a></div>
<?php if (!empty($course)): ?>
<div class="card-cix mb-4"><h5><?= e($course['title']) ?> - Modules</h5>
    <a href="<?= base_url('admin/module-create/' . $course['id']) ?>" class="btn-cix btn-cix-accent btn-cix-sm"><i class="fas fa-plus"></i> Add Module</a>
</div>
<?php endif; ?>
<?php if (empty($modules)): ?>
    <div class="empty-state"><i class="fas fa-layer-group"></i><h5>No Modules</h5></div>
<?php else: ?>
<div class="card-cix">
    <div class="table-responsive">
        <table class="table-cix"><thead><tr><th>#</th><th>Module</th><th>Course</th><th>Lessons</th><th>Status</th></tr></thead>
        <tbody><?php foreach ($modules as $i => $m): ?>
        <tr><td><?= $i + 1 ?></td><td><strong><?= e($m['title']) ?></strong></td><td class="text-secondary"><?= e($m['course_title'] ?? '') ?></td>
        <td><?php $lc = $pdo->prepare("SELECT COUNT(*) FROM lessons WHERE module_id = ?"); $lc->execute([$m['id']]); echo $lc->fetchColumn(); ?></td>
        <td><span class="badge-cix <?= $m['is_published'] ? 'badge-active' : 'badge-pending' ?>"><?= $m['is_published'] ? 'Published' : 'Draft' ?></span></td></tr>
        <?php endforeach; ?></tbody></table>
    </div>
</div>
<?php endif; ?>
