<template>
	<div class="entry-card entry-card--subagent entry-card--subagent-batch">
		<div class="entry-card__top">
			<div class="entry-card__title-group">
				<span class="entry-chip">子代理批次</span>
				<span class="entry-subtitle">{{ subagentBatchHeadline(entry) }}</span>
			</div>
		</div>
		<div class="subagent-meta">
			<span class="subagent-pill" :class="`is-${subagentState?.status || batchContent.status}`">
				{{ subagentStatusLabel(subagentState?.status || batchContent.status) }}
			</span>
			<span>{{ subagentTaskCount(entry) }} 个任务</span>
			<span>批次 {{ batchContent.batchId.slice(0, 8) }}</span>
		</div>
		<div v-if="subagentRuntimeRouteSummary(entry)" class="runtime-route-summary">
			<span class="runtime-route-summary__label">工具路由</span>
			<span>{{ subagentRuntimeRouteSummary(entry) }}</span>
		</div>
		<div v-if="subagentTaskPreview(entry).length" class="subagent-list">
			<div v-for="(task, index) in subagentTaskPreview(entry)" :key="`${entry.id}-task-${index}`" class="subagent-list__item">
				<strong>#{{ index + 1 }}</strong>
				<span>{{ task }}</span>
			</div>
		</div>
		<div v-if="subagentState?.events?.length" class="subagent-events">
			<div
				v-for="(runtimeEvent, index) in subagentState.events.slice(-4)"
				:key="`${entry.id}-event-${index}`"
				class="subagent-events__item"
			>
				<span class="subagent-events__kind">{{ subagentEventLabel(runtimeEvent.kind) }}</span>
				<pre>{{ stringifyContent(runtimeEvent.payload) }}</pre>
			</div>
		</div>
	</div>
</template>

<script lang="ts" setup>
import type {
	SessionTreeEntry,
	SessionTreeSubagentBatchContent,
	SubagentRuntimeState,
} from '../../types/index.d';

defineProps<{
	entry: SessionTreeEntry;
	batchContent: SessionTreeSubagentBatchContent;
	subagentState: SubagentRuntimeState | null;
	subagentBatchHeadline: (entry: SessionTreeEntry) => string;
	subagentStatusLabel: (status?: string) => string;
	subagentTaskCount: (entry: SessionTreeEntry) => number;
	subagentRuntimeRouteSummary: (entry: SessionTreeEntry) => string;
	subagentTaskPreview: (entry: SessionTreeEntry) => string[];
	subagentEventLabel: (kind: 'started' | 'event' | 'completed') => string;
	stringifyContent: (content: unknown) => string;
}>();

</script>
