<?php $pageTitle = 'Edit Course: ' . e($course['title']); ?>
<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>
<div class="card-cix">
    <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-edit text-orange me-2"></i> Edit Course</h5></div>
    <?php if (!empty($error)): ?><div class="alert-cix alert-cix-error"><?= $error ?></div><?php endif; ?>
    <form method="POST" action="<?= base_url('admin/course-edit/' . $course['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($course['title']) ?>" required></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Duration (hours)</label><input type="number" name="duration_hours" class="form-control-cix" value="<?= (int)$course['duration_hours'] ?>"></div></div>
            <div class="col-12"><div class="form-group-cix"><label class="form-label-cix">Subtitle</label><input type="text" name="subtitle" class="form-control-cix" value="<?= e($course['subtitle'] ?? '') ?>"></div></div>
            <div class="col-12"><div class="form-group-cix"><label class="form-label-cix">Description</label><textarea name="description" class="form-control-cix" rows="4"><?= e($course['description'] ?? '') ?></textarea></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Category</label><select name="category_id" class="form-control-cix"><option value="">None</option><?php foreach ($categories as $cat): ?><option value="<?= $cat['id'] ?>" <?= $course['category_id'] == $cat['id'] ? 'selected' : '' ?>><?= e($cat['name']) ?></option><?php endforeach; ?></select></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Level</label><select name="level_id" class="form-control-cix"><option value="">None</option><?php foreach ($levels as $l): ?><option value="<?= $l['id'] ?>" <?= $course['level_id'] == $l['id'] ? 'selected' : '' ?>><?= e($l['name']) ?></option><?php endforeach; ?></select></div></div>
            <div class="col-md-4"><div class="form-group-cix"><label class="form-label-cix">Pass Mark</label><input type="number" name="pass_mark" class="form-control-cix" value="<?= (int)$course['pass_mark'] ?>"></div></div>
            <div class="col-md-4"><div class="form-check"><input class="form-check-input" type="checkbox" name="certificate_eligible" value="1" <?= $course['certificate_eligible'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Certificate Eligible</label></div></div>
            <div class="col-md-4"><div class="form-check"><input class="form-check-input" type="checkbox" name="is_featured" value="1" <?= $course['is_featured'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Featured</label></div></div>
            <div class="col-md-4"><div class="form-check"><input class="form-check-input" type="checkbox" name="is_published" value="1" <?= $course['is_published'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Published</label></div></div>
        </div>
        <button type="submit" class="btn-cix btn-cix-accent mt-3"><i class="fas fa-save"></i> Update Course</button>
    </form>
</div>
