<?php $pageTitle = e($course['title']); ?>
<div class="mb-3">
    <a href="<?= base_url('student/courses') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to My Courses</a>
</div>
<div class="card-cix mb-4">
    <h3><?= e($course['title']) ?></h3>
    <p class="text-secondary"><?= e($course['subtitle'] ?? '') ?></p>
</div>
<?php if (empty($modules)): ?>
    <div class="empty-state"><i class="fas fa-layer-group"></i><h5>No Modules Yet</h5><p>Course content is being prepared.</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><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 = ? AND is_published = 1 ORDER BY sort_order");
        $stmt->execute([$mod['id']]);
        $lessons = $stmt->fetchAll();
        ?>
        <?php if (!empty($lessons)): ?>
            <?php foreach ($lessons as $lesson): ?>
            <div style="padding:0.6rem 1rem;border-top:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;">
                <div class="d-flex align-items-center gap-2">
                    <?php
                    $icon = 'fa-file-alt';
                    if ($lesson['lesson_type'] === 'video') $icon = 'fa-video';
                    elseif ($lesson['lesson_type'] === 'pdf') $icon = 'fa-file-pdf';
                    elseif ($lesson['lesson_type'] === 'download') $icon = 'fa-download';
                    ?>
                    <i class="fas <?= $icon ?> text-secondary"></i>
                    <span><?= e($lesson['title']) ?></span>
                    <small class="text-secondary">(<?= ucfirst($lesson['lesson_type']) ?>)</small>
                </div>
                <a href="<?= base_url('student/lesson/' . e($mod['slug']) . '/' . e($lesson['slug'])) ?>" class="btn-cix btn-cix-sm btn-cix-outline">View</a>
            </div>
            <?php endforeach; ?>
        <?php else: ?>
            <p class="text-secondary p-3 mb-0">No lessons published yet.</p>
        <?php endif; ?>
    </div>
    <?php endforeach; ?>
<?php endif; ?>
