@php
    $skills = collect($point['skills'] ?? []);
    $parents = collect($point['parents'] ?? []);
    $metrics = [
        [
            'label' => '重要度',
            'value' => number_format((float) ($point['importance'] ?? 0), 1),
            'subtitle' => '教研侧设定的掌握权重',
        ],
        [
            'label' => '技能数量',
            'value' => $skills->count(),
            'subtitle' => '拆解后的可练单元',
        ],
        [
            'label' => '上游节点',
            'value' => $parents->count(),
            'subtitle' => '可追溯的先修知识',
        ],
    ];
@endphp

<div class="space-y-6">
    <div class="rounded-2xl bg-gradient-to-br from-primary-500/90 via-primary-500 to-primary-600 text-white shadow-lg px-6 py-5">
        <div class="flex flex-wrap gap-4 items-start justify-between">
            <div class="space-y-1">
                <p class="text-sm uppercase tracking-[0.2em] text-white/80">Knowledge Node</p>
                <h2 class="text-2xl font-semibold">
                    {{ $point['cn_name'] ?? '未命名知识点' }}
                    <span class="ml-2 text-sm font-normal text-white/70">({{ $point['kp_code'] ?? '未知编号' }})</span>
                </h2>
                <div class="flex flex-wrap gap-2 text-sm text-white/90">
                    <span class="inline-flex items-center gap-1 rounded-full bg-white/15 px-3 py-1">
                        <x-filament::icon icon="heroicon-m-banknotes" class="h-4 w-4" />
                        {{ $point['category'] ?? '未分类' }}
                    </span>
                    <span class="inline-flex items-center gap-1 rounded-full bg-white/15 px-3 py-1">
                        <x-filament::icon icon="heroicon-m-academic-cap" class="h-4 w-4" />
                        {{ $point['phase'] ?? '未知学段' }} @if($point['grade']) · {{ $point['grade'] }} 年级 @endif
                    </span>
                </div>
            </div>
            <div class="flex gap-4">
                @foreach($metrics as $metric)
                    <div class="text-right">
                        <p class="text-xs uppercase tracking-widest text-white/70">{{ $metric['label'] }}</p>
                        <p class="text-2xl font-semibold">{{ $metric['value'] }}</p>
                        <p class="text-xs text-white/80">{{ $metric['subtitle'] }}</p>
                    </div>
                @endforeach
            </div>
        </div>
    </div>

    <x-filament::section>
        <div class="grid gap-6 lg:grid-cols-2">
            <div class="space-y-4">
                <h3 class="text-sm font-semibold text-gray-500 dark:text-gray-400">知识路径</h3>
                <div class="rounded-xl border border-gray-200/80 px-4 py-3 dark:border-gray-700/70">
                    <p class="text-sm text-gray-900 dark:text-gray-100">
                        {{ $point['group_path'] ?? '尚未设置。' }}
                    </p>
                </div>

                <h3 class="text-sm font-semibold text-gray-500 dark:text-gray-400">描述 / 知识意图</h3>
                <div class="rounded-xl border border-gray-200/80 bg-gray-50 px-4 py-3 text-sm text-gray-700 dark:border-gray-700/60 dark:bg-gray-800/50 dark:text-gray-200">
                    {!! nl2br(e($point['description'] ?? '暂无描述，建议补充该知识点的课堂目标或常见错因。')) !!}
                </div>
            </div>

            <div class="space-y-4">
                <h3 class="text-sm font-semibold text-gray-500 dark:text-gray-400">先修关系</h3>
                <div class="rounded-xl border border-gray-200/80 px-4 py-4 dark:border-gray-700/70">
                    @if($parents->isEmpty())
                        <p class="text-sm text-gray-500">无父节点，可能是一级知识点。</p>
                    @else
                        <ol class="relative border-l border-dashed border-primary-200 dark:border-primary-500/40 pl-4">
                            @foreach($parents as $parent)
                                <li class="mb-4 ml-2">
                                    <span class="absolute -left-1.5 mt-1 h-3 w-3 rounded-full border-2 border-white bg-primary-400 dark:border-gray-900"></span>
                                    <p class="text-sm font-medium text-gray-900 dark:text-gray-100">{{ $parent }}</p>
                                    <p class="text-xs text-gray-500">触发该节点之前需掌握</p>
                                </li>
                            @endforeach
                        </ol>
                    @endif
                </div>
            </div>
        </div>
    </x-filament::section>

    <x-filament::section heading="技能拆解">
        @if($skills->isEmpty())
            <div class="rounded-xl border border-dashed border-gray-300 bg-white px-4 py-6 text-center text-sm text-gray-500 dark:border-gray-700 dark:bg-gray-900/40">
                该知识点尚未配置技能，建议补充规则步骤、策略和应用场景，便于题库筛选。
            </div>
        @else
            <div class="grid gap-4 md:grid-cols-2">
                @foreach($skills as $skill)
                    <div class="rounded-2xl border border-gray-200/70 bg-white/80 px-5 py-4 shadow-sm backdrop-blur-sm dark:border-gray-700/60 dark:bg-gray-900/40">
                        <div class="flex items-start justify-between">
                            <div>
                                <p class="text-sm font-semibold text-gray-900 dark:text-gray-100">
                                    {{ $skill['skill_name'] ?? '未命名技能' }}
                                </p>
                                <p class="text-xs text-gray-500">
                                    {{ $skill['skill_type'] ?? '类型未知' }}
                                </p>
                            </div>
                            <span class="inline-flex items-center gap-1 rounded-full bg-primary-50 px-2.5 py-0.5 text-xs font-medium text-primary-700 dark:bg-primary-500/10 dark:text-primary-300">
                                <x-filament::icon icon="heroicon-m-shield-check" class="h-4 w-4" />
                                难度 {{ $skill['difficulty'] ?? '-' }}
                            </span>
                        </div>
                        <p class="mt-3 text-sm text-gray-600 dark:text-gray-300 leading-relaxed">
                            {{ $skill['description'] ?? '暂无描述' }}
                        </p>
                        @if(!empty($skill['examples']))
                            <div class="mt-3 rounded-lg bg-gray-50 px-3 py-2 text-xs text-gray-500 dark:bg-gray-800/50 dark:text-gray-300">
                                <p class="font-medium text-gray-600 dark:text-gray-200">例题提示：</p>
                                {{ $skill['examples'][0]['prompt'] ?? '' }}
                            </div>
                        @endif
                    </div>
                @endforeach
            </div>
        @endif
    </x-filament::section>
</div>
