<?php
include '../config.php';

if (!isSiswa()) {
    redirect('../login.php');
}

$user_id = $_SESSION['user_id'];

// Ambil data siswa
$sql_siswa = "SELECT * FROM lms_users WHERE id = ?";
$stmt_siswa = $conn->prepare($sql_siswa);
$stmt_siswa->bind_param('i', $user_id);
$stmt_siswa->execute();
$result_siswa = $stmt_siswa->get_result();
$siswa = $result_siswa->fetch_assoc();

// Ambil kursus yang di-enroll
$sql_enrolled_lms_courses = "SELECT c.*, e.progress, e.tanggal_enroll, u.nama_lengkap as nama_guru,
                         cat.nama_kategori
                         FROM lms_enrollments e 
                         JOIN lms_courses c ON e.id_course = c.id 
                         JOIN lms_users u ON c.id_guru = u.id 
                         JOIN lms_categories cat ON c.id_kategori = cat.id 
                         WHERE e.id_siswa = ? AND e.status = 'active'
                         ORDER BY e.tanggal_enroll DESC";
$stmt_enrolled = $conn->prepare($sql_enrolled_lms_courses);
$stmt_enrolled->bind_param('i', $user_id);
$stmt_enrolled->execute();
$result_enrolled = $stmt_enrolled->get_result();

// Hitung statistik
$sql_stats = "SELECT 
    COUNT(*) as total_lms_courses,
    AVG(e.progress) as avg_progress,
    SUM(CASE WHEN e.progress = 100 THEN 1 ELSE 0 END) as completed_lms_courses,
    (SELECT COUNT(*) FROM lms_quiz_attempts WHERE id_siswa = ?) as total_lms_quizzes
    FROM lms_enrollments e 
    WHERE e.id_siswa = ? AND e.status = 'active'";
$stmt_stats = $conn->prepare($sql_stats);
$stmt_stats->bind_param('ii', $user_id, $user_id);
$stmt_stats->execute();
$stats = $stmt_stats->get_result()->fetch_assoc();

// Ambil kursus yang sedang aktif (progress < 100%)
$sql_active_lms_courses = "SELECT c.*, e.progress, u.nama_lengkap as nama_guru
                       FROM lms_enrollments e 
                       JOIN lms_courses c ON e.id_course = c.id 
                       JOIN lms_users u ON c.id_guru = u.id 
                       WHERE e.id_siswa = ? AND e.progress < 100 AND e.status = 'active'
                       ORDER BY e.tanggal_enroll DESC 
                       LIMIT 3";
$stmt_active = $conn->prepare($sql_active_lms_courses);
$stmt_active->bind_param('i', $user_id);
$stmt_active->execute();
$result_active = $stmt_active->get_result();

// Ambil kursus yang sudah selesai (progress = 100%)
$sql_completed_lms_courses = "SELECT c.*, e.progress, e.tanggal_enroll, u.nama_lengkap as nama_guru
                          FROM lms_enrollments e 
                          JOIN lms_courses c ON e.id_course = c.id 
                          JOIN lms_users u ON c.id_guru = u.id 
                          WHERE e.id_siswa = ? AND e.progress = 100 AND e.status = 'active'
                          ORDER BY e.tanggal_enroll DESC 
                          LIMIT 3";
$stmt_completed = $conn->prepare($sql_completed_lms_courses);
$stmt_completed->bind_param('i', $user_id);
$stmt_completed->execute();
$result_completed = $stmt_completed->get_result();

// Ambil quiz attempts terbaru
$sql_recent_lms_quizzes = "SELECT qa.*, q.judul_quiz, c.judul as course_title, c.id as course_id
                       FROM lms_quiz_attempts qa 
                       JOIN lms_quizzes q ON qa.id_quiz = q.id 
                       JOIN lms_lessons l ON q.id_lesson = l.id 
                       JOIN lms_courses c ON l.id_course = c.id 
                       WHERE qa.id_siswa = ? 
                       ORDER BY qa.waktu_mulai DESC 
                       LIMIT 5";
$stmt_lms_quizzes = $conn->prepare($sql_recent_lms_quizzes);
$stmt_lms_quizzes->bind_param('i', $user_id);
$stmt_lms_quizzes->execute();
$result_lms_quizzes = $stmt_lms_quizzes->get_result();

