<template>
  <div class="diagnosis-suggestion">
    <!-- 诊断建议区域 -->
    <div class="diagnosis-section">
      <div class="diagnosis-title">
        诊断建议：
      </div>
      <div class="diagnosis-content">
        {{ diagnosisSuggestion || '暂无诊断建议' }}
      </div>
    </div>

    <!-- 操作按钮区域 -->
    <div class="action-buttons-section">
      <a-button
        type="default"
        @click="insertToRecord"
        :disabled="!diagnosisSuggestion"
        class="action-button"
      >
        插入病历
      </a-button>
      <a-button
        type="primary"
        @click="submitAndAnalyze"
        :disabled="!diagnosisSuggestion"
        class="action-button"
      >
        提交并分析
      </a-button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// Props
const props = defineProps({
  examinationOrder: {
    type: Object,
    required: true
  }
})

// Emits
const emit = defineEmits(['insert-to-record', 'proceed-to-next', 'action3'])

// 响应式数据
const diagnosisSuggestion = ref('')

// 生成AI诊断建议（演示阶段直接生成模拟内容）
const generateDiagnosisSuggestion = () => {
  // 演示阶段直接生成模拟诊断建议
  diagnosisSuggestion.value = `根据检查结果分析，患者可能患有急性上呼吸道感染。

临床表现：发热、咳嗽、咽痛等症状。

诊断依据：
1. 症状符合上呼吸道感染表现
2. 实验室检查显示白细胞轻度升高
3. C反应蛋白轻度增高

治疗建议：
1. 抗感染治疗为主
2. 对症治疗：退热、止咳等
3. 休息、多饮水，定期复查

如症状持续不缓解或加重，请及时就医复查。`
}

// 插入病历
const insertToRecord = () => {
  if (diagnosisSuggestion.value) {
    console.log('插入病历内容：', diagnosisSuggestion.value)
    emit('insert-to-record', diagnosisSuggestion.value)

    // 触发action3事件，传递诊断建议信息
    emit('action3', {
      diagnosisSuggestion: diagnosisSuggestion.value,
      examinationOrder: props.examinationOrder
    })
  }
}

// 提交并分析（进入下一阶段）
const submitAndAnalyze = () => {
  if (diagnosisSuggestion.value) {
    emit('proceed-to-next', {
      stage: 'prescription',
      diagnosisSuggestion: diagnosisSuggestion.value,
      examinationOrder: props.examinationOrder
    })
    console.log('提交并分析，进入医嘱建议阶段')
  }
}

// 初始化
onMounted(() => {
  // 演示阶段直接生成诊断建议
  generateDiagnosisSuggestion()
})
</script>

<style scoped>
.diagnosis-suggestion {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
  overflow-y: auto;
}

.diagnosis-section {
  background: #FFFFFF;
  padding: 16px;
  border-radius: 6px;
  border: 1px solid #e8e8e8;
}

.diagnosis-title {
  color: #313131;
  font-family: 'Source Han Sans';
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 8px;
}

.diagnosis-content {
  color: #313131;
  font-family: 'Source Han Sans';
  font-weight: normal;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-line;
}

.action-buttons-section {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e8e8e8;
}

.action-button {
  width: 173px;
  height: 32px;
  border-radius: 6px;
  opacity: 1;
  background: #FFFFFF;
  box-sizing: border-box;
  border: 1px solid #9499A0;
  font-family: 'Source Han Sans';
  font-size: 16px;
  font-weight: normal;
  line-height: normal;
  text-align: center;
  color: #313131;
}
</style>
