<div>
    <!-- 页面标题 -->
    <div class="flex items-center justify-between mb-6">
        <div>
            <h1 class="text-2xl font-bold">知识图谱管理</h1>
            <p class="text-sm text-base-content/60 mt-1">管理和维护数学知识图谱数据</p>
        </div>
        <div class="flex items-center gap-2">
            <x-filament::actions :actions="$this->getCachedHeaderActions()" />
        </div>
    </div>

    <!-- 统计卡片 -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
        <div class="stats shadow bg-base-100 transition-all hover:shadow-xl">
            <div class="stat">
                <div class="stat-figure text-primary">
                    <div class="avatar placeholder">
                        <div class="bg-primary/10 rounded-full w-12 h-12 flex items-center justify-center">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-6 h-6 stroke-current text-primary"><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>
                </div>
                <div class="stat-title">知识点总数</div>
                <div class="stat-value text-primary text-3xl">{{ is_array($this->knowledgePoints) ? count($this->knowledgePoints) : 0 }}</div>
                <div class="stat-desc flex items-center gap-2">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-success" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <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" />
                    </svg>
                    图谱中的活跃节点
                </div>
            </div>
        </div>

        <div class="stats shadow bg-base-100 transition-all hover:shadow-xl">
            <div class="stat">
                <div class="stat-figure text-secondary">
                    <div class="avatar placeholder">
                        <div class="bg-secondary/10 rounded-full w-12 h-12 flex items-center justify-center">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-6 h-6 stroke-current text-secondary"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"></path></svg>
                        </div>
                    </div>
                </div>
                <div class="stat-title">学段覆盖</div>
                <div class="stat-value text-secondary text-3xl">{{ is_array($this->knowledgePoints) ? collect($this->knowledgePoints)->pluck('phase')->unique()->count() : 0 }}</div>
                <div class="stat-desc flex items-center gap-2">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-info" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
                    </svg>
                    不同的教育阶段
                </div>
            </div>
        </div>

        <div class="stats shadow bg-base-100 transition-all hover:shadow-xl">
            <div class="stat">
                <div class="stat-figure text-accent">
                    <div class="avatar placeholder">
                        <div class="bg-accent/10 rounded-full w-12 h-12 flex items-center justify-center">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-6 h-6 stroke-current text-accent"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"></path></svg>
                        </div>
                    </div>
                </div>
                <div class="stat-title">学科分类</div>
                <div class="stat-value text-accent text-3xl">{{ is_array($this->knowledgePoints) ? collect($this->knowledgePoints)->pluck('category')->unique()->count() : 0 }}</div>
                <div class="stat-desc flex items-center gap-2">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-warning" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <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" />
                    </svg>
                    学科类别数量
                </div>
            </div>
        </div>
    </div>

    <!-- 数据表格 -->
    <div class="bg-base-100 rounded-box shadow-lg overflow-hidden">
        <div class="bg-base-200 px-6 py-4 border-b border-base-300">
            <div class="flex items-center justify-between">
                <h2 class="text-lg font-semibold">知识点列表</h2>
                <div class="flex items-center gap-2">
                    <div class="form-control">
                        <div class="input-group">
                            <input type="text" placeholder="搜索知识点..." class="input input-bordered input-sm w-64" />
                            <button class="btn btn-square btn-sm">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
                                </svg>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="overflow-x-auto">
            <table class="table table-zebra w-full">
                <!-- head -->
                <thead class="bg-base-200/50 text-base-content/70">
                    <tr>
                        <th class="font-semibold">ID</th>
                        <th class="font-semibold">编码 / 名称</th>
                        <th class="font-semibold">学段 / 年级</th>
                        <th class="font-semibold">分类</th>
                        <th class="font-semibold">重要性</th>
                        <th class="text-right font-semibold">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($this->knowledgePoints as $point)
                    <tr class="hover transition-all duration-200 hover:bg-base-200/50">
                        <td>
                            <div class="font-mono text-xs opacity-60 bg-base-200/50 px-2 py-1 rounded">
                                {{ $point['id'] ?? $point['kp_code'] }}
                            </div>
                        </td>
                        <td>
                            <div class="flex items-center gap-3">
                                <div class="avatar placeholder">
                                    <div class="bg-primary/10 text-primary rounded-full w-10 h-10 flex items-center justify-center">
                                        <span class="text-sm font-bold">{{ substr($point['cn_name'] ?? 'K', 0, 1) }}</span>
                                    </div>
                                </div>
                                <div>
                                    <div class="font-semibold">{{ $point['cn_name'] ?? '未知知识点' }}</div>
                                    <div class="text-xs opacity-60 font-mono flex items-center gap-1">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 20l4-16m6 16l4-16M6 9h14M4 15h14" />
                                        </svg>
                                        {{ $point['kp_code'] ?? 'N/A' }}
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="flex flex-col gap-1">
                                <span class="badge badge-sm badge-ghost gap-1">
                                    <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
                                    </svg>
                                    {{ $point['phase'] ?? '未设置' }}
                                </span>
                                @if(isset($point['grade']))
                                    <span class="text-xs opacity-70 flex items-center gap-1">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                                        </svg>
                                        {{ $point['grade'] }}年级
                                    </span>
                                @endif
                            </div>
                        </td>
                        <td>
                            <div class="flex flex-wrap gap-1">
                                <span class="badge badge-outline badge-primary badge-sm">{{ $point['category'] ?? '未分类' }}</span>
                            </div>
                        </td>
                        <td>
                            <div class="rating rating-sm rating-half">
                                @for($i = 1; $i <= 5; $i++)
                                    <input type="radio" name="rating-{{ $point['id'] ?? $point['kp_code'] }}" class="mask mask-star-2 bg-orange-400 rating-disabled" @checked(($point['importance'] ?? 0) >= $i) disabled />
                                @endfor
                            </div>
                            <div class="text-xs opacity-60 mt-1">
                                {{ $point['importance'] ?? 0 }}/5
                            </div>
                        </td>
                        <td>
                            <div class="flex items-center justify-end gap-1">
                                <div class="tooltip" data-tip="编辑">
                                    <button wire:click="edit('{{ $point['kp_code'] ?? '' }}')" class="btn btn-ghost btn-xs">
                                          <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10" />
                                          </svg>
                                          Edit
                                        </button>
                                </div>
                                <div class="tooltip" data-tip="删除">
                                    <button wire:click="delete('{{ $point['kp_code'] ?? '' }}')" class="btn btn-ghost btn-xs text-error hover:bg-error/10">
                                          <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
                                          </svg>
                                          Delete
                                        </button>
                                </div>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="text-center py-16">
                            <div class="flex flex-col items-center justify-center gap-4">
                                <div class="bg-base-200/50 rounded-full p-6">
                                    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-16 h-16 opacity-30">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5m8.25 3.25a2.25 2.25 0 100 4.5 2.25 2.25 0 000-4.5zM12 7v13" />
                                    </svg>
                                </div>
                                <div class="flex flex-col items-center gap-2">
                                    <h3 class="text-lg font-semibold opacity-80">暂无知识点数据</h3>
                                    <p class="text-sm opacity-60">请点击上方"导入图谱数据"按钮开始导入</p>
                                </div>
                            </div>
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
    <x-filament-actions::modals />
</div>
