<script setup lang="ts">
import { ref } from 'vue'
import MarkdownContent from './MarkdownContent.vue'

defineProps<{
  content: string
}>()

const expanded = ref(false)
</script>

<template>
  <div class="thinking-block">
    <button class="thinking-toggle" @click="expanded = !expanded">
      <svg
        :class="['chevron', { rotated: expanded }]"
        width="12" height="12" viewBox="0 0 24 24"
        fill="none" stroke="currentColor" stroke-width="2"
      >
        <polyline points="9 18 15 12 9 6" />
      </svg>
      <span class="thinking-label">Thinking</span>
      <span class="thinking-length">{{ content.length }} chars</span>
    </button>
    <div v-if="expanded" class="thinking-content">
      <MarkdownContent :content="content" />
    </div>
  </div>
</template>

<style scoped>
.thinking-block {
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 8px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.thinking-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: rgba(168, 85, 247, 0.06);
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  text-align: left;
}

.thinking-toggle:hover {
  background: rgba(168, 85, 247, 0.1);
}

.chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.chevron.rotated {
  transform: rotate(90deg);
}

.thinking-label {
  font-weight: 500;
  color: #a855f7;
}

.thinking-length {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.thinking-content {
  padding: 0.75rem;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  border-top: 1px solid rgba(168, 85, 247, 0.15);
  background: rgba(168, 85, 247, 0.03);
}
</style>
