<template>
  <div class="sdgsat1-case-detail">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item><a href="/portal">首页</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/portal/sdgsat1">SDGSAT-1专区</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/portal/sdgsat1?menu=cases">数据开发与应用</a></el-breadcrumb-item>
        <el-breadcrumb-item>案例详情</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- 白色背景内容区域 -->
    <div class="content-container" v-loading="loading">
      <!-- 调试信息 -->
      <div v-if="debugInfo" class="debug-info">
        <h3>调试信息</h3>
        <pre>{{ debugInfo }}</pre>
      </div>

      <!-- 标题 -->
      <div class="case-title">
        <h1>{{ caseDetail.title }}</h1>
      </div>

      <!-- 详情内容 -->
      <div class="case-content" v-html="caseDetail.content"></div>
    </div>
  </div>
</template>

<script>
import { getCaseDetail } from '@/api/portal/sdgsat1'

export default {
  name: 'SDGSAT1CaseDetail',
  data() {
    return {
      loading: true,
      debugInfo: '',
      caseDetail: {
        title: '',
        content: ''
      }
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    async getDetail() {
      this.loading = true
      try {
        const { id } = this.$route.query
        if (!id) {
          this.$message.error('缺少案例ID')
          this.debugInfo = '缺少案例ID: ' + JSON.stringify(this.$route.query)
          this.loading = false
          return
        }
        
        this.debugInfo = '获取案例详情，ID: ' + id
        console.log('获取案例详情，ID:', id)
        
        const response = await getCaseDetail(id)
        this.debugInfo += '\nAPI响应: ' + JSON.stringify(response)
        console.log('API响应:', response)
        
        if (response.code === 200 && response.data) {
          this.caseDetail = response.data
          this.debugInfo += '\n案例详情数据: ' + JSON.stringify(this.caseDetail)
          console.log('案例详情数据:', this.caseDetail)
        } else {
          this.debugInfo += '\nAPI响应格式错误: ' + JSON.stringify(response)
          console.error('API响应格式错误:', response)
          this.$message.error('获取案例详情失败：响应格式错误')
        }
      } catch (error) {
        this.debugInfo += '\n获取案例详情失败: ' + error.message
        console.error('获取案例详情失败:', error)
        this.$message.error('获取案例详情失败：网络错误')
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.sdgsat1-case-detail {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 40px 0;
}

/* 面包屑导航 */
.breadcrumb {
  max-width: 1390px;
  margin: 0 auto 30px;
  padding: 0 30px;
}

/* 内容容器 */
.content-container {
  max-width: 1390px;
  margin: 0 auto;
  padding: 40px 60px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* 调试信息 */
.debug-info {
  background: #f5f7fa;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 30px;
  
  h3 {
    margin-top: 0;
    color: #1e3c72;
  }
  
  pre {
    margin: 0;
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
  }
}

/* 标题样式 */
.case-title {
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e0e0e0;

  h1 {
    font-size: 28px;
    font-weight: 700;
    color: #1e3c72;
    line-height: 1.4;
    margin: 0;
  }
}

/* 详情内容样式 */
.case-content {
  line-height: 1.8;
  color: #333333;

  :deep(h1),
  :deep(h2),
  :deep(h3),
  :deep(h4),
  :deep(h5),
  :deep(h6) {
    color: #1e3c72;
    margin-top: 30px;
    margin-bottom: 20px;
  }

  :deep(h1) {
    font-size: 24px;
    font-weight: 600;
  }

  :deep(h2) {
    font-size: 20px;
    font-weight: 600;
  }

  :deep(h3) {
    font-size: 18px;
    font-weight: 500;
  }

  :deep(p) {
    margin-bottom: 20px;
  }

  :deep(img) {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 20px 0;
    display: block;
  }

  :deep(ul),
  :deep(ol) {
    margin-left: 24px;
    margin-bottom: 20px;
  }

  :deep(li) {
    margin-bottom: 10px;
  }

  :deep(a) {
    color: #1e3c72;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sdgsat1-case-detail {
    padding: 20px 0;
  }

  .breadcrumb {
    margin-bottom: 20px;
    padding: 0 20px;
  }

  .content-container {
    padding: 30px 20px;
  }

  .case-title h1 {
    font-size: 24px;
  }
}
</style>