<?php $pageTitle = 'Student: ' . e($student['first_name'] . ' ' . $student['last_name']); ?>
<div class="mb-3"><a href="<?= base_url('admin/students') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Students</a></div>
<div class="row g-4">
    <div class="col-lg-4">
        <div class="card-cix mb-4">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-user text-orange me-2"></i> Student Info</h5></div>
            <p><strong>Name:</strong> <?= e($student['first_name'] . ' ' . $student['last_name']) ?></p>
            <p><strong>Student #:</strong> <span style="color:var(--secondary)"><?= e($student['student_number']) ?></span></p>
            <p><strong>Email:</strong> <?= e($student['email']) ?></p>
            <p><strong>Phone:</strong> <?= e($student['phone'] ?? '-') ?></p>
            <p><strong>WhatsApp:</strong> <?= e($student['whatsapp'] ?? '-') ?></p>
            <p><strong>Province:</strong> <?= e($student['province'] ?? '-') ?></p>
            <p><strong>Package:</strong> <?= e($student['package_name'] ?? '-') ?></p>
            <p><strong>Enrollment:</strong> <span class="badge-cix badge-<?= $student['enrollment_status'] ?>"><?= ucfirst($student['enrollment_status']) ?></span></p>
            <p><strong>Payment:</strong> <span class="badge-cix badge-<?= $student['payment_status'] ?>"><?= ucfirst($student['payment_status']) ?></span></p>
            <a href="https://wa.me/27<?= ltrim(e($student['whatsapp'] ?? ''), '0') ?>" class="btn-cix btn-cix-sm btn-cix-accent" target="_blank"><i class="fab fa-whatsapp"></i> WhatsApp</a>
        </div>
        <form method="POST" action="<?= base_url('admin/student-update/' . $student['id']) ?>">
            <?= csrf_field() ?>
            <div class="card-cix">
                <div class="form-group-cix"><label class="form-label-cix">Enrollment Status</label><select name="enrollment_status" class="form-control-cix"><option value="not_enrolled" <?= $student['enrollment_status'] === 'not_enrolled' ? 'selected' : '' ?>>Not Enrolled</option><option value="active" <?= $student['enrollment_status'] === 'active' ? 'selected' : '' ?>>Active</option><option value="suspended" <?= $student['enrollment_status'] === 'suspended' ? 'selected' : '' ?>>Suspended</option><option value="completed" <?= $student['enrollment_status'] === 'completed' ? 'selected' : '' ?>>Completed</option><option value="cancelled" <?= $student['enrollment_status'] === 'cancelled' ? 'selected' : '' ?>>Cancelled</option></select></div>
                <div class="form-check mb-3"><input class="form-check-input" type="checkbox" name="is_active" value="1" <?= $student['is_active'] ? 'checked' : '' ?>><label class="form-check-label text-secondary">Active Account</label></div>
                <button type="submit" class="btn-cix btn-cix-primary btn-cix-sm"><i class="fas fa-save"></i> Update</button>
            </div>
        </form>
    </div>
    <div class="col-lg-8">
        <div class="card-cix mb-4">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-book text-orange me-2"></i> Enrollments</h5></div>
            <?php if (empty($enrollments)): ?><p class="text-secondary p-3">No enrollments</p>
            <?php else: ?><div class="table-responsive"><table class="table-cix"><thead><tr><th>Course</th><th>Status</th><th>Enrolled</th></tr></thead><tbody><?php foreach ($enrollments as $en): ?><tr><td><?= e($en['course_title']) ?></td><td><span class="badge-cix badge-<?= $en['status'] ?>"><?= ucfirst($en['status']) ?></span></td><td class="text-secondary small"><?= e($en['enrolled_at']) ?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?>
        </div>
        <div class="card-cix mb-4">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-credit-card text-orange me-2"></i> Payments</h5></div>
            <?php if (empty($payments)): ?><p class="text-secondary p-3">No payments</p>
            <?php else: ?><div class="table-responsive"><table class="table-cix"><thead><tr><th>Amount</th><th>Status</th><th>Date</th></tr></thead><tbody><?php foreach ($payments as $p): ?><tr><td style="color:var(--secondary);font-weight:700;">R<?= number_format($p['amount'], 2) ?></td><td><span class="badge-cix badge-<?= $p['status'] ?>"><?= ucfirst($p['status']) ?></span></td><td class="text-secondary small"><?= e($p['created_at']) ?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?>
        </div>
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-laptop-code text-orange me-2"></i> Test Attempts</h5></div>
            <?php if (empty($testAttempts)): ?><p class="text-secondary p-3">No test attempts</p>
            <?php else: ?><div class="table-responsive"><table class="table-cix"><thead><tr><th>Test</th><th>Score</th><th>Status</th><th>Date</th></tr></thead><tbody><?php foreach ($testAttempts as $ta): ?><tr><td><?= e($ta['test_title']) ?></td><td style="color:var(--secondary);font-weight:700;"><?= e($ta['score']) ?>%</td><td><span class="badge-cix <?= $ta['passed'] ? 'badge-active' : 'badge-rejected' ?>"><?= $ta['passed'] ? 'Passed' : 'Failed' ?></span></td><td class="text-secondary small"><?= e($ta['created_at']) ?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?>
        </div>
    </div>
</div>
