<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hasil Analisis - ASGARD</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Plus Jakarta Sans', sans-serif;
            background-color: #f8fafc;
        }

        .card-shadow {
            box-shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
        }
    </style>
</head>
<body class="flex flex-col min-h-screen text-slate-800">

    <nav class="sticky top-0 z-50 bg-white/95 backdrop-blur-md border-b border-slate-100 px-6 py-4">
        <div class="max-w-7xl mx-auto flex items-center justify-between gap-4">
            <div class="flex items-center gap-4">
                <div class="w-10 h-10 bg-emerald-100 rounded-xl flex items-center justify-center text-emerald-600 font-bold">AS</div>
                <span class="font-black text-xl tracking-tighter text-emerald-950 uppercase italic">ASGARD.</span>
            </div>

            <div class="hidden md:flex items-center gap-8 text-[11px] font-bold uppercase tracking-widest text-slate-400">
                <a href="{{ route('student.profile') }}" class="hover:text-emerald-600 transition">Beranda</a>
                <a href="{{ route('student.prediction') }}" class="text-emerald-600">Cek Rekomendasi</a>
                <a href="#" class="hover:text-emerald-600 transition">Kontak BK</a>
            </div>

            <div class="flex items-center gap-3">
                <div class="hidden sm:flex items-center gap-3 bg-emerald-50 px-4 py-2 rounded-full border border-emerald-100">
                    <div class="w-2 h-2 bg-emerald-500 rounded-full animate-pulse"></div>
                    <span class="text-[10px] font-bold text-emerald-700 uppercase">Siswa Terdaftar</span>
                </div>
                <button onclick="handleLogout()" class="bg-red-50 hover:bg-red-100 text-red-600 border border-red-100 px-4 py-2 rounded-full transition-all">
                    <span class="text-[10px] font-bold uppercase tracking-widest">Logout</span>
                </button>
            </div>
        </div>
    </nav>

    <main class="flex-grow px-6 py-10">
        <div class="max-w-5xl mx-auto">
            <div class="text-center mb-8">
                <div class="inline-flex items-center gap-2 bg-emerald-100 text-emerald-700 px-4 py-2 rounded-full text-xs font-bold">
                    Analisis Random Forest Selesai ✅
                </div>
                <h1 class="mt-5 text-4xl md:text-5xl font-extrabold tracking-tight text-slate-900">
                    Laporan Rekomendasi AI
                </h1>
                <p class="text-slate-500 mt-3">
                    Berdasarkan data akademik dan minat bakat, berikut diagnosis masa depanmu.
                </p>
            </div>

            <div class="bg-gradient-to-br from-emerald-600 via-emerald-500 to-teal-600 rounded-[2.5rem] p-8 md:p-14 text-white card-shadow mb-8 relative overflow-hidden">
                <div class="absolute inset-0 opacity-10">
                    <div class="absolute -top-10 -left-10 w-40 h-40 bg-white rounded-full blur-3xl"></div>
                    <div class="absolute -bottom-10 -right-10 w-56 h-56 bg-white rounded-full blur-3xl"></div>
                </div>

                <div class="relative z-10 text-center">
                    <p class="text-[11px] md:text-sm font-bold uppercase tracking-[0.35em] text-emerald-100 mb-5">
                        Sangat Cocok di Bidang
                    </p>

                    <h2 class="text-3xl md:text-6xl font-black uppercase leading-tight tracking-tight mb-8">
                        {{ $riwayat->hasil_rekomendasi_jurusan }}
                    </h2>

                    <div class="flex flex-col sm:flex-row gap-3 justify-center">
                        <a href="{{ route('student.prediction') }}"
                           class="inline-flex items-center justify-center bg-emerald-700/70 hover:bg-emerald-800 text-white font-bold py-4 px-8 rounded-2xl transition border border-white/10">
                            ↻ Ulangi Analisis
                        </a>

                        <a href="{{ route('student.profile') }}"
                           class="inline-flex items-center justify-center bg-white hover:bg-slate-100 text-emerald-700 font-bold py-4 px-8 rounded-2xl transition">
                            Kembali ke Dashboard →
                        </a>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-[2rem] border border-slate-100 card-shadow p-6 md:p-8 mb-8">
                <div class="flex items-center gap-3 mb-6">
                    <div class="w-10 h-10 rounded-2xl bg-violet-100 flex items-center justify-center text-xl">👤</div>
                    <h3 class="text-2xl font-extrabold text-slate-800">Rekapan Profilmu</h3>
                </div>

                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <div class="bg-slate-50 border border-slate-100 rounded-3xl p-5">
                        <p class="text-[11px] font-bold uppercase tracking-widest text-slate-400 mb-3">Kondisi Ekonomi</p>
                        <div class="flex items-center gap-4">
                            <div class="w-14 h-14 rounded-2xl bg-amber-100 flex items-center justify-center text-2xl">💰</div>
                            <div>
                                <p class="font-extrabold text-slate-800 leading-snug">
                                    {{ $labelEkonomi }}
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="bg-slate-50 border border-slate-100 rounded-3xl p-5">
                        <p class="text-[11px] font-bold uppercase tracking-widest text-slate-400 mb-3">Minat Utama</p>
                        <div class="flex items-center gap-4">
                            <div class="w-14 h-14 rounded-2xl bg-pink-100 flex items-center justify-center text-2xl">🎯</div>
                            <div>
                                <p class="font-extrabold text-slate-800 leading-snug">
                                    {{ $minatUtama }}
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="bg-slate-50 border border-slate-100 rounded-3xl p-5">
                        <p class="text-[11px] font-bold uppercase tracking-widest text-slate-400 mb-3">Akademik</p>
                        <div class="flex items-center gap-4">
                            <div class="w-14 h-14 rounded-2xl bg-cyan-100 flex items-center justify-center text-2xl">📚</div>
                            <div>
                                <p class="font-extrabold text-slate-800 leading-snug">
                                    15 Mata Pelajaran
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                <div class="bg-white rounded-[2rem] border border-slate-100 card-shadow p-6 md:p-8">
                    <h3 class="text-xl font-extrabold text-slate-800 mb-4">Ringkasan Analisis</h3>
                    <p class="text-slate-600 leading-relaxed">
                        Berdasarkan perpaduan profil akademik, kecenderungan minat bakat, dan kondisi ekonomi keluarga,
                        sistem menilai bahwa jurusan ini merupakan pilihan yang paling relevan untuk dipertimbangkan pada tahap saat ini.
                    </p>
                </div>

                <div class="bg-white rounded-[2rem] border border-slate-100 card-shadow p-6 md:p-8">
                    <h3 class="text-xl font-extrabold text-slate-800 mb-4">Peluang Karier</h3>
                    <p class="text-slate-600 leading-relaxed">
                        {{ $prospekKerja }}
                    </p>
                </div>
            </div>
        </div>
    </main>

    <footer class="bg-[#062C22] text-white py-16 px-6 mt-16">
        <div class="max-w-7xl mx-auto grid grid-cols-1 md:grid-cols-3 gap-12">
            <div class="space-y-6">
                <div class="flex items-center gap-4">
                    <span class="font-black text-2xl tracking-tighter uppercase italic">ASGARD.</span>
                </div>
                <p class="text-slate-300 text-sm leading-relaxed max-w-xs">
                    Sistem pakar rekomendasi jurusan kuliah SMAN 4 Jember berbasis data-driven.
                </p>
            </div>

            <div>
                <h5 class="font-bold text-xs uppercase tracking-widest text-emerald-400 mb-6">Informasi</h5>
                <ul class="space-y-4 text-sm text-slate-300">
                    <li><a href="{{ route('panduan') }}" class="hover:text-white transition">Panduan Sistem</a></li>
                    <li><a href="#" class="hover:text-white transition">Kebijakan Privasi</a></li>
                </ul>
            </div>

            <div>
                <h5 class="font-bold text-xs uppercase tracking-widest text-emerald-400 mb-6">Sekolah</h5>
                <ul class="space-y-4 text-sm text-slate-300">
                    <li>SMAN 4 Jember</li>
                    <li>Jl. Wolter Monginsidi No.24</li>
                    <li>Jember, Jawa Timur</li>
                </ul>
            </div>
        </div>

        <div class="max-w-7xl mx-auto mt-16 pt-8 border-t border-white/10 text-center">
            <p class="text-[10px] font-medium uppercase tracking-[0.5em] text-slate-400">
                © 2026 GALANG SEFIAN ADJI - POLITEKNIK NEGERI JEMBER
            </p>
        </div>
    </footer>

    <script>
        function getAccessToken() {
            return localStorage.getItem('access_token');
        }

        function getUserRole() {
            return localStorage.getItem('user_role');
        }

        function redirectByRole(role) {
            if (role === 'admin') {
                window.location.href = "{{ route('admin.dashboard') }}";
                return;
            }

            if (role === 'siswa') {
                window.location.href = "{{ route('student.profile') }}";
                return;
            }

            window.location.href = "{{ route('login') }}";
        }

        async function handleLogout() {
            const token = getAccessToken();

            if (token) {
                try {
                    await fetch('/api/logout', {
                        method: 'POST',
                        headers: {
                            'Authorization': `Bearer ${token}`,
                            'Accept': 'application/json'
                        }
                    });
                } catch (error) {
                    console.error('Logout error:', error);
                }
            }

            localStorage.removeItem('access_token');
            localStorage.removeItem('user_role');
            window.location.href = "{{ route('login') }}";
        }

        document.addEventListener('DOMContentLoaded', function () {
            const token = getAccessToken();
            const role = getUserRole();

            if (!token) {
                window.location.href = "{{ route('login') }}";
                return;
            }

            if (role !== 'siswa') {
                redirectByRole(role);
            }
        });
    </script>
</body>
</html>