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

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

$user_id = $_SESSION['user_id'];

// Ambil data progress semua kursus
$sql_progress = "SELECT c.*, e.progress, e.tanggal_enroll, e.status as enrollment_status,
                        u.nama_lengkap as nama_guru, cat.nama_kategori,
                        (SELECT COUNT(*) FROM lms_lessons WHERE id_course = c.id) as total_lms_lessons,
                        (SELECT COUNT(*) FROM lms_lessons l 
                         WHERE l.id_course = c.id AND l.urutan <= (e.progress/10)) as completed_lms_lessons
                 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 = ? 
                 ORDER BY e.tanggal_enroll DESC";
$stmt_progress = $conn->prepare($sql_progress);
$stmt_progress->bind_param('i', $user_id);
$stmt_progress->execute();
$result_progress = $stmt_progress->get_result();

// Hitung statistik progress
$total_lms_courses = 0;
$total_progress = 0;
$completed_lms_courses = 0;
$active_lms_courses = 0;

$lms_courses_data = [];
while ($course = $result_progress->fetch_assoc()) {
    $lms_courses_data[] = $course;
    $total_lms_courses++;
    $total_progress += $course['progress'];
    
    if ($course['progress'] == 100) {
        $completed_lms_courses++;
    } elseif ($course['progress'] > 0 && $course['progress'] < 100) {
        $active_lms_courses++;
    }
}

$average_progress = $total_lms_courses > 0 ? round($total_progress / $total_lms_courses, 1) : 0;

// Ambil aktivitas belajar terbaru
$sql_activities = "SELECT qa.*, q.judul_quiz, l.judul_lesson, c.judul as course_title, c.id as course_id,
                          l.urutan as lesson_urutan
                   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 10";
$stmt_activities = $conn->prepare($sql_activities);
$stmt_activities->bind_param('i', $user_id);
$stmt_activities->execute();
$result_activities = $stmt_activities->get_result();

// Ambil progress per minggu (untuk chart)
$sql_weekly_progress = "SELECT 
                        YEARWEEK(tanggal_enroll) as week,
                        COUNT(*) as lms_courses_started,
                        AVG(progress) as avg_progress
                        FROM lms_enrollments 
                        WHERE id_siswa = ? 
                        AND tanggal_enroll >= DATE_SUB(NOW(), INTERVAL 8 WEEK)
                        GROUP BY YEARWEEK(tanggal_enroll)
                        ORDER BY week DESC 
                        LIMIT 8";
$stmt_weekly = $conn->prepare($sql_weekly_progress);
$stmt_weekly->bind_param('i', $user_id);
$stmt_weekly->execute();
$result_weekly = $stmt_weekly->get_result();

$weekly_data = [];
while ($week = $result_weekly->fetch_assoc()) {
    $weekly_data[] = $week;
}

// Hitung waktu belajar total (estimasi)
$sql_study_time = "SELECT SUM(l.durasi_menit) as total_minutes
                   FROM lms_enrollments e 
                   JOIN lms_courses c ON e.id_course = c.id 
                   JOIN lms_lessons l ON c.id = l.id_course 
                   WHERE e.id_siswa = ? AND l.urutan <= (e.progress/10)";
