{{-- 学习分析组件 --}}
<div class="space-y-6">
    @if(!empty($analysisData) || !empty($paperAnalysisData))
        {{-- 本次试卷分析结果 --}}
        @if(!empty($paperAnalysisData) && isset($paperAnalysisData['question_results']))
        <div class="card bg-base-100 shadow-xl border-2 border-primary">
            <div class="card-body">
                <h2 class="card-title text-2xl mb-4">
                    <svg class="w-6 h-6" 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>
                    本次试卷分析
                </h2>

                <div class="divider my-2"></div>

                {{-- 分析摘要 --}}
                @if(isset($paperAnalysisData['summary']))
                <div class="stats stats-vertical lg:stats-horizontal shadow w-full mb-6">
                    <div class="stat">
                        <div class="stat-title">题目总数</div>
                        <div class="stat-value text-primary">{{ $paperAnalysisData['summary']['question_count'] ?? 0 }}</div>
                    </div>
                    <div class="stat">
                        <div class="stat-title">分析成功</div>
                        <div class="stat-value text-success">{{ $paperAnalysisData['summary']['successful_analyses'] ?? 0 }}</div>
                    </div>
                    <div class="stat">
                        <div class="stat-title">掌握度更新</div>
                        <div class="stat-value text-info">{{ $paperAnalysisData['summary']['mastery_updates'] ?? 0 }}</div>
                    </div>
                </div>
                @endif

                {{-- 题目分析详情 --}}
                <div class="space-y-4">
                    @foreach($paperAnalysisData['question_results'] as $result)
                        <div class="card bg-base-200 border {{ $result['correct'] ? 'border-success' : 'border-error' }}">
                            <div class="card-body">
                                <div class="flex items-start justify-between">
                                    <div class="flex-1">
                                        <div class="flex items-center gap-2 mb-3">
                                            <span class="badge badge-primary badge-lg">第 {{ $result['question_number'] }} 题</span>
                                            <span class="badge badge-outline">{{ $result['kp_code'] }}</span>
                                            
                                            @if($result['correct'])
                                                <div class="badge badge-success gap-1">
                                                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                                                    </svg>
                                                    正确
                                                </div>
                                            @else
                                                <div class="badge badge-error gap-1">
                                                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
                                                    </svg>
                                                    错误
                                                </div>
                                            @endif
                                            
                                            <span class="ml-auto text-2xl font-bold">{{ $result['score'] }}<span class="text-sm opacity-70">/{{ $result['full_score'] }}</span></span>
                                        </div>

                                        @if(!$result['correct'])
                                            <div class="divider my-2"></div>
                                            
                                            {{-- 错误分析 --}}
                                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                                <div class="alert alert-warning">
                                                    <svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
                                                    </svg>
                                                    <div>
                                                        <div class="font-semibold">错误类型</div>
                                                        <div class="text-sm">{{ $result['mistake_type'] ?? '未知' }} - {{ $result['mistake_category'] ?? '' }}</div>
                                                    </div>
                                                </div>
                                                
                                                <div class="alert alert-info">
                                                    <svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                                    </svg>
                                                    <div>
                                                        <div class="font-semibold">错误原因</div>
                                                        <div class="text-sm">{{ $result['reason'] ?? '' }}</div>
                                                    </div>
                                                </div>
                                            </div>

                                            {{-- 学习建议 --}}
                                            @if(isset($result['suggestions']) && $result['suggestions'])
                                            <div class="alert alert-success mt-3">
                                                <svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
                                                </svg>
                                                <div>
                                                    <div class="font-semibold">学习建议</div>
                                                    <div class="text-sm">{{ $result['suggestions'] }}</div>
                                                </div>
                                            </div>
                                            @endif

                                            {{-- 下一步措施 --}}
                                            @if(isset($result['next_steps']) && is_array($result['next_steps']) && count($result['next_steps']) > 0)
                                            <div class="mt-3">
                                                <div class="font-semibold mb-2">下一步措施:</div>
                                                <ul class="list-disc list-inside space-y-1">
                                                    @foreach($result['next_steps'] as $step)
                                                        <li class="text-sm">{{ $step }}</li>
                                                    @endforeach
                                                </ul>
                                            </div>
                                            @endif
                                        @else
                                            {{-- 正确答案的鼓励 --}}
                                            <div class="alert alert-success">
                                                <svg class="w-5 h-5 shrink-0" 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>
                                                <span>{{ $result['suggestions'] ?? '答案完全正确，掌握度很好！' }}</span>
                                            </div>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
        @endif

        {{-- 整体掌握度分析 --}}
        @if(!empty($analysisData) && $recordData['status'] === 'completed')
            {{-- 整体掌握度 --}}
            @if(isset($analysisData['overall_mastery']))
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h2 class="card-title text-2xl mb-4">整体掌握度评估</h2>
                    <div class="divider my-2"></div>
                    <div class="stats stats-vertical lg:stats-horizontal shadow w-full">
                        <div class="stat">
                            <div class="stat-title">掌握度评分</div>
                            <div class="stat-value text-primary">{{ number_format($analysisData['overall_mastery'] * 100, 1) }}%</div>
                            <div class="stat-desc">
                                @if($analysisData['overall_mastery'] >= 0.8)
                                    优秀
                                @elseif($analysisData['overall_mastery'] >= 0.6)
                                    良好
                                @else
                                    需加强
                                @endif
                            </div>
                        </div>
                        <div class="stat">
                            <div class="stat-title">薄弱知识点</div>
                            <div class="stat-value text-warning">{{ count($analysisData['weak_areas'] ?? []) }} 个</div>
                            <div class="stat-desc">需要重点关注</div>
                        </div>
                        <div class="stat">
                            <div class="stat-title">知识点总数</div>
                            <div class="stat-value">{{ $analysisData['total_knowledge_points'] ?? 0 }}</div>
                            <div class="stat-desc">已评估</div>
                        </div>
                    </div>
                </div>
            </div>
            @endif

            {{-- 知识点掌握情况 --}}
            @if(!empty($analysisData['knowledge_points']))
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h2 class="card-title text-xl mb-4">知识点掌握情况</h2>
                    <div class="divider my-2"></div>
                    <div class="overflow-x-auto">
                        <table class="table table-zebra">
                            <thead>
                                <tr>
                                    <th>知识点</th>
                                    <th>掌握度</th>
                                    <th>答题次数</th>
                                    <th>正确率</th>
                                    <th>状态</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($analysisData['knowledge_points'] as $kp)
                                    <tr>
                                        <td>
                                            <div class="font-medium">{{ $kp['name'] ?? $kp['kp_code'] }}</div>
                                            <div class="text-xs opacity-70">{{ $kp['kp_code'] }}</div>
                                        </td>
                                        <td>
                                            <div class="flex items-center gap-2">
                                                <progress 
                                                    class="progress {{ $kp['mastery'] >= 0.7 ? 'progress-success' : ($kp['mastery'] >= 0.4 ? 'progress-warning' : 'progress-error') }} w-20" 
                                                    value="{{ $kp['mastery'] * 100 }}" 
                                                    max="100"
                                                ></progress>
                                                <span class="text-sm">{{ number_format($kp['mastery'] * 100, 1) }}%</span>
                                            </div>
                                        </td>
                                        <td>{{ $kp['total_attempts'] ?? 0 }} 次</td>
                                        <td>{{ number_format(($kp['accuracy_rate'] ?? 0) * 100, 1) }}%</td>
                                        <td>
                                            @if($kp['mastery'] >= 0.7)
                                                <span class="badge badge-success badge-sm">良好</span>
                                            @elseif($kp['mastery'] >= 0.4)
                                                <span class="badge badge-warning badge-sm">一般</span>
                                            @else
                                                <span class="badge badge-error badge-sm">薄弱</span>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            @endif

            {{-- 学习建议 --}}
            @if(!empty($analysisData['recommendations']))
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h2 class="card-title text-xl mb-4">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
                        </svg>
                        学习建议
                    </h2>
                    <div class="divider my-2"></div>
                    <div class="space-y-3">
                        @foreach($analysisData['recommendations'] as $recommendation)
                            <div class="alert alert-info">
                                <svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                </svg>
                                <span>{{ $recommendation }}</span>
                            </div>
                        @endforeach
                    </div>
                </div>
            </div>
            @endif
        @endif
    @else
        <div class="card bg-base-100 shadow-xl">
            <div class="card-body">
                <div class="text-center py-12">
                    <svg class="w-16 h-16 mx-auto mb-4 opacity-30" 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="text-lg font-medium opacity-70">暂无学习分析数据</p>
                    <p class="text-sm mt-2 opacity-50">完成评分后将生成学习分析报告</p>
                </div>
            </div>
        </div>
    @endif
</div>
