<script setup lang="ts">
const props = defineProps<{
  text: string;
  loading?: boolean;
  defaultCollapsed?: boolean;
}>();

const collapsed = ref(props.defaultCollapsed ?? false);

const displayText = computed(() => {
  if (!props.text) return "";
  return props.text;
});
</script>

<template>
  <div class="agent-reasoning">
    <button class="reasoning-header" @click="collapsed = !collapsed">
      <Icon name="lucide:brain" class="reasoning-icon" />
      <span class="reasoning-title">思考</span>
      <span v-if="loading" class="reasoning-status">思考中…</span>
      <Icon
        :name="collapsed ? 'lucide:chevron-right' : 'lucide:chevron-down'"
        class="reasoning-toggle"
      />
    </button>
    <div v-show="!collapsed" class="reasoning-body">
      <pre>{{ displayText }}</pre>
    </div>
  </div>
</template>

<style scoped>
.agent-reasoning {
  background: var(--color-surface-soft);
  border: 1px solid var(--color-hairline);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

.reasoning-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-body);
  transition: background 0.15s;
}

.reasoning-header:hover {
  background: rgba(0, 0, 0, 0.02);
}

.reasoning-icon {
  font-size: 16px;
  color: var(--color-accent-teal);
}

.reasoning-title {
  font-weight: 500;
}

.reasoning-status {
  font-size: 12px;
  color: var(--color-muted);
  font-style: italic;
}

.reasoning-toggle {
  margin-left: auto;
  font-size: 14px;
  color: var(--color-muted);
}

.reasoning-body {
  padding: 0 14px 12px;
  max-height: 400px;
  overflow-y: auto;
}

.reasoning-body pre {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-body);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
</style>
