<template>
  <div :class="['thinking-block', { 'thinking-block--expanded': expanded }]">
    <div class="thinking-block__header" @click="expanded = !expanded">
      <div class="thinking-block__title">
        <BulbOutlined class="thinking-block__icon" />
        <span class="thinking-block__label">思考过程</span>
        <a-spin v-if="isStreaming" size="small" class="thinking-block__spinner" />
      </div>
      <RightOutlined :class="['thinking-block__expand', { 'thinking-block__expand--open': expanded }]" />
    </div>
    <div v-if="expanded" class="thinking-block__content">
      <div class="thinking-block__text">{{ content }}</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { BulbOutlined, RightOutlined } from '@ant-design/icons-vue'
import { Spin as ASpin } from 'ant-design-vue'

defineProps<{
  content: string
  isStreaming?: boolean
}>()

const expanded = ref(false)
</script>

<style scoped>
.thinking-block {
  border: 1px solid var(--border-color-split, #f0f0f0);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  font-size: var(--font-sm, 13px);
  background: var(--bg-tertiary, #fafafa);
  margin-bottom: var(--space-2, 8px);
}

.thinking-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2, 8px) var(--space-3, 12px);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast, 0.15s);
}

.thinking-block__header:hover {
  background: rgba(0, 0, 0, 0.02);
}

.thinking-block__title {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
}

.thinking-block__icon {
  font-size: 14px;
  color: var(--color-warning, #faad14);
}

.thinking-block__label {
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-secondary, #666);
  font-size: var(--font-xs, 12px);
}

.thinking-block__spinner {
  margin-left: var(--space-1, 4px);
}

.thinking-block__expand {
  font-size: 10px;
  color: var(--text-placeholder, #bfbfbf);
  transition: transform var(--transition-fast, 0.15s);
}

.thinking-block__expand--open {
  transform: rotate(90deg);
}

.thinking-block__content {
  padding: var(--space-2, 8px) var(--space-3, 12px);
  border-top: 1px solid var(--border-color-split, #f0f0f0);
}

.thinking-block__text {
  color: var(--text-tertiary, #999);
  font-size: var(--font-xs, 12px);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}
</style>