// Ambil rekomendasi kursus
$sql_recommendations = "SELECT c.*, u.nama_lengkap as nama_guru, cat.nama_kategori
                        FROM lms_courses c 
                        JOIN lms_users u ON c.id_guru = u.id 
                        JOIN lms_categories cat ON c.id_kategori = cat.id 
                        WHERE c.id NOT IN (
                            SELECT id_course FROM lms_enrollments WHERE id_siswa = ?
                        )
                        ORDER BY c.rating DESC, c.total_siswa DESC 
                        LIMIT 3";
$stmt_recommend = $conn->prepare($sql_recommendations);
$stmt_recommend->bind_param('i', $user_id);
$stmt_recommend->execute();
$result_recommend = $stmt_recommend->get_result();

// Fungsi untuk format tanggal Indonesia
function formatTanggalIndonesia($date) {
    $bulan = array(
        1 => 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
        'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'
    );
    
    $hari = array(
        'Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'
    );
    
    $timestamp = strtotime($date);
    $hari_ini = $hari[date('w', $timestamp)];
    $tanggal = date('j', $timestamp);
    $bulan_ini = $bulan[date('n', $timestamp)];
    $tahun = date('Y', $timestamp);
    
    return $hari_ini . ', ' . $tanggal . ' ' . $bulan_ini . ' ' . $tahun;
}

// Format tanggal untuk aktivitas
function formatTanggalAktivitas($date) {
    $bulan = array(
        1 => 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun',
        'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'
    );
    
    $timestamp = strtotime($date);
    $tanggal = date('j', $timestamp);
    $bulan_ini = $bulan[date('n', $timestamp)];
    $tahun = date('Y', $timestamp);
    
    return $tanggal . ' ' . $bulan_ini . ' ' . $tahun;
}

