<div>
    @php
        $student = $this->record;
        $teacher = $student->teacher;
        $currentUser = auth()->user();
        $isTeacher = $currentUser?->isTeacher() ?? false;
    @endphp

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        {{-- 左侧主信息 --}}
        <div class="lg:col-span-2 space-y-6">
            {{-- 基本信息卡片 --}}
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <div class="flex items-center justify-between mb-6">
                        <h2 class="card-title text-xl">基本信息</h2>
                        <a href="{{ \App\Filament\Resources\StudentResource::getUrl('edit', ['record' => $student]) }}"
                           class="btn btn-sm btn-outline btn-primary gap-2">
                            <x-heroicon-o-pencil-square class="w-4 h-4" />
                            编辑
                        </a>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        {{-- 学生ID --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">学生ID</span>
                            </label>
                            <div class="flex items-center gap-2">
                                <span class="badge badge-primary badge-lg font-mono">{{ $student->student_id }}</span>
                                <button onclick="navigator.clipboard.writeText('{{ $student->student_id }}')"
                                        class="btn btn-ghost btn-xs tooltip" data-tip="复制">
                                    <x-heroicon-o-clipboard-document class="w-4 h-4" />
                                </button>
                            </div>
                        </div>

                        {{-- 姓名 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">姓名</span>
                            </label>
                            <p class="text-lg font-semibold">{{ $student->name }}</p>
                        </div>

                        {{-- 年级 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">年级</span>
                            </label>
                            <span class="badge badge-success badge-lg">{{ $student->grade }}</span>
                        </div>

                        {{-- 班级 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">班级</span>
                            </label>
                            <p class="text-base">{{ $student->class_name ?: '未分配' }}</p>
                        </div>

                        @if(!$isTeacher && $teacher)
                        {{-- 指导老师 --}}
                        <div class="form-control md:col-span-2">
                            <label class="label">
                                <span class="label-text text-base-content/60">指导老师</span>
                            </label>
                            <div class="flex items-center gap-3">
                                <div class="avatar placeholder">
                                    <div class="bg-primary text-primary-content rounded-full w-10">
                                        <span>{{ mb_substr($teacher->user?->full_name ?? $teacher->name ?? '?', 0, 1) }}</span>
                                    </div>
                                </div>
                                <div>
                                    <p class="font-medium">{{ $teacher->user?->full_name ?? $teacher->name }}</p>
                                    <p class="text-sm text-base-content/60">ID: {{ $teacher->teacher_id }}</p>
                                </div>
                            </div>
                        </div>
                        @endif
                    </div>

                    @if($student->remark)
                    <div class="divider"></div>
                    <div class="form-control">
                        <label class="label">
                            <span class="label-text text-base-content/60">备注</span>
                        </label>
                        <div class="bg-base-200 rounded-lg p-4">
                            <p class="text-sm">{{ $student->remark }}</p>
                        </div>
                    </div>
                    @endif
                </div>
            </div>

            {{-- 功能操作卡片 --}}
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h2 class="card-title text-xl mb-4">
                        <x-heroicon-o-squares-2x2 class="w-6 h-6" />
                        功能操作
                    </h2>

                    <div class="grid grid-cols-3 gap-4">
                        {{-- 智能出卷 --}}
                        <a href="{{ route('filament.admin.pages.intelligent-exam-generation') }}?student_id={{ $student->student_id }}"
                           class="card bg-gradient-to-br from-primary/10 to-primary/5 hover:from-primary/20 hover:to-primary/10 transition-all cursor-pointer border border-primary/20">
                            <div class="card-body items-center text-center p-4">
                                <div class="w-12 h-12 rounded-full bg-primary/20 flex items-center justify-center mb-2">
                                    <x-heroicon-o-document-plus class="w-6 h-6 text-primary" />
                                </div>
                                <span class="font-medium text-sm">智能出卷</span>
                            </div>
                        </a>

                        {{-- 学生仪表板 --}}
                        <a href="{{ route('filament.admin.pages.student-dashboard') }}?student_id={{ $student->student_id }}"
                           class="card bg-gradient-to-br from-secondary/10 to-secondary/5 hover:from-secondary/20 hover:to-secondary/10 transition-all cursor-pointer border border-secondary/20">
                            <div class="card-body items-center text-center p-4">
                                <div class="w-12 h-12 rounded-full bg-secondary/20 flex items-center justify-center mb-2">
                                    <x-heroicon-o-chart-bar class="w-6 h-6 text-secondary" />
                                </div>
                                <span class="font-medium text-sm">学习报告</span>
                            </div>
                        </a>

                        {{-- 错题本 --}}
                        <a href="{{ route('filament.admin.pages.mistake-book') }}?student_id={{ $student->student_id }}"
                           class="card bg-gradient-to-br from-error/10 to-error/5 hover:from-error/20 hover:to-error/10 transition-all cursor-pointer border border-error/20">
                            <div class="card-body items-center text-center p-4">
                                <div class="w-12 h-12 rounded-full bg-error/20 flex items-center justify-center mb-2">
                                    <x-heroicon-o-book-open class="w-6 h-6 text-error" />
                                </div>
                                <span class="font-medium text-sm">错题本</span>
                            </div>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        {{-- 右侧信息 --}}
        <div class="lg:col-span-1 space-y-6">
            {{-- 头像卡片 --}}
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body items-center text-center">
                    <div class="avatar placeholder mb-4">
                        <div class="bg-gradient-to-br from-primary to-secondary text-primary-content rounded-full w-24">
                            <span class="text-3xl">{{ mb_substr($student->name, 0, 1) }}</span>
                        </div>
                    </div>
                    <h3 class="text-xl font-bold">{{ $student->name }}</h3>
                    <p class="text-base-content/60">{{ $student->grade }} {{ $student->class_name }}</p>
                    <div class="badge badge-outline mt-2">{{ $student->student_id }}</div>
                </div>
            </div>

            {{-- 时间信息卡片 --}}
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h3 class="card-title text-base mb-4">
                        <x-heroicon-o-clock class="w-5 h-5" />
                        时间信息
                    </h3>
                    <div class="space-y-4">
                        <div class="flex justify-between items-center">
                            <span class="text-base-content/60 text-sm">创建时间</span>
                            <span class="text-sm">{{ $student->created_at?->format('Y-m-d H:i') ?? '-' }}</span>
                        </div>
                        <div class="flex justify-between items-center">
                            <span class="text-base-content/60 text-sm">更新时间</span>
                            <span class="text-sm">{{ $student->updated_at?->format('Y-m-d H:i') ?? '-' }}</span>
                        </div>
                    </div>
                </div>
            </div>

            {{-- 快捷操作 --}}
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h3 class="card-title text-base mb-4">
                        <x-heroicon-o-bolt class="w-5 h-5" />
                        快捷导航
                    </h3>
                    <div class="flex flex-col gap-2">
                        <a href="{{ \App\Filament\Resources\StudentResource::getUrl('index') }}"
                           class="btn btn-ghost btn-sm justify-start gap-2">
                            <x-heroicon-o-arrow-left class="w-4 h-4" />
                            返回列表
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
