<script setup lang="ts">
import type { ChatTimelineStatusItem } from './types';

import { computed } from 'vue';

import { KnowledgeIcon, SkillIcon } from '@easyflow/icons';

import { ChatEventLabel } from '../chat-status';

defineOptions({
  name: 'ChatTimelineStatusRow',
});

const props = defineProps<{
  item: ChatTimelineStatusItem;
}>();

const isRunning = computed(() => props.item.status === 'running');
const isSeparator = computed(() => props.item.presentation === 'separator');
</script>

<template>
  <div
    class="chat-timeline-status-row"
    :class="[
      `is-${item.status}`,
      `is-${item.tone || 'muted'}`,
      { 'is-separator': isSeparator },
    ]"
    :aria-label="item.label"
    :title="item.label"
  >
    <span
      v-if="isSeparator"
      class="chat-timeline-status-row__line"
      aria-hidden="true"
    ></span>
    <ChatEventLabel
      class="chat-timeline-status-row__content"
      :active="isRunning"
      :text="item.label"
    >
      <template #icon>
        <SkillIcon
          v-if="item.icon === 'skill'"
          class="chat-timeline-status-row__icon"
          aria-hidden="true"
        />
        <KnowledgeIcon
          v-else-if="item.icon !== 'none'"
          class="chat-timeline-status-row__icon"
          aria-hidden="true"
        />
      </template>
    </ChatEventLabel>
    <span
      v-if="isSeparator"
      class="chat-timeline-status-row__line"
      aria-hidden="true"
    ></span>
  </div>
</template>

<style scoped>
.chat-timeline-status-row {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  padding: 2px 0;
  color: var(--el-text-color-placeholder);
}

.chat-timeline-status-row__content {
  min-width: 0;
  max-width: 100%;
}

.chat-timeline-status-row__content :deep(.chat-event-label) {
  align-items: flex-start;
  white-space: normal;
}

.chat-timeline-status-row__content :deep(.chat-event-label__icon) {
  margin-top: var(--space-1);
}

.chat-timeline-status-row__content :deep(.chat-shimmer-text) {
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  white-space: normal;
}

.chat-timeline-status-row__icon {
  width: 14px;
  height: 14px;
  color: var(--el-text-color-placeholder);
}

.chat-timeline-status-row.is-cancelled,
.chat-timeline-status-row.is-done,
.chat-timeline-status-row.is-error,
.chat-timeline-status-row.is-incomplete {
  opacity: 0.84;
}

.chat-timeline-status-row.is-error,
.chat-timeline-status-row.is-danger {
  color: var(--el-color-danger);
}

.chat-timeline-status-row.is-error .chat-timeline-status-row__icon,
.chat-timeline-status-row.is-danger .chat-timeline-status-row__icon {
  color: var(--el-color-danger);
}

.chat-timeline-status-row.is-error :deep(.chat-event-label),
.chat-timeline-status-row.is-danger :deep(.chat-event-label),
.chat-timeline-status-row.is-error :deep(.chat-shimmer-text),
.chat-timeline-status-row.is-danger :deep(.chat-shimmer-text) {
  color: var(--el-color-danger);
}

.chat-timeline-status-row.is-separator {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  max-width: 100%;
}

.chat-timeline-status-row.is-separator .chat-timeline-status-row__line {
  flex: 1 1 auto;
  min-width: 24px;
  height: 1px;
  background: var(--el-border-color-lighter);
}
</style>
