<script setup lang="ts">
import type { MessagePart } from "~/types/chat";

const props = defineProps<{
  parts: MessagePart[];
  isLoading: boolean;
}>();

const emit = defineEmits<{
  approve: [toolCallId: string, approved: boolean];
}>();
</script>

<template>
  <template v-for="part in parts" :key="part.id">
    <AgentReasoningBlock
      v-if="part.type === 'reasoning'"
      :text="part.text || ''"
      :loading="part.reasoningLoading"
    />

    <AgentToolCallBlock
      v-else-if="part.type === 'tool-call'"
      :part="part"
      :is-loading="isLoading"
      @approve="(id, approved) => emit('approve', id, approved)"
    />

    <AgentToolResultBlock
      v-else-if="part.type === 'tool-result' && part.result !== undefined"
      :result="part.result"
    />

    <AgentMarkdown
      v-else-if="part.type === 'text' && part.text"
      :text="part.text"
    />
  </template>
</template>
