<?php $pageTitle = 'Application: ' . e($application['first_name'] . ' ' . $application['last_name']); ?>
<div class="mb-3"><a href="<?= base_url('admin/applications') ?>" class="text-secondary"><i class="fas fa-arrow-left me-1"></i> Back to Applications</a></div>
<div class="row g-4">
    <div class="col-lg-8">
        <div class="card-cix mb-4">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-file-alt text-orange me-2"></i> Application Details</h5>
                <span class="badge-cix badge-<?= $application['status'] ?>"><?= ucfirst($application['status']) ?></span>
            </div>
            <div class="row g-3">
                <div class="col-md-6"><p class="text-secondary mb-1">Name</p><h5><?= e($application['first_name'] . ' ' . $application['last_name']) ?></h5></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Email</p><p><?= e($application['email']) ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Phone</p><p><?= e($application['phone'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">WhatsApp</p><p><?= e($application['whatsapp'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">ID/Passport</p><p><?= e($application['id_passport'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Province</p><p><?= e($application['province'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Town</p><p><?= e($application['town'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Education Level</p><p><?= e($application['highest_education'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Interested Package</p><p><?= e($application['package_name'] ?? '-') ?></p></div>
                <div class="col-md-6"><p class="text-secondary mb-1">Applied On</p><p><?= e($application['created_at']) ?></p></div>
            </div>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-gavel text-orange me-2"></i> Review Action</h5></div>
            <?php if (!empty($error)): ?><div class="alert-cix alert-cix-error"><?= $error ?></div><?php endif; ?>
            <?php if ($application['status'] === 'pending' || $application['status'] === 'under_review'): ?>
            <form method="POST" action="<?= base_url('admin/applications/' . $application['id']) ?>">
                <?= csrf_field() ?>
                <div class="form-group-cix"><label class="form-label-cix">Review Notes</label><textarea name="review_notes" class="form-control-cix" rows="3" placeholder="Add review notes..."></textarea></div>
                <button type="submit" name="action" value="accept" class="btn-cix btn-cix-accent w-100 mb-2" onclick="return confirm('Accept this application and create a student account?')"><i class="fas fa-check"></i> Accept Application</button>
                <button type="submit" name="action" value="reject" class="btn-cix btn-cix-danger w-100" onclick="return confirm('Reject this application?')"><i class="fas fa-times"></i> Reject</button>
            </form>
            <?php else: ?>
            <p class="text-secondary p-3">Application already <?= e($application['status']) ?>.</p>
            <?php endif; ?>
            <div class="mt-3">
                <a href="https://wa.me/27<?= ltrim(e($application['whatsapp'] ?? $application['phone'] ?? ''), '0') ?>" class="btn-cix btn-cix-sm btn-cix-accent w-100" target="_blank"><i class="fab fa-whatsapp"></i> WhatsApp Applicant</a>
            </div>
        </div>
    </div>
</div>