$tanggal_hari_ini = formatTanggalIndonesia(date('Y-m-d'));
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard Siswa - SMANSAB LMS</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        :root {
            --primary-color: #3f51b5;
            --secondary-color: #f5f5f5;
        }
        
        .sidebar {
            background: var(--primary-color);
            color: white;
            min-height: 100vh;
            padding: 0;
        }
        
        .sidebar-sticky {
            position: sticky;
            top: 0;
            height: 100vh;
            padding-top: 20px;
            overflow-y: auto;
        }
        
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            padding: 12px 20px;
            margin: 2px 0;
            border-radius: 0;
            transition: all 0.3s;
        }
        
        .sidebar .nav-link:hover {
            color: white;
            background: rgba(255, 255, 255, 0.1);
        }
        
        .sidebar .nav-link.active {
            color: white;
            background: rgba(255, 255, 255, 0.2);
            border-left: 4px solid #fff;
        }
        
        .sidebar .nav-link i {
            width: 20px;
            margin-right: 10px;
        }
        
        .main-content {
            background: #f8f9fa;
            min-height: 100vh;
        }
        
        .navbar-custom {
            background: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        
        .stat-card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            transition: transform 0.3s;
        }
        
        .stat-card:hover {
            transform: translateY(-5px);
        }
        
        .progress-course {
            height: 8px;
            border-radius: 4px;
        }
        
        .course-card {
            border: none;
            border-radius: 10px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            transition: transform 0.3s;
        }
        
        .course-card:hover {
            transform: translateY(-3px);
        }
        
        .welcome-section {
            background: linear-gradient(135deg, var(--primary-color), #7986cb);
            color: white;
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 30px;
        }
        
        .quiz-badge {
            font-size: 0.7rem;
            padding: 4px 8px;
        }
        
        .bg-progress {
            background: linear-gradient(45deg, #667eea, #764ba2);
        }
        
        .bg-lms_courses {
            background: linear-gradient(45deg, #f093fb, #f5576c);
        }
        
        .bg-completed {
            background: linear-gradient(45deg, #4facfe, #00f2fe);
        }
        
        .bg-lms_quizzes {
            background: linear-gradient(45deg, #43e97b, #38f9d7);
        }
        
        .date-box {
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            padding: 15px;
            border: 1px solid rgba(255, 255, 255, 0.3);
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- Sidebar -->
            <div class="col-md-3 col-lg-2 sidebar">
                <div class="sidebar-sticky">
                    <div class="text-center mb-4">
                        <h4 class="fw-bold">
                            <i class="bi bi-book-half"></i><br>
                            SMANSAB LMS
                        </h4>
                        <small class="text-white-50">Siswa Dashboard</small>
                    </div>
                    
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link active" href="dashboard.php">
                                <i class="bi bi-speedometer2"></i> Dashboard
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="my_courses.php">
                                <i class="bi bi-journal-bookmark"></i> Kursus Saya
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="progress.php">
                                <i class="bi bi-graph-up"></i> Progress Belajar
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="quizzes.php">
                                <i class="bi bi-pencil-square"></i> Kuis & Ujian
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="certificates.php">
                                <i class="bi bi-award"></i> Sertifikat
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="profile.php">
                                <i class="bi bi-person"></i> Profil Saya
                            </a>
                        </li>
                        <li class="nav-item mt-4">
                            <a class="nav-link" href="../logout.php">
                                <i class="bi bi-box-arrow-right"></i> Logout
                            </a>
                        </li>
                    </ul>
                    
                    <div class="mt-5 px-3">
                        <small class="text-white-50">
                            <i class="bi bi-info-circle"></i> Butuh bantuan?
                            <a href="#" class="text-white">Hubungi Admin</a>
                        </small>
                    </div>
                </div>
            </div>

            <!-- Main Content -->
            <div class="col-md-9 col-lg-10 main-content">
                <!-- Top Navbar -->
                <nav class="navbar navbar-custom">
                    <div class="container-fluid">
                        <div class="d-flex align-items-center">
                            <button class="btn btn-outline-primary me-3 d-md-none" type="button">
                                <i class="bi bi-list"></i>
                            </button>
                            <h5 class="mb-0">Dashboard Siswa</h5>
                        </div>
                        <div class="d-flex align-items-center">
                            <div class="dropdown">
                                <button class="btn btn-outline-primary dropdown-toggle" type="button" 
                                        data-bs-toggle="dropdown">
                                    <i class="bi bi-person-circle me-2"></i>
                                    <?php echo $siswa['nama_lengkap']; ?>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><a class="dropdown-item" href="profile.php">
                                        <i class="bi bi-person me-2"></i>Profil
                                    </a></li>
                                    <li><a class="dropdown-item" href="../courses.php">
                                        <i class="bi bi-search me-2"></i>Jelajah Kursus
                                    </a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a class="dropdown-item" href="../logout.php">
                                        <i class="bi bi-box-arrow-right me-2"></i>Logout
                                    </a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </nav>

                <div class="container-fluid mt-4">
                    <!-- Welcome Section -->
                    <div class="welcome-section">
                        <div class="row align-items-center">
                            <div class="col-md-8">
                                <h3 class="fw-bold" id="greeting-text">Halo, <?php echo $siswa['nama_lengkap']; ?>! 👋</h3>
                                <p class="mb-0">Selamat datang di dashboard pembelajaran Anda. Teruslah belajar dan raih impian Anda!</p>
                            </div>
                            <div class="col-md-4 text-end">
                                <div class="date-box text-white d-inline-block">
                                    <small class="opacity-75">Hari Ini</small>
                                    <h4 class="mb-0 fw-bold"><?php echo $tanggal_hari_ini; ?></h4>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Statistics Cards -->
                    <div class="row mb-4">
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title text-muted mb-2">Total Kursus</h6>
                                            <h3 class="fw-bold text-primary"><?php echo $stats['total_lms_courses']; ?></h3>
                                        </div>
                                        <div class="col-4 text-end">
                                            <div class="bg-primary rounded-circle p-3 d-inline-flex">
                                                <i class="bi bi-journal-bookmark text-white" style="font-size: 1.5rem;"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title text-muted mb-2">Progress Rata-rata</h6>
                                            <h3 class="fw-bold text-success"><?php echo number_format($stats['avg_progress'] ?? 0, 1); ?>%</h3>
                                        </div>
                                        <div class="col-4 text-end">
                                            <div class="bg-success rounded-circle p-3 d-inline-flex">
                                                <i class="bi bi-graph-up text-white" style="font-size: 1.5rem;"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title text-muted mb-2">Kursus Selesai</h6>
                                            <h3 class="fw-bold text-info"><?php echo $stats['completed_lms_courses']; ?></h3>
                                        </div>
                                        <div class="col-4 text-end">
                                            <div class="bg-info rounded-circle p-3 d-inline-flex">
                                                <i class="bi bi-check-circle text-white" style="font-size: 1.5rem;"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title text-muted mb-2">Total Kuis</h6>
                                            <h3 class="fw-bold text-warning"><?php echo $stats['total_lms_quizzes']; ?></h3>
                                        </div>
                                        <div class="col-4 text-end">
                                            <div class="bg-warning rounded-circle p-3 d-inline-flex">
                                                <i class="bi bi-pencil-square text-white" style="font-size: 1.5rem;"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <!-- Kursus yang Sedang Berjalan -->
                        <div class="col-lg-6 mb-4">
                            <div class="card border-0 shadow-sm">
                                <div class="card-header bg-white border-0">
                                    <h6 class="mb-0">
                                        <i class="bi bi-play-circle text-primary me-2"></i>
                                        Kursus yang Sedang Berjalan
                                    </h6>
                                </div>
                                <div class="card-body">
                                    <?php if ($result_active->num_rows > 0): ?>
                                        <?php while($course = $result_active->fetch_assoc()): ?>
                                            <div class="course-card card mb-3">
                                                <div class="card-body">
                                                    <div class="row align-items-center">
                                                        <div class="col-8">
                                                            <h6 class="card-title mb-1"><?php echo $course['judul']; ?></h6>
                                                            <small class="text-muted">
                                                                Oleh: <?php echo $course['nama_guru']; ?>
                                                            </small>
                                                            <div class="mt-2">
                                                                <div class="d-flex justify-content-between mb-1">
                                                                    <small>Progress</small>
                                                                    <small><?php echo $course['progress']; ?>%</small>
                                                                </div>
                                                                <div class="progress progress-course">
                                                                    <div class="progress-bar" 
                                                                         style="width: <?php echo $course['progress']; ?>%">
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-4 text-end">
                                                            <a href="course_detail.php?id=<?php echo $course['id']; ?>" 
                                                               class="btn btn-primary btn-sm">
                                                                Lanjutkan
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endwhile; ?>
                                    <?php else: ?>
                                        <div class="text-center py-4">
                                            <i class="bi bi-journal-x text-muted" style="font-size: 3rem;"></i>
                                            <p class="text-muted mt-2">Belum ada kursus yang sedang diikuti</p>
                                            <a href="../courses.php" class="btn btn-primary btn-sm">
                                                Jelajah Kursus
                                            </a>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>

                        <!-- Aktivitas Terbaru -->
                        <div class="col-lg-6 mb-4">
                            <div class="card border-0 shadow-sm">
                                <div class="card-header bg-white border-0">
                                    <h6 class="mb-0">
                                        <i class="bi bi-clock text-warning me-2"></i>
                                        Aktivitas Terbaru
                                    </h6>
                                </div>
                                <div class="card-body">
                                    <?php if ($result_lms_quizzes->num_rows > 0): ?>
                                        <div class="list-group list-group-flush">
                                            <?php while($quiz = $result_lms_quizzes->fetch_assoc()): ?>
                                                <div class="list-group-item px-0">
                                                    <div class="d-flex align-items-center">
                                                        <div class="flex-shrink-0">
                                                            <div class="bg-light rounded p-2">
                                                                <i class="bi bi-pencil-square text-primary"></i>
                                                            </div>
                                                        </div>
                                                        <div class="flex-grow-1 ms-3">
                                                            <h6 class="mb-0 small"><?php echo $quiz['judul_quiz']; ?></h6>
                                                            <small class="text-muted">
                                                                <?php echo $quiz['course_title']; ?>
                                                            </small>
                                                            <div class="mt-1">
                                                                <span class="badge quiz-badge 
                                                                    <?php echo $quiz['nilai'] >= 60 ? 'bg-success' : 'bg-danger'; ?>">
                                                                    Nilai: <?php echo $quiz['nilai'] ?? '0'; ?>
                                                                </span>
                                                                <small class="text-muted ms-2">
                                                                    <?php echo formatTanggalAktivitas($quiz['waktu_mulai']); ?>
                                                                </small>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php endwhile; ?>
                                        </div>
                                    <?php else: ?>
                                        <div class="text-center py-4">
                                            <i class="bi bi-clock text-muted" style="font-size: 3rem;"></i>
                                            <p class="text-muted mt-2">Belum ada aktivitas terbaru</p>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Kursus yang Sudah Selesai -->
                            <div class="card border-0 shadow-sm mt-4">
                                <div class="card-header bg-white border-0">
                                    <h6 class="mb-0">
                                        <i class="bi bi-check-circle text-success me-2"></i>
                                        Kursus Selesai
                                    </h6>
                                </div>
                                <div class="card-body">
                                    <?php if ($result_completed->num_rows > 0): ?>
                                        <?php while($course = $result_completed->fetch_assoc()): ?>
                                            <div class="d-flex align-items-center mb-3">
                                                <div class="flex-shrink-0">
                                                    <div class="bg-success rounded p-2">
                                                        <i class="bi bi-check-lg text-white"></i>
                                                    </div>
                                                </div>
                                                <div class="flex-grow-1 ms-3">
                                                    <h6 class="mb-0 small"><?php echo $course['judul']; ?></h6>
                                                    <small class="text-muted">
                                                        Selesai: <?php echo formatTanggalAktivitas($course['tanggal_enroll']); ?>
                                                    </small>
                                                </div>
                                                <div class="flex-shrink-0">
                                                    <span class="badge bg-success">100%</span>
                                                </div>
                                            </div>
                                        <?php endwhile; ?>
                                    <?php else: ?>
                                        <div class="text-center py-3">
                                            <small class="text-muted">Belum ada kursus yang selesai</small>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Rekomendasi Kursus -->
                    <?php if ($result_recommend->num_rows > 0): ?>
                    <div class="row mt-4">
                        <div class="col-12">
                            <div class="card border-0 shadow-sm">
                                <div class="card-header bg-white border-0 d-flex justify-content-between align-items-center">
                                    <h6 class="mb-0">
                                        <i class="bi bi-stars text-warning me-2"></i>
                                        Rekomendasi untuk Anda
                                    </h6>
                                    <a href="../courses.php" class="btn btn-outline-primary btn-sm">
                                        Lihat Semua
                                    </a>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <?php while($course = $result_recommend->fetch_assoc()): ?>
                                            <div class="col-md-4 mb-3">
                                                <div class="card course-card h-100">
                                                    <div class="card-body">
                                                        <span class="badge bg-light text-dark mb-2">
                                                            <?php echo $course['nama_kategori']; ?>
                                                        </span>
                                                        <h6 class="card-title"><?php echo $course['judul']; ?></h6>
                                                        <p class="card-text small text-muted">
                                                            <?php echo strlen($course['deskripsi']) > 80 ? 
                                                                substr($course['deskripsi'], 0, 80) . '...' : 
                                                                $course['deskripsi']; ?>
                                                        </p>
                                                        <div class="d-flex justify-content-between align-items-center">
                                                            <small class="text-muted">
                                                                <?php echo $course['nama_guru']; ?>
                                                            </small>
                                                            <a href="course_detail.php?id=<?php echo $course['id']; ?>" 
                                                               class="btn btn-primary btn-sm">
                                                                Lihat
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endwhile; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Simple greeting based on time
        function updateGreeting() {
            const hour = new Date().getHours();
            const greeting = document.getElementById('greeting-text');
            let newGreeting = 'Halo, <?php echo $siswa['nama_lengkap']; ?>! 👋';
            
            if (hour < 12) newGreeting = 'Selamat Pagi, <?php echo $siswa['nama_lengkap']; ?>! 🌅';
            else if (hour < 15) newGreeting = 'Selamat Siang, <?php echo $siswa['nama_lengkap']; ?>! ☀️';
            else if (hour < 18) newGreeting = 'Selamat Sore, <?php echo $siswa['nama_lengkap']; ?>! 🌇';
            else newGreeting = 'Selamat Malam, <?php echo $siswa['nama_lengkap']; ?>! 🌙';
            
            if (greeting) greeting.textContent = newGreeting;
        }
        
        // Update greeting on page load
        document.addEventListener('DOMContentLoaded', updateGreeting);
    </script>
</body>
</html>