<?php $pageTitle = 'Edit Lesson'; ?>
<div class="mb-3"><a href="<?= base_url('admin/modules/' . $lesson['course_id']) ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Modules</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 Lesson</h5></div>
    <?php if (!empty($error)): ?><div class="alert-cix alert-cix-error"><?= $error ?></div><?php endif; ?>
    <form method="POST" action="<?= base_url('admin/lesson-edit/' . $lesson['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($lesson['title']) ?>" required></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Lesson Type</label><select name="lesson_type" class="form-control-cix"><option value="text" <?= $lesson['lesson_type'] === 'text' ? 'selected' : '' ?>>Text</option><option value="video" <?= $lesson['lesson_type'] === 'video' ? 'selected' : '' ?>>Video</option><option value="pdf" <?= $lesson['lesson_type'] === 'pdf' ? 'selected' : '' ?>>PDF</option><option value="download" <?= $lesson['lesson_type'] === 'download' ? 'selected' : '' ?>>Download</option><option value="external_link" <?= $lesson['lesson_type'] === 'external_link' ? 'selected' : '' ?>>External Link</option><option value="mixed" <?= $lesson['lesson_type'] === 'mixed' ? 'selected' : '' ?>>Mixed</option></select></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">Video URL</label><input type="text" name="video_url" class="form-control-cix" value="<?= e($lesson['video_url'] ?? '') ?>" placeholder="https://youtube.com/..."></div></div>
            <div class="col-md-6"><div class="form-group-cix"><label class="form-label-cix">External URL</label><input type="text" name="external_url" class="form-control-cix" value="<?= e($lesson['external_url'] ?? '') ?>"></div></div>
            <div class="col-md-4"><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)($lesson['duration_minutes'] ?? 0) ?>"></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Sort Order</label><input type="number" name="sort_order" class="form-control-cix" value="<?= (int)$lesson['sort_order'] ?>"></div></div>
            <div class="col-md-4"><div class="form-check mt-4"><input class="form-check-input" type="checkbox" name="is_published" value="1" <?= $lesson['is_published'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Published</label></div></div>
            <div class="col-12"><div class="form-group-cix"><label class="form-label-cix">Content</label><textarea name="content" class="form-control-cix" rows="12"><?= e($lesson['content'] ?? '') ?></textarea></div></div>
        </div>
        <button type="submit" class="btn-cix btn-cix-accent mt-3"><i class="fas fa-save"></i> Update Lesson</button>
    </form>
</div>
