<div>
    @php
        $teacher = $this->record;
    @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\TeacherResource::getUrl('edit', ['record' => $teacher]) }}"
                           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">{{ $teacher->teacher_id }}</span>
                                <button onclick="navigator.clipboard.writeText('{{ $teacher->teacher_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">{{ $teacher->name }}</p>
                        </div>

                        {{-- 教授科目 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">教授科目</span>
                            </label>
                            <span class="badge badge-info badge-lg">{{ $teacher->subject }}</span>
                        </div>

                        {{-- 学生数量 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">管理学生数</span>
                            </label>
                            <span class="badge badge-warning badge-lg">{{ $studentsCount }}</span>
                        </div>
                    </div>

                    @if($teacher->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 whitespace-pre-wrap">{{ $teacher->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-key class="w-6 h-6" />
                        登录信息
                    </h2>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        {{-- 手机号 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">手机号（登录名）</span>
                            </label>
                            <div class="flex items-center gap-2">
                                @if($teacher->user && $teacher->user->username)
                                    <span class="font-mono">●●●●●●{{ substr($teacher->user->username, -4) }}</span>
                                    <button onclick="navigator.clipboard.writeText('{{ $teacher->user->username }}')"
                                            class="btn btn-ghost btn-xs tooltip" data-tip="复制完整号码">
                                        <x-heroicon-o-clipboard-document class="w-4 h-4" />
                                    </button>
                                @else
                                    <span class="text-base-content/40">未设置</span>
                                @endif
                            </div>
                            <label class="label">
                                <span class="label-text-alt">点击复制完整号码</span>
                            </label>
                        </div>

                        
                        {{-- 创建时间 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">创建时间</span>
                            </label>
                            <span class="badge badge-success">{{ is_string($teacher->created_at) ? $teacher->created_at : $teacher->created_at?->format('Y-m-d H:i:s') }}</span>
                        </div>

                        {{-- 最后登录 --}}
                        <div class="form-control">
                            <label class="label">
                                <span class="label-text text-base-content/60">最后登录</span>
                            </label>
                            <span class="text-sm">{{ $teacher->user?->last_login?->format('Y-m-d H:i:s') ?? '从未登录' }}</span>
                        </div>
                    </div>
                </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-chart-bar class="w-6 h-6" />
                        教学统计
                    </h2>

                    <div class="stats stats-vertical lg:stats-horizontal shadow bg-base-200 w-full">
                        <div class="stat">
                            <div class="stat-figure text-primary">
                                <x-heroicon-o-users class="w-8 h-8" />
                            </div>
                            <div class="stat-title">学生数量</div>
                            <div class="stat-value text-primary">{{ $studentsCount }}</div>
                            <div class="stat-desc">位学生在管理中</div>
                        </div>

                        <div class="stat">
                            <div class="stat-figure text-secondary">
                                <x-heroicon-o-document-text class="w-8 h-8" />
                            </div>
                            <div class="stat-title">创建考试</div>
                            <div class="stat-value text-secondary">{{ $examCount ?? 0 }}</div>
                            <div class="stat-desc">场考试已创建</div>
                        </div>
                    </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($teacher->name, 0, 1) }}</span>
                        </div>
                    </div>
                    <h3 class="text-xl font-bold">{{ $teacher->name }}</h3>
                    <p class="text-base-content/60">{{ $teacher->subject }}</p>
                    <div class="badge badge-outline mt-2">{{ $teacher->teacher_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-bolt class="w-5 h-5" />
                        快捷操作
                    </h3>
                    <div class="flex flex-col gap-2">
                        <a href="{{ \App\Filament\Resources\TeacherResource::getUrl('edit', ['record' => $teacher]) }}"
                           class="btn btn-primary gap-2">
                            <x-heroicon-o-pencil class="w-4 h-4" />
                            编辑信息
                        </a>

                        <a href="/admin/students?tableFilters[teacher_id][value]={{ $teacher->teacher_id }}"
                           class="btn btn-secondary gap-2">
                            <x-heroicon-o-users class="w-4 h-4" />
                            查看学生
                        </a>

                        <a href="{{ \App\Filament\Resources\TeacherResource::getUrl('index') }}"
                           class="btn btn-ghost gap-2">
                            <x-heroicon-o-arrow-left class="w-4 h-4" />
                            返回列表
                        </a>
                    </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-academic-cap class="w-5 h-5" />
                        教学功能
                    </h3>
                    <div class="grid grid-cols-2 gap-2">
                        <a href="{{ route('filament.admin.pages.intelligent-exam-generation') }}?teacher_id={{ $teacher->teacher_id }}"
                           class="btn btn-outline gap-2">
                            <x-heroicon-o-document-plus class="w-4 h-4" />
                            智能出卷
                        </a>

                        <a href="{{ route('filament.admin.pages.question-management') }}?teacher_id={{ $teacher->teacher_id }}"
                           class="btn btn-outline gap-2">
                            <x-heroicon-o-folder class="w-4 h-4" />
                            题库管理
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>