<div>
    <div class="space-y-6">
        <!-- 顶部操作条 -->
        <div class="flex flex-wrap items-center justify-between gap-3">
            <div class="flex items-center gap-2">
                <a href="{{ route('filament.admin.resources.students.create') }}"
                   class="btn btn-primary">
                    <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                    </svg>
                    添加新学生
                </a>
                @if(!$this->isTeacher)
                <a href="{{ route('filament.admin.resources.teachers.create') }}"
                   class="btn btn-success">
                    <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                    </svg>
                    添加新老师
                </a>
                @endif
            </div>
            <div class="flex items-center gap-2">
                <a href="{{ route('filament.admin.pages.student-dashboard') }}"
                   class="btn btn-ghost">
                    <svg class="h-4 w-4" 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-2z"></path>
                    </svg>
                    学生仪表板
                </a>
                @if($this->selectedTeacherId)
                    <span class="rounded-lg bg-primary-50 px-3 py-1 text-sm text-primary-700">
                        当前筛选：{{ $this->selectedTeacherName ?? '指定老师' }}
                    </span>
                    <button
                        wire:click="resetTeacherFilter"
                        class="btn btn-xs btn-ghost text-slate-500">
                        重置筛选
                    </button>
                @endif
            </div>
        </div>

        <!-- 老师概览 -->
        <div class="space-y-4">
            <div class="flex flex-wrap items-center justify-between gap-3">
                <div>
                    <h3 class="text-lg font-semibold text-gray-900 dark:text-white">老师概览</h3>
                    <p class="text-sm text-gray-500 dark:text-gray-400">以老师为核心查看所带学生与近期动态</p>
                </div>
                <div class="flex gap-2">
                    @if(!$this->isTeacher)
                    <a href="{{ route('filament.admin.resources.teachers.index') }}"
                       class="inline-flex items-center gap-2 rounded-lg border border-gray-200 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800"
                    >
                        查看全部老师
                    </a>
                    @endif
                </div>
            </div>

            <div class="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
                @forelse($this->teacherOverview as $teacher)
                    <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm dark:border-gray-700 dark:bg-gray-900/70">
                        <div class="flex items-start justify-between gap-3">
                            <div>
                                <p class="text-lg font-semibold text-gray-900 dark:text-gray-100">
                                    {{ $teacher['teacher_name'] ?? '未命名老师' }}
                                </p>
                                <p class="text-xs text-gray-500 dark:text-gray-400">
                                    {{ $teacher['teacher_email'] ?? '未配置邮箱' }}
                                </p>
                                <p class="mt-2 text-sm text-gray-600 dark:text-gray-300">
                                    负责学生：
                                    <span class="font-semibold text-gray-900 dark:text-white">
                                        {{ $teacher['students_count'] ?? 0 }}
                                    </span>
                                </p>
                                <p class="text-xs text-gray-400 dark:text-gray-500">
                                    最近动态：
                                    {{ $teacher['latest_student_activity']
                                        ? \Illuminate\Support\Carbon::parse($teacher['latest_student_activity'])->diffForHumans()
                                        : '暂无' }}
                                </p>
                            </div>
                            <button
                                onclick="window.location.href='/admin/students?tableFilters[teacher_id][value]={{ $teacher['teacher_id'] }}'"
                                class="inline-flex items-center gap-1 rounded-lg border border-primary-200 bg-primary-50 px-3 py-1 text-xs font-semibold text-primary-700 transition hover:bg-primary-100 dark:border-primary-500/40 dark:bg-primary-500/10 dark:text-primary-300"
                            >
                                查看学生
                                <svg class="h-3.5 w-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
                                </svg>
                            </button>
                        </div>

                        <div class="mt-4">
                            <p class="text-xs font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500">所带学生</p>
                            <div class="mt-2 space-y-2">
                                @forelse($teacher['students'] as $student)
                                    <div class="flex items-center justify-between rounded-lg border border-gray-100 px-3 py-2 text-sm dark:border-gray-700">
                                        <div>
                                            <p class="font-medium text-gray-900 dark:text-gray-100">{{ $student['name'] ?? '未命名学生' }}</p>
                                            <p class="text-xs text-gray-500 dark:text-gray-400">
                                                {{ $student['grade'] ?? '未知年级' }} · {{ $student['class_name'] ?? '未知班级' }}
                                            </p>
                                        </div>
                                        <a
                                            href="{{ route('filament.admin.resources.students.view', $student['student_id']) }}"
                                            target="_blank"
                                            class="text-xs font-semibold text-primary-600 hover:text-primary-700 dark:text-primary-400"
                                        >
                                            详情
                                        </a>
                                    </div>
                                @empty
                                    <p class="text-xs text-gray-500 dark:text-gray-400">尚无学生</p>
                                @endforelse
                            </div>
                        </div>
                    </div>
                @empty
                    <div class="rounded-xl border border-dashed border-gray-300 px-4 py-6 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">
                        暂无老师数据
                    </div>
                @endforelse
            </div>
        </div>


        <!-- 数据表格 -->
        <div class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700">
            {{ $this->table }}
        </div>

        <!-- 页面说明 -->
        <div class="bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-800 p-4">
            <div class="flex items-start gap-3">
                <svg class="h-5 w-5 text-blue-600 dark:text-blue-400 mt-0.5" 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 class="text-sm text-blue-800 dark:text-blue-200">
                    <p class="font-medium mb-1">使用说明</p>
                    <ul class="list-disc list-inside space-y-1 text-blue-700 dark:text-blue-300">
                        @if(!$this->isTeacher)
                        <li>可以点击按钮添加新学生或新老师</li>
                        <li>查看老师概览了解各老师所带学生情况</li>
                        <li>支持按年级、班级、指导老师筛选学生数据</li>
                        @else
                        <li>您只能查看和管理自己指导的学生</li>
                        <li>可以点击"添加新学生"为您的班级添加学生</li>
                        <li>在老师概览中查看您的学生信息和近期动态</li>
                        <li>支持按年级、班级筛选您的学生数据</li>
                        @endif
                        <li>表格会自动刷新显示最新数据</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
