
<?php
// Get student information
 $studentId = $_SESSION['user_id'];
 $stmt = $pdo->prepare("SELECT * FROM students WHERE id = ?");
 $stmt->execute([$studentId]);
 $student = $stmt->fetch(PDO::FETCH_ASSOC);

// Get education history
 $stmt = $pdo->prepare("SELECT * FROM education_history WHERE student_id = ?");
 $stmt->execute([$studentId]);
 $educationHistory = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Get examination results
 $stmt = $pdo->prepare("SELECT * FROM examination_results WHERE student_id = ?");
 $stmt->execute([$studentId]);
 $examResults = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Get referee information
 $stmt = $pdo->prepare("SELECT * FROM referees WHERE student_id = ?");
 $stmt->execute([$studentId]);
 $referee = $stmt->fetch(PDO::FETCH_ASSOC);
?>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h4 class="mb-0">Student Dashboard</h4>
                <span class="badge bg-<?php echo $student['application_status'] === 'Approved' ? 'success' : ($student['application_status'] === 'Rejected' ? 'danger' : 'warning'); ?>">
                    <?php echo $student['application_status']; ?>
                </span>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <div class="stats-card">
                            <h3><?php echo $student['registration_no']; ?></h3>
                            <p>Registration Number</p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="stats-card">
                            <h3><?php echo $student['payment_status']; ?></h3>
                            <p>Payment Status</p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="stats-card">
                            <h3><?php echo $student['application_status']; ?></h3>
                            <p>Application Status</p>
                        </div>
                    </div>
                </div>
                
                <div class="row mt-4">
                    <div class="col-md-6">
                        <div class="card dashboard-card">
                            <div class="card-header">
                                Personal Information
                            </div>
                            <div class="card-body">
                                <table class="table table-borderless">
                                    <tr>
                                        <td><strong>Name:</strong></td>
                                        <td><?php echo $student['first_name'] . ' ' . $student['surname']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Email:</strong></td>
                                        <td><?php echo $student['email']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Phone:</strong></td>
                                        <td><?php echo $student['mobile_phone']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>State of Origin:</strong></td>
                                        <td><?php echo $student['state_of_origin']; ?></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="card dashboard-card">
                            <div class="card-header">
                                Application Details
                            </div>
                            <div class="card-body">
                                <table class="table table-borderless">
                                    <tr>
                                        <td><strong>Subject 1:</strong></td>
                                        <td><?php echo $student['subject1']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Subject 2:</strong></td>
                                        <td><?php echo $student['subject2']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Subject 3:</strong></td>
                                        <td><?php echo $student['subject3']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Application Date:</strong></td>
                                        <td><?php echo date('d M Y', strtotime($student['created_at'])); ?></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="row mt-4">
                    <div class="col-md-12">
                        <div class="card dashboard-card">
                            <div class="card-header">
                                Application Actions
                            </div>
                            <div class="card-body">
                                <div class="d-flex flex-wrap gap-2">
                                    <a href="?page=application_form" class="btn btn-primary">
                                        <i class="bi bi-pencil"></i> Edit Application
                                    </a>
                                    <?php if ($student['payment_status'] === 'Pending'): ?>
                                        <a href="?page=payment" class="btn btn-success">
                                            <i class="bi bi-credit-card"></i> Make Payment
                                        </a>
                                    <?php endif; ?>
                                    <button class="btn btn-secondary" onclick="window.print()">
                                        <i class="bi bi-printer"></i> Print Application
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
