<template>
  <div class="page-container">
    <!-- Header 占满宽度 -->
    <header class="report-header">
      <div class="header-container">
        <div class="header-content">
          <div class="title-area">
            <div class="source-info">
              <!-- <img src="/placeholder.svg?height=40&width=40" alt="智库logo" class="source-logo"> -->
              <span class="source-name">{{ reportSummary.thinkTankName }}</span>
            </div>
            <h1 class="main-title">{{ reportSummary.name }}</h1>
            <h2 class="sub-title">{{ reportSummary.ename }}</h2>
            <div class="tags-area">
              <el-tag type="primary" size="small" v-for="tag in reportSummary.tags" :key="tag">{{ tag }}</el-tag>
            </div>
          </div>
          <div class="meta-info">
            <div class="publish-date">{{ reportSummary.times }}</div>
          </div>
        </div>
      </div>
      
      <!-- Tab切换区域 -->
      <div class="header-tabs">
        <div class="tabs-container">
          <el-tabs v-model="activeTab" class="header-tab-nav">
            <el-tab-pane label="内容摘要" name="summary">
              <template #label>
                <span class="tab-label">
                  <el-icon><Document /></el-icon>
                  内容摘要
                </span>
              </template>
            </el-tab-pane>
            <el-tab-pane label="政策追踪" name="policy">
              <template #label>
                <span class="tab-label">
                  <el-icon><Search /></el-icon>
                  政策追踪
                </span>
              </template>
            </el-tab-pane>
            <el-tab-pane label="影响分析" name="analysis">
              <template #label>
                <span class="tab-label">
                  <el-icon><TrendCharts /></el-icon>
                  影响分析
                </span>
              </template>
            </el-tab-pane>
          </el-tabs>
          
          <div class="action-buttons">
            <el-button type="plain" size="default">
              <el-icon><Link /></el-icon>
              查看官网
            </el-button>
            <el-button type="plain" size="default">
              <el-icon><Download /></el-icon>
              下载原文
            </el-button>
            <el-button type="primary" size="default">
              <el-icon><DataAnalysis /></el-icon>
              分析报告
            </el-button>
          </div>
        </div>
      </div>
    </header>

    <!-- Main Content 最大宽度1200px并居中 -->
    <main class="main-content">
      <div class="content-container">
        <!-- 根据activeTab显示不同的组件 -->
        <Overview v-if="activeTab === 'summary'" :reportSummary="reportSummary" :content="content" />
        <Policy v-else-if="activeTab === 'policy'" :policy="policy" />
        <Effect v-else-if="activeTab === 'analysis'" />
      </div>
    </main>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { 
  Document, 
  Search, 
  TrendCharts, 
  Link, 
  Download, 
  DataAnalysis
} from '@element-plus/icons-vue'
import {
  getThinkTankReportSummary,
  getThinkTankReportContent,
  getThinkTankReportPolicy
} from '@/api'
import { useRoute } from 'vue-router'

// 引入组件
import Overview from './Overview.vue'
import Policy from './Policy.vue'
import Effect from './Effect.vue'

const activeTab = ref('summary')
const route = useRoute()
const reportSummary = ref({})
const content = ref({})
const policy = ref([])

const getReportSummary = async () => {
  const { data } = await getThinkTankReportSummary({ id: route.params.id })
  console.log('getReportSummary', data)
  reportSummary.value = data
}

const getContent = async () => {
  const { data } = await getThinkTankReportContent({ id: route.params.id })
  console.log('getContent', data)
  content.value = data
}

const getPolicy = async () => {
  const { data } = await getThinkTankReportPolicy({ id: route.params.id })
  console.log('getPolicy', data)
  policy.value = data
}

onMounted(() => {
  getReportSummary()
  getContent()
  getPolicy()
})
</script>

<style scoped>
.page-container {
  background-color: #f5f7fa;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
  min-height: 100vh;
  width: 100%;
}

/* Header Styles - 占满宽度 */
.report-header {
  background-color: #fff;
  width: 100%;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.title-area {
  flex: 1;
}

.source-info {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.source-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  margin-right: 10px;
}

.source-name {
  font-size: 14px;
  color: #666;
}

.main-title {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0 0 8px 0;
  line-height: 1.4;
}

.sub-title {
  font-size: 16px;
  color: #666;
  font-weight: normal;
  margin: 0 0 15px 0;
  line-height: 1.4;
}

.tags-area {
  display: flex;
  gap: 8px;
}

.meta-info {
  text-align: right;
  color: #666;
  font-size: 14px;
}

.publish-date {
  color: #8B5CF6;
  font-weight: 500;
}

/* Header Tabs区域 */
.header-tabs {
  background-color: #fff;
  width: 100%;
  margin-top: 20px;
}

.tabs-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e4e7ed;
}

.header-tab-nav {
  flex: 1;
  margin: 0;
}

.header-tab-nav :deep(.el-tabs__header) {
  margin: 0;
  border-bottom: none;
}

.header-tab-nav :deep(.el-tabs__nav-wrap) {
  padding: 0;
}

.header-tab-nav :deep(.el-tabs__nav-wrap::after) {
  display: none;
}

.header-tab-nav :deep(.el-tabs__item) {
  font-size: 16px;
  font-weight: 500;
  color: #606266;
  padding: 16px 24px;
  border-bottom: 3px solid transparent;
  transition: all 0.3s ease;
}

.header-tab-nav :deep(.el-tabs__item:hover) {
  color: #409eff;
}

.header-tab-nav :deep(.el-tabs__item.is-active) {
  color: #409eff;
  border-bottom-color: #409eff;
  font-weight: 600;
}

.header-tab-nav :deep(.el-tabs__active-bar) {
  display: none;
}

.tab-label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.action-buttons {
  display: flex;
  align-items: center;
}

.action-buttons .el-button {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Main Content Styles - 最大宽度1200px并居中 */
.main-content {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0 24px;
}

.content-container {
  max-width: 1200px;
  width: 100%;
  border-radius: 8px;
}

/* 响应式设计 */
@media (max-width: 1240px) {
  .header-container {
    padding: 24px 20px 0;
  }
  
  .tabs-container {
    padding: 0 20px;
  }
}

@media (max-width: 1040px) {
  .content-container {
    margin: 0 20px;
  }
  
  .main-content {
    padding: 0;
  }
}

@media (max-width: 768px) {
  .header-container {
    padding: 16px 16px 0;
  }
  
  .header-content {
    flex-direction: column;
    gap: 16px;
  }
  
  .tabs-container {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
    padding: 0 16px;
  }
  
  .header-tab-nav :deep(.el-tabs__item) {
    padding: 12px 16px;
    font-size: 14px;
  }
  
  .action-buttons {
    justify-content: center;
  }
  
  .content-container {
    margin: 0 16px;
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .header-container {
    padding: 12px 12px 0;
  }
  
  .tabs-container {
    padding: 0 12px;
  }
  
  .header-tab-nav :deep(.el-tabs__item) {
    padding: 10px 12px;
    font-size: 13px;
  }
  
  .content-container {
    margin: 0 12px;
    padding: 12px;
  }
  
  .main-title {
    font-size: 20px;
  }
  
  .sub-title {
    font-size: 14px;
  }
  
  .action-buttons {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .action-buttons .el-button {
    font-size: 12px;
  }
}
</style>