<div class="space-y-6">
    {{-- Header --}}
    <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
        <div class="flex items-center justify-between">
            <div>
                <h2 class="text-2xl font-bold text-gray-900">{{ $student->name ?? '学生' }}</h2>
                <p class="text-sm text-gray-500 mt-1">
                    学号: {{ $studentId }} | 
                    邮箱: {{ $student->email ?? 'N/A' }}
                </p>
            </div>
            <div class="flex items-center space-x-4">
                <div class="text-right">
                    <p class="text-sm text-gray-500">知识点数量</p>
                    <p class="text-2xl font-bold text-indigo-600">{{ $totalKnowledgePoints }}</p>
                </div>
            </div>
        </div>
    </div>

    {{-- Loading State --}}
    @if($loading)
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-12 text-center">
            <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-indigo-600 mx-auto"></div>
            <p class="mt-4 text-gray-500">加载学习数据中...</p>
        </div>
    {{-- Error State --}}
    @elseif($error)
        <div class="bg-red-50 border border-red-200 rounded-lg p-6">
            <div class="flex">
                <svg class="h-5 w-5 text-red-400" fill="currentColor" viewBox="0 0 20 20">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
                </svg>
                <div class="ml-3">
                    <h3 class="text-sm font-medium text-red-800">加载失败</h3>
                    <p class="mt-2 text-sm text-red-700">{{ $error }}</p>
                </div>
            </div>
        </div>
    {{-- Data --}}
    @else
        {{-- Mastery Overview --}}
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
            <h3 class="text-lg font-semibold text-gray-900 mb-4">掌握度概览</h3>
            
            @if(empty($masteryPoints))
                <div class="text-center py-12 text-gray-500">
                    <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
                    </svg>
                    <p class="mt-2">暂无掌握度数据</p>
                </div>
            @else
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                    @foreach($masteryPoints as $point)
                        @php
                            $mastery = $point['mastery_level'] * 100;
                            if ($mastery >= 80) {
                                $colorClass = 'green';
                                $badgeClass = 'bg-green-100 text-green-800';
                                $barClass = 'bg-green-600';
                            } elseif ($mastery >= 60) {
                                $colorClass = 'yellow';
                                $badgeClass = 'bg-yellow-100 text-yellow-800';
                                $barClass = 'bg-yellow-600';
                            } else {
                                $colorClass = 'red';
                                $badgeClass = 'bg-red-100 text-red-800';
                                $barClass = 'bg-red-600';
                            }
                        @endphp
                        <div class="border border-gray-200 rounded-lg p-4">
                            <div class="flex items-center justify-between mb-2">
                                <h4 class="font-medium text-gray-900">{{ $point['kp_code'] }}</h4>
                                <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {{ $badgeClass }}">
                                    {{ number_format($mastery, 1) }}%
                                </span>
                            </div>
                            <p class="text-sm text-gray-600 mb-2">{{ $point['kp_name'] ?? 'N/A' }}</p>
                            <div class="w-full bg-gray-200 rounded-full h-2">
                                <div class="{{ $barClass }} h-2 rounded-full"
                                     style="width: {{ $mastery }}%"></div>
                            </div>
                            <div class="mt-2 flex justify-between text-xs text-gray-500">
                                <span>答题: {{ $point['total_attempts'] ?? 0 }} 次</span>
                                <span>正确: {{ $point['correct_attempts'] ?? 0 }} 次</span>
                            </div>
                        </div>
                    @endforeach
                </div>
            @endif
        </div>

        {{-- Exercise History --}}
        @if(!empty($analysis['exercises']))
            <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
                <h3 class="text-lg font-semibold text-gray-900 mb-4">最近练习</h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">时间</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">题目</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">结果</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">用时</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            @foreach(array_slice($analysis['exercises'], 0, 10) as $exercise)
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                        {{ \Carbon\Carbon::parse($exercise->created_at)->format('m-d H:i') }}
                                    </td>
                                    <td class="px-6 py-4 text-sm text-gray-900">{{ $exercise->question_id }}</td>
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        @if($exercise->is_correct)
                                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
                                                正确
                                            </span>
                                        @else
                                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
                                                错误
                                            </span>
                                        @endif
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                        {{ $exercise->time_spent_seconds ?? 0 }}秒
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        @endif
    @endif
</div>