$stmt_study = $conn->prepare($sql_study_time);
$stmt_study->bind_param('i', $user_id);
$stmt_study->execute();
$study_result = $stmt_study->get_result();
$total_study_minutes = $study_result->fetch_assoc()['total_minutes'] ?? 0;
$total_study_hours = round($total_study_minutes / 60, 1);
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Progress Belajar - 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">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <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);
        }
        
        .chart-container {
            background: white;
            border-radius: 15px;
            padding: 20px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        
        .activity-item {
            padding: 15px;
            border-left: 4px solid transparent;
            transition: all 0.3s;
        }
        
        .activity-item:hover {
            background: #f8f9fa;
        }
        
        .activity-quiz {
            border-left-color: #ffc107;
        }
        
        .activity-complete {
            border-left-color: #28a745;
        }
        
        .progress-ring {
            width: 120px;
            height: 120px;
        }
        
        .level-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-time {
            background: linear-gradient(45deg, #43e97b, #38f9d7);
        }
    </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" 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 active" 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">Progress Belajar</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 $_SESSION['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">
                    <!-- Header Section -->
                    <div class="row mb-4">
                        <div class="col-12">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h4 class="fw-bold">Progress Belajar</h4>
                                    <p class="text-muted mb-0">Pantau perkembangan pembelajaran Anda</p>
                                </div>
                                <div class="dropdown">
                                    <button class="btn btn-outline-primary dropdown-toggle" type="button" 
                                            data-bs-toggle="dropdown">
                                        <i class="bi bi-download me-2"></i>Export Laporan
                                    </button>
                                    <ul class="dropdown-menu">
                                        <li><a class="dropdown-item" href="#"><i class="bi bi-file-pdf me-2"></i>PDF</a></li>
                                        <li><a class="dropdown-item" href="#"><i class="bi bi-file-excel me-2"></i>Excel</a></li>
                                    </ul>
                                </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 text-white bg-progress">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title mb-2">Progress Rata-rata</h6>
                                            <h2 class="fw-bold"><?php echo $average_progress; ?>%</h2>
                                            <small>Dari semua kursus</small>
                                        </div>
                                        <div class="col-4 text-end">
                                            <i class="bi bi-graph-up-arrow" style="font-size: 2.5rem;"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0 text-white bg-lms_courses">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title mb-2">Total Kursus</h6>
                                            <h2 class="fw-bold"><?php echo $total_lms_courses; ?></h2>
                                            <small>Kursus diikuti</small>
                                        </div>
                                        <div class="col-4 text-end">
                                            <i class="bi bi-journal-bookmark" style="font-size: 2.5rem;"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0 text-white bg-completed">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title mb-2">Kursus Selesai</h6>
                                            <h2 class="fw-bold"><?php echo $completed_lms_courses; ?></h2>
                                            <small>100% progress</small>
                                        </div>
                                        <div class="col-4 text-end">
                                            <i class="bi bi-check-circle" style="font-size: 2.5rem;"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-xl-3 col-md-6 mb-4">
                            <div class="card stat-card border-0 text-white bg-time">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-8">
                                            <h6 class="card-title mb-2">Waktu Belajar</h6>
                                            <h2 class="fw-bold"><?php echo $total_study_hours; ?>h</h2>
                                            <small>Total belajar</small>
                                        </div>
                                        <div class="col-4 text-end">
                                            <i class="bi bi-clock" style="font-size: 2.5rem;"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <!-- Progress Chart -->
                        <div class="col-lg-8 mb-4">
                            <div class="chart-container">
                                <div class="d-flex justify-content-between align-items-center mb-4">
                                    <h6 class="mb-0 fw-bold">Progress Belajar 8 Minggu Terakhir</h6>
                                    <div class="dropdown">
                                        <button class="btn btn-outline-secondary btn-sm dropdown-toggle" type="button" 
                                                data-bs-toggle="dropdown">
                                            <i class="bi bi-filter me-1"></i>Filter
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Mingguan</a></li>
                                            <li><a class="dropdown-item" href="#">Bulanan</a></li>
                                            <li><a class="dropdown-item" href="#">Tahunan</a></li>
                                        </ul>
                                    </div>
                                </div>
                                <canvas id="progressChart" height="250"></canvas>
                            </div>

                            <!-- lms_courses Progress -->
                            <div class="chart-container">
                                <h6 class="fw-bold mb-4">Progress Per Kursus</h6>
                                <?php if (!empty($lms_courses_data)): ?>
                                    <?php foreach ($lms_courses_data as $course): ?>
                                        <div class="course-card card mb-3">
                                            <div class="card-body">
                                                <div class="row align-items-center">
                                                    <div class="col-md-8">
                                                        <h6 class="card-title mb-1"><?php echo $course['judul']; ?></h6>
                                                        <div class="d-flex align-items-center mb-2">
                                                            <small class="text-muted me-3">
                                                                Oleh: <?php echo $course['nama_guru']; ?>
                                                            </small>
                                                            <span class="level-badge badge bg-light text-dark">
                                                                <?php echo ucfirst($course['level']); ?>
                                                            </span>
                                                        </div>
                                                        <div class="mb-2">
                                                            <div class="d-flex justify-content-between mb-1">
                                                                <small class="text-muted">Progress</small>
                                                                <small class="text-muted">
                                                                    <?php echo $course['completed_lms_lessons']; ?> dari <?php echo $course['total_lms_lessons']; ?> materi
                                                                </small>
                                                            </div>
                                                            <div class="progress progress-course">
                                                                <div class="progress-bar 
                                                                    <?php echo $course['progress'] == 100 ? 'bg-success' : 'bg-primary'; ?>" 
                                                                     style="width: <?php echo $course['progress']; ?>%">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-4 text-end">
                                                        <div class="mb-2">
                                                            <h4 class="fw-bold text-primary mb-0"><?php echo $course['progress']; ?>%</h4>
                                                            <small class="text-muted">Progress</small>
                                                        </div>
                                                        <a href="course_learn.php?id=<?php echo $course['id']; ?>" 
                                                           class="btn btn-primary btn-sm">
                                                            <?php echo $course['progress'] == 100 ? 'Lihat Ulang' : 'Lanjutkan'; ?>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    <?php endforeach; ?>
                                <?php else: ?>
                                    <div class="text-center py-5">
                                        <i class="bi bi-journal-x text-muted" style="font-size: 3rem;"></i>
                                        <p class="text-muted mt-3">Belum ada progress belajar</p>
                                        <a href="../courses.php" class="btn btn-primary">
                                            <i class="bi bi-search me-2"></i>Jelajah Kursus
                                        </a>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>

                        <!-- Sidebar - Aktivitas & Pencapaian -->
                        <div class="col-lg-4 mb-4">
                            <!-- Aktivitas Terbaru -->
                            <div class="chart-container mb-4">
                                <h6 class="fw-bold mb-3">
                                    <i class="bi bi-clock-history me-2"></i>Aktivitas Terbaru
                                </h6>
                                <div class="activities-list">
                                    <?php if ($result_activities->num_rows > 0): ?>
                                        <?php while($activity = $result_activities->fetch_assoc()): ?>
                                            <div class="activity-item activity-quiz">
                                                <div class="d-flex align-items-start">
                                                    <div class="flex-shrink-0">
                                                        <div class="bg-warning rounded-circle p-2">
                                                            <i class="bi bi-pencil-square text-white"></i>
                                                        </div>
                                                    </div>
                                                    <div class="flex-grow-1 ms-3">
                                                        <h6 class="mb-1 small">Mengerjakan Quiz</h6>
                                                        <p class="mb-1 small"><?php echo $activity['judul_quiz']; ?></p>
                                                        <small class="text-muted">
                                                            <?php echo $activity['course_title']; ?> • 
                                                            Nilai: <strong><?php echo $activity['nilai'] ?? '0'; ?></strong>
                                                        </small>
                                                        <div class="mt-1">
                                                            <small class="text-muted">
                                                                <?php echo date('d M Y H:i', strtotime($activity['waktu_mulai'])); ?>
                                                            </small>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endwhile; ?>
                                    <?php else: ?>
                                        <div class="text-center py-4">
                                            <i class="bi bi-clock text-muted" style="font-size: 2rem;"></i>
                                            <p class="text-muted mt-2 small">Belum ada aktivitas terbaru</p>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Pencapaian -->
                            <div class="chart-container">
                                <h6 class="fw-bold mb-3">
                                    <i class="bi bi-award me-2"></i>Pencapaian
                                </h6>
                                <div class="achievements-list">
                                    <div class="d-flex align-items-center mb-3">
                                        <div class="flex-shrink-0">
                                            <div class="bg-success rounded-circle 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">Pembelajar Aktif</h6>
                                            <small class="text-muted">Menyelesaikan <?php echo $completed_lms_courses; ?> kursus</small>
                                        </div>
                                    </div>
                                    
                                    <div class="d-flex align-items-center mb-3">
                                        <div class="flex-shrink-0">
                                            <div class="bg-primary rounded-circle p-2">
                                                <i class="bi bi-clock text-white"></i>
                                            </div>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <h6 class="mb-0 small">Dedikasi Waktu</h6>
                                            <small class="text-muted"><?php echo $total_study_hours; ?> jam belajar</small>
                                        </div>
                                    </div>
                                    
                                    <div class="d-flex align-items-center mb-3">
                                        <div class="flex-shrink-0">
                                            <div class="bg-warning rounded-circle p-2">
                                                <i class="bi bi-lightning text-white"></i>
                                            </div>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <h6 class="mb-0 small">Konsistensi</h6>
                                            <small class="text-muted">Progress rata-rata <?php echo $average_progress; ?>%</small>
                                        </div>
                                    </div>
                                    
                                    <?php if ($completed_lms_courses >= 5): ?>
                                    <div class="d-flex align-items-center mb-3">
                                        <div class="flex-shrink-0">
                                            <div class="bg-danger rounded-circle p-2">
                                                <i class="bi bi-star text-white"></i>
                                            </div>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <h6 class="mb-0 small">Expert Learner</h6>
                                            <small class="text-muted">Menyelesaikan 5+ kursus</small>
                                        </div>
                                    </div>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Tips Belajar -->
                            <div class="chart-container mt-4">
                                <h6 class="fw-bold mb-3">
                                    <i class="bi bi-lightbulb me-2"></i>Tips Belajar
                                </h6>
                                <div class="tips-list">
                                    <div class="alert alert-info alert-dismissible fade show" role="alert">
                                        <small>
                                            <strong>Atur jadwal rutin!</strong> Belajar 30 menit setiap hari lebih efektif daripada 3 jam sekali seminggu.
                                        </small>
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                    <div class="alert alert-warning alert-dismissible fade show" role="alert">
                                        <small>
                                            <strong>Istirahat teratur!</strong> Gunakan teknik Pomodoro: 25 menit belajar, 5 menit istirahat.
                                        </small>
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                                        <small>
                                            <strong>Praktik langsung!</strong> Coba implementasikan konsep yang dipelajari dengan proyek kecil.
                                        </small>
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Progress Chart
        document.addEventListener('DOMContentLoaded', function() {
            const ctx = document.getElementById('progressChart').getContext('2d');
            
            // Data dari PHP (dummy data untuk contoh)
            const weeklyData = <?php echo json_encode($weekly_data); ?>;
            
            // Siapkan data untuk chart
            const weeks = weeklyData.map(week => `Minggu ${week.week % 100}`).reverse();
            const progress = weeklyData.map(week => parseFloat(week.avg_progress || 0)).reverse();
            const lms_courses = weeklyData.map(week => parseInt(week.lms_courses_started || 0)).reverse();
            
            const progressChart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: weeks,
                    datasets: [
                        {
                            label: 'Progress Rata-rata (%)',
                            data: progress,
                            borderColor: '#3f51b5',
                            backgroundColor: 'rgba(63, 81, 181, 0.1)',
                            tension: 0.4,
                            fill: true
                        },
                        {
                            label: 'Kursus Dimulai',
                            data: lms_courses,
                            borderColor: '#ff9800',
                            backgroundColor: 'rgba(255, 152, 0, 0.1)',
                            tension: 0.4,
                            fill: true
                        }
                    ]
                },
                options: {
                    responsive: true,
                    plugins: {
                        legend: {
                            position: 'top',
                        },
                        tooltip: {
                            mode: 'index',
                            intersect: false
                        }
                    },
                    scales: {
                        y: {
                            beginAtZero: true,
                            max: 100,
                            ticks: {
                                callback: function(value) {
                                    return value + '%';
                                }
                            }
                        }
                    }
                }
            });
        });
    </script>
</body>
</html>