<!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;600;700;800&display=swap" rel="stylesheet">
    <style>
        body { font-family: 'Plus Jakarta Sans', sans-serif; background-color: #f8fafc; }
    </style>
</head>
<body class="flex flex-col min-h-screen">

    <nav class="bg-white border-b border-slate-100 px-6 py-4 mb-10">
        <div class="max-w-7xl mx-auto flex justify-between items-center">
            <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="flex items-center gap-3">
                <a href="{{ route('student.prediction') }}"
                   class="text-sm font-semibold text-slate-600 hover:text-emerald-600 transition">
                    Kembali ke Form
                </a>
                <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 flex items-center justify-center px-6">
        <div class="max-w-xl w-full bg-white p-10 rounded-3xl shadow-xl text-center border border-slate-100 relative overflow-hidden">
            <div class="absolute -top-10 -right-10 w-32 h-32 bg-emerald-50 rounded-full blur-2xl"></div>
            <div class="absolute -bottom-10 -left-10 w-32 h-32 bg-blue-50 rounded-full blur-2xl"></div>

            <div class="relative z-10">
                <div class="w-20 h-20 bg-emerald-100 text-emerald-600 rounded-full flex items-center justify-center mx-auto mb-6">
                    <svg class="w-10 h-10" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                    </svg>
                </div>

                <h2 class="text-slate-500 font-bold tracking-widest text-sm mb-2 uppercase">Rekomendasi AI Engine</h2>
                <h1 class="text-4xl font-extrabold text-slate-800 mb-6 leading-tight">
                    {{ $riwayat->hasil_rekomendasi_jurusan }}
                </h1>

                <div class="bg-slate-50 p-6 rounded-2xl mb-8 border border-slate-100 text-left">
                    <h3 class="font-bold text-slate-800 mb-2">Ringkasan Analisis</h3>
                    <p class="text-slate-600 text-sm leading-relaxed mb-4">
                        Berdasarkan perpaduan profil akademik siswa, skor minat bakat RIASEC, dan kondisi ekonomi keluarga,
                        sistem merekomendasikan jurusan ini sebagai pilihan yang paling sesuai untuk Anda.
                    </p>

                    <h3 class="font-bold text-slate-800 mb-2">Peluang Karier</h3>
                    <p class="text-slate-600 text-sm leading-relaxed">
                        {{ $prospekKerja ?? 'Informasi prospek karier belum tersedia untuk jurusan ini.' }}
                    </p>
                </div>

                <div class="flex flex-col sm:flex-row gap-3 justify-center">
                    <a href="{{ route('student.prediction') }}"
                       class="inline-block bg-slate-800 hover:bg-slate-900 text-white font-bold py-3 px-8 rounded-xl transition shadow-lg">
                        Analisis Ulang
                    </a>

                    <a href="{{ route('student.profile') }}"
                       class="inline-block bg-emerald-600 hover:bg-emerald-700 text-white font-bold py-3 px-8 rounded-xl transition shadow-lg">
                        Kembali ke Dashboard
                    </a>
                </div>
            </div>
        </div>
    </main>

    <footer class="bg-slate-900 text-white mt-20 py-12 px-6">
        <div class="max-w-7xl mx-auto flex justify-between items-center text-center">
            <p class="text-[10px] font-medium uppercase tracking-[0.2em] text-slate-500 w-full">
                © 2026 ASGARD SMAN 4 JEMBER. All Rights Reserved.
            </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>