<template>
	<div class="message-with-delegated-results">
		<message-item :message="message" />
		<div class="entry-card entry-card--subagent entry-card--subagent-result">
			<div class="entry-card__top">
				<div class="entry-card__title-group">
					<span class="entry-chip">委派结果</span>
					<span class="entry-subtitle">{{ subagentResultHeadline(entry) }}</span>
				</div>
			</div>
			<div class="subagent-meta">
				<span class="subagent-pill is-completed">已完成</span>
				<span>{{ subagentResultCount(entry) }} 条结果</span>
			</div>
			<subagent-diagnostics
				:diagnostics="subagentProjectionDiagnostics(entry)"
				:display="subagentProjectionDiagnosticsDisplay(entry)"
				:summary="subagentProjectionDiagnosticsSummary(entry)"
			/>
			<subagent-task-panels
				v-if="subagentTaskPanels(entry).length"
				:entry="entry"
				:panels="subagentTaskPanels(entry)"
				:visible-task-evidence-summaries="visibleTaskEvidenceSummaries"
				:has-more-task-evidence-summaries="hasMoreTaskEvidenceSummaries"
				:toggle-subagent-evidence-expanded="toggleSubagentEvidenceExpanded"
				:task-panel-scope-key="taskPanelScopeKey"
				:is-subagent-evidence-expanded="isSubagentEvidenceExpanded"
				:evidence-kind-label="evidenceKindLabel"
				:subagent-tool-execution-count-label="subagentToolExecutionCountLabel"
				:subagent-tool-execution-label="subagentToolExecutionLabel"
				:subagent-tool-execution-meta="subagentToolExecutionMeta"
				:is-tool-execution-block-collapsed="isToolExecutionBlockCollapsed"
				:stringify-content="stringifyContent"
				:has-long-tool-execution-block="hasLongToolExecutionBlock"
				:toggle-tool-execution-block="toggleToolExecutionBlock"
				:is-tool-execution-block-expanded="isToolExecutionBlockExpanded"
				:visible-task-process-events="visibleTaskProcessEvents"
				:process-event-label="processEventLabel"
				:format-timestamp="formatTimestamp"
				:process-event-detail="processEventDetail"
				:process-event-payload-preview="processEventPayloadPreview"
				:is-process-event-payload-collapsed="isProcessEventPayloadCollapsed"
				:has-process-event-long-payload="hasProcessEventLongPayload"
				:toggle-process-event-payload-expanded="toggleProcessEventPayloadExpanded"
				:is-process-event-payload-expanded="isProcessEventPayloadExpanded"
				:has-more-task-process-events="hasMoreTaskProcessEvents"
				:is-subagent-process-expanded="isSubagentProcessExpanded"
				:toggle-subagent-process-expanded="toggleSubagentProcessExpanded"
			/>
		</div>
	</div>
</template>

<script lang="ts" setup>
import MessageItem from '../message-item.vue';
import SubagentDiagnostics from './SubagentDiagnostics.vue';
import SubagentTaskPanels from './SubagentTaskPanels.vue';
import type {
	ChatMessage,
	SessionTreeEntry,
	SubagentEvidenceSummary,
	SubagentProcessEvent,
	SubagentProjectionDiagnostics,
	SubagentTaskPanel,
	SubagentToolExecution,
} from '../../types/index.d';

type DiagnosticsDisplay = {
	projectionPathLabel: string;
	selectedSourceLabel: string;
	inputSourcesLabel: string;
	ignoredSourcesLabel: string;
};

defineProps<{
	entry: SessionTreeEntry;
	message: ChatMessage;
	subagentResultHeadline: (entry: SessionTreeEntry) => string;
	subagentResultCount: (entry: SessionTreeEntry) => number;
	subagentProjectionDiagnostics: (entry: SessionTreeEntry) => SubagentProjectionDiagnostics | null;
	subagentProjectionDiagnosticsDisplay: (entry: SessionTreeEntry) => DiagnosticsDisplay;
	subagentProjectionDiagnosticsSummary: (entry: SessionTreeEntry) => string;
	subagentTaskPanels: (entry: SessionTreeEntry) => SubagentTaskPanel[];
	visibleTaskEvidenceSummaries: (entry: SessionTreeEntry, panel: SubagentTaskPanel) => SubagentEvidenceSummary[];
	hasMoreTaskEvidenceSummaries: (panel: SubagentTaskPanel) => boolean;
	toggleSubagentEvidenceExpanded: (entryId: string) => void;
	taskPanelScopeKey: (entryId: string, panel: SubagentTaskPanel) => string;
	isSubagentEvidenceExpanded: (entryId: string) => boolean;
	evidenceKindLabel: (kind?: string) => string;
	subagentToolExecutionCountLabel: (panel: SubagentTaskPanel) => string;
	subagentToolExecutionLabel: (execution: SubagentToolExecution) => string;
	subagentToolExecutionMeta: (execution: SubagentToolExecution) => string[];
	isToolExecutionBlockCollapsed: (execution: SubagentToolExecution, field: 'args' | 'result' | 'error') => boolean;
	stringifyContent: (content: unknown) => string;
	hasLongToolExecutionBlock: (execution: SubagentToolExecution, field: 'args' | 'result' | 'error') => boolean;
	toggleToolExecutionBlock: (execution: SubagentToolExecution, field: 'args' | 'result' | 'error') => void;
	isToolExecutionBlockExpanded: (execution: SubagentToolExecution, field: 'args' | 'result' | 'error') => boolean;
	visibleTaskProcessEvents: (entry: SessionTreeEntry, panel: SubagentTaskPanel) => SubagentProcessEvent[];
	processEventLabel: (event: SubagentProcessEvent) => string;
	formatTimestamp: (timestamp?: string) => string;
	processEventDetail: (event: SubagentProcessEvent) => string;
	processEventPayloadPreview: (event: SubagentProcessEvent) => string;
	isProcessEventPayloadCollapsed: (entryId: string, index: number, event: SubagentProcessEvent) => boolean;
	hasProcessEventLongPayload: (event: SubagentProcessEvent) => boolean;
	toggleProcessEventPayloadExpanded: (entryId: string, index: number, event: SubagentProcessEvent) => void;
	isProcessEventPayloadExpanded: (entryId: string, index: number, event: SubagentProcessEvent) => boolean;
	hasMoreTaskProcessEvents: (panel: SubagentTaskPanel) => boolean;
	isSubagentProcessExpanded: (entryId: string) => boolean;
	toggleSubagentProcessExpanded: (entryId: string) => void;
}>();

</script>
