<div class="ui-page">
    <div class="mx-auto flex max-w-7xl flex-col gap-6 px-4 py-8">
        @include('filament.partials.page-header', [
            'kicker' => '卷子管理',
            'title' => '源卷子列表',
            'subtitle' => '基于 Markdown 拆分的卷子结构与题型区块管理',
            'actions' => view('filament.partials.density-toggle'),
        ])

        @php
            $total = \App\Models\SourcePaper::count();
            $draft = \App\Models\SourcePaper::doesntHave('parts')->count();
            $completed = \App\Models\SourcePaper::has('parts')->has('candidates')->count();
            $grading = \App\Models\SourcePaper::whereHas('candidates', fn ($q) => $q->where('status', 'pending'))->count();
        @endphp

        <div class="grid grid-cols-1 gap-4 md:grid-cols-4">
            <div class="ui-stat">
                <div class="ui-stat-label">总卷数</div>
                <div class="ui-stat-value">{{ $total }}</div>
            </div>
            <div class="ui-stat">
                <div class="ui-stat-label">草稿</div>
                <div class="ui-stat-value text-amber-600">{{ $draft }}</div>
            </div>
            <div class="ui-stat">
                <div class="ui-stat-label">已完成</div>
                <div class="ui-stat-value text-emerald-600">{{ $completed }}</div>
            </div>
            <div class="ui-stat">
                <div class="ui-stat-label">评分中</div>
                <div class="ui-stat-value text-blue-600">{{ $grading }}</div>
            </div>
        </div>

        <div class="ui-card">
            <div class="ui-card-header">
                <div>
                    <div class="ui-section-title">卷子列表</div>
                    <div class="ui-subtitle">卷名、来源文件、题量与区块信息</div>
                </div>
                <div class="ui-badge-muted">支持 Tag + Range 过滤</div>
            </div>
            <div class="ui-card-body">
                {{ $this->table }}
            </div>
        </div>
    </div>
    @include('filament.partials.loading-overlay')
</div>
