<template>
  <div class="overview-container">
    <el-row :gutter="20">
      <!-- 左侧内容 -->
      <el-col :span="8">
        <!-- 内容摘要 -->
        <div class="content-card">
          <div class="card-header">
            <CardTitle title="内容摘要" />
            <el-icon class="expand-icon"><ArrowRight /></el-icon>
          </div>
          <div class="card-body">
            <div class="summary-content">
              <div v-html="props.reportSummary.summary"></div>
              <el-button type="text" class="more-btn">查看更多 ></el-button>
            </div>
          </div>
        </div>

        <!-- 涉及科技领域 -->
        <div class="content-card tech-fields" style="margin-top: 20px;">
          <div class="card-header">
            <CardTitle title="涉及科技领域" />
            <el-icon class="expand-icon"><ArrowRight /></el-icon>
          </div>
          <div class="card-body">
            <div class="tech-tags">
              <el-tag type="primary" size="small" v-for="tag in props.reportSummary.researchTypes" :key="tag">{{ tag }}</el-tag>
            </div>
            <WordCloud :words="props.reportSummary.researchTypes" />
          </div>
        </div>
      </el-col>

      <!-- 右侧主要内容 -->
      <el-col :span="16">
        <div class="content-card main-content-card">
          <div class="card-header">
            <CardTitle title="主要内容" />
            <div class="content-actions">
              <el-button type="plain" size="small">核心发现</el-button>
              <el-button type="plain" size="small">政策建议</el-button>
              <el-icon class="expand-icon"><Paperclip /></el-icon>
            </div>
          </div>
          
          <div class="card-body">
            <div class="main-content-list">
              <div v-for="(item, index) in mainContentList" :key="item.id" class="content-item">
                <!-- 左侧：序号 -->
                <div class="item-number">{{ item.serialNum }}</div>
                
                <!-- 中间：标题和内容 -->
                <div class="item-main">
                  <h4 class="item-title">{{ item.content }}</h4>
                  <p class="item-content">{{ item.econtent }}</p>
                </div>
                
                <!-- 右侧：标签 -->
                <div class="item-tags">
                  <el-tag 
                    v-for="tag in item.tags" 
                    :key="tag.name" 
                    :type="tag.type" 
                    size="small"
                    class="content-tag"
                  >
                    {{ tag.name }}
                  </el-tag>
                </div>
              </div>
            </div>

            <!-- 分页 -->
            <div class="pagination-wrapper">
              <el-pagination
                v-model:current-page="currentPage"
                :page-size="pageSize"
                :total="totalElements"
                layout="prev, pager, next"
                :pager-count="5"
                small
              />
              <span class="total-info">共{{ totalElements }}项结果</span>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Paperclip } from '@element-plus/icons-vue'
import CardTitle from '@/components/CardTitle.vue'
import { mockMainContentList } from '../mockData'
import WordCloud from './WordCloud.vue'

const props = defineProps({
  reportSummary: {
    type: Object,
    required: true
  },
  content: {
    type: Object,
    required: true
  }
})
const currentPage = ref(1)
const totalElements = ref(6)
const pageSize = ref(10)

// 标签类型映射 - 根据限制方式设置不同的标签颜色
const getTagType = (tagName) => {
  const tagTypeMap = {
    '出口管制': 'danger',
    '资本管制': 'warning', 
    '技术封锁': 'danger',
    '金融制裁': 'danger',
    '对台军售': 'warning',
    '关税贸易': 'primary',
    '供应链打击': 'warning'
  }
  return tagTypeMap[tagName] || 'info'
}

// 处理接口数据的方法
const processApiData = (apiResponse) => {
  if (!apiResponse || !apiResponse.content) return []
  
  return apiResponse.content.map(item => ({
    id: item.id,
    title: item.content, // 使用content作为标题
    content: item.content, // 内容
    econtent: item.econtent,
    serialNum: item.serialNum,
    tags: item.xzfsList.map(tag => ({
      name: tag,
      type: getTagType(tag)
    }))
  }))
}

// 更新分页信息的方法
const updatePagination = (apiResponse) => {
  if (apiResponse) {
    totalElements.value = apiResponse.totalElements || 0
    pageSize.value = apiResponse.size || 10
    currentPage.value = (apiResponse.number || 0) + 1 // API返回的是0基础的页码
  }
}

const mainContentList = ref(mockMainContentList)
</script>

<style scoped>
.overview-container {
  padding: 0;
}

.content-card {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 20px;
}

.expand-icon {
  color: #999;
  cursor: pointer;
  margin-left: 10px;
}

.summary-content {
  line-height: 1.8;
  color: #666;
}

.summary-content p {
  margin-bottom: 16px;
  text-align: justify;
}

.more-btn {
  color: #409eff;
  padding: 0;
}

.tech-tags {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tech-tag {
  background: #f5f7fa;
  border: 1px solid #dcdfe6;
  color: #606266;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
}

.tech-tag.ai-chip {
  background: #fff7e6;
  border-color: #ffd591;
  color: #fa8c16;
}

.content-actions {
  display: flex;
  align-items: center;
}

.main-content-list {
  margin-bottom: 20px;
}

.content-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f0f0;
  gap: 16px;
}

.content-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.item-number {
  width: 28px;
  height: 28px;
  background: #409eff;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-title {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.4;
}

.item-content {
  margin: 0;
  line-height: 1.6;
  color: #4b5563;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-tags {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  min-width: 120px;
  align-items: flex-end;
}

.content-tag {
  font-size: 12px;
  height: 22px;
  line-height: 20px;
  padding: 0 8px;
  white-space: nowrap;
}

.pagination-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 20px;
  border-top: 1px solid #f0f0f0;
}

.total-info {
  font-size: 12px;
  color: #999;
}

.pagination-wrapper :deep(.el-pagination) {
  --el-pagination-font-size: 12px;
}

.pagination-wrapper :deep(.el-pagination .el-pager li) {
  min-width: 28px;
  height: 28px;
  line-height: 28px;
}

.pagination-wrapper :deep(.el-pagination .btn-prev),
.pagination-wrapper :deep(.el-pagination .btn-next) {
  height: 28px;
  line-height: 28px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .content-item {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 20px;
  }
  
  .item-number {
    align-self: flex-start;
  }
  
  .item-main {
    order: 2;
  }
  
  .item-tags {
    order: 3;
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: wrap;
    min-width: auto;
  }
  
  .item-title {
    font-size: 15px;
  }
  
  .item-content {
    font-size: 13px;
  }
}
</style>
