<?php
session_start();
if (!isset($_SESSION['id_pelajar'])) {
    header('Location: login_pelajar.php');
    exit;
}
include 'includes/header.php';
include 'includes/sidebar_pelajar.php';
include 'includes/config.php';

$id_pelajar = $_SESSION['id_pelajar'];

// Dapatkan maklumat pelajar
$sql = "SELECT * FROM pelajar WHERE id = $id_pelajar LIMIT 1";
$result = mysqli_query($conn, $sql);
$pelajar = mysqli_fetch_assoc($result);

// URL gambar
$gambar_url = !empty($pelajar['gambar']) ? 'uploads/' . $pelajar['gambar'] : 'images/default-avatar.png';
?>

<div style="margin-left: 180px; margin-top: 100px; padding: 20px; min-height: calc(100vh - 100px);">

    <div class="card shadow p-4 mb-4">
        <div class="row g-4 align-items-center">
            <!-- Gambar Pelajar -->
            <div class="col-md-3 text-center">
                <img src="<?= htmlspecialchars($gambar_url); ?>" 
                     alt="Gambar Pelajar" 
                     class="rounded-circle img-thumbnail" 
                     style="width: 150px; height: 150px; object-fit: cover; cursor: pointer;"
                     onclick="document.getElementById('uploadGambar').click();">
                <form id="formGambar" action="upload_gambar.php" method="POST" enctype="multipart/form-data" style="display:none;">
                    <input type="file" name="gambar" id="uploadGambar" accept="image/*" onchange="document.getElementById('formGambar').submit();">
                </form>
            </div>

            <!-- Maklumat Pelajar -->
            <div class="col-md-9">
                <h3 class="fw-bold text-primary">Selamat Datang, <?= htmlspecialchars($pelajar['nama']); ?> 👋</h3>
                <div class="row mt-3">
                    <div class="col-md-6">
                        <p><strong>No. Kad Pengenalan:</strong> <?= htmlspecialchars($pelajar['no_ic']); ?></p>
                        <p><strong>Program:</strong> <?= htmlspecialchars($pelajar['program']); ?></p>
                        <p><strong>Jantina:</strong> <?= htmlspecialchars($pelajar['jantina']); ?></p>
                        <p><strong>Status:</strong> <?= htmlspecialchars($pelajar['status']); ?></p>
                    </div>
                    <div class="col-md-6">
                        <p><strong>Bangsa:</strong> <?= htmlspecialchars($pelajar['bangsa']); ?></p>
                        <p><strong>Agama:</strong> <?= htmlspecialchars($pelajar['agama']); ?></p>
                        <p><strong>Warganegara:</strong> <?= htmlspecialchars($pelajar['warganegara']); ?></p>
                        <p><strong>No. Telefon:</strong> <?= htmlspecialchars($pelajar['no_telefon']); ?></p>
                        <p><strong>E-mel:</strong> <?= htmlspecialchars($pelajar['emel']); ?></p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Seksyen Aktiviti -->
    <div class="card shadow p-4">
        <h4 class="mb-3 text-secondary">Aktiviti Akan Datang</h4>
        <ul class="list-group">
            <li class="list-group-item">Mesyuarat Kelab XYZ - 15 Ogos 2025</li>
            <li class="list-group-item">Program Gotong Royong - 20 Ogos 2025</li>
            <li class="list-group-item">Kursus Kepimpinan - 25 Ogos 2025</li>
        </ul>
    </div>
</div>

<?php include 'includes/footer.php'; ?>
