<template>
  <div class="page-container">
    <!-- Header 占满宽度 -->
    <header class="report-header">
      <div class="header-container">
        <div class="header-content">
          <!-- 左侧封面图片 -->
          <div class="cover-image-area">
            <div class="book-cover">
              <div class="cover-title">{{ reportSummary.name }}</div>
              <div class="cover-subtitle">{{ reportSummary.ename }}</div>
              <div class="cover-globe"></div>
            </div>
          </div>
          
          <!-- 中间标题区域 -->
          <div class="title-area">
            <h1 class="main-title">{{ reportSummary.name }}</h1>
            <h2 class="sub-title">{{ reportSummary.ename }}</h2>
            <div class="tags-area">
              <span 
                v-for="(tag, index) in reportSummary.tags" 
                :key="tag" 
                class="tag-item"
                :class="{ 'tag-primary': index % 2 === 0, 'tag-danger': index % 2 === 1 }"
              >
                {{ tag }}
              </span>
            </div>
          </div>
          
          <!-- 右侧元信息 -->
          <div class="meta-info">
            <div class="source-info">
              <el-icon class="source-icon"><TrendCharts /></el-icon>
              <span class="source-name">{{ reportSummary.thinkTankName }}</span>
            </div>
            <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 { mockContent } from '../mockData'

// 引入组件
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
  reportSummary.value = {
    thinkTankName: '兰德公司',
    name: '美国经济竞争分析',
    ename: 'Analysis of US Economic Competition',
    tags: ['美国', '经济竞争', '政治竞争', '军事竞争'],
    times: '2025-11-27',
    summary: mockContent,
    researchTypes: ['人工智能',
                  '军事与安全',
                  '半导体与高科技',
                  '经济与贸易',
                  '国际规则与多边体系',
                  '地缘政治'],
  }
}

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%;
  --max-width: 1650px;
}

/* 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: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px 0;
}

.header-content {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

/* 左侧封面图片区域 */
.cover-image-area {
  flex-shrink: 0;
}

.book-cover {
  width: 88px;
  height: 115px;
  background: linear-gradient(135deg, #d4a574 0%, #c8965f 100%);
  border-radius: 4px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.cover-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cover-subtitle {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.2;
  margin-top: 4px;
}

.cover-globe {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
  border-radius: 50%;
  opacity: 0.6;
}

.cover-globe::before {
  content: '';
  position: absolute;
  top: 20%;
  left: 30%;
  width: 40%;
  height: 30%;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

.cover-globe::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 20%;
  width: 35%;
  height: 25%;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

/* 中间标题区域 */
.title-area {
  flex: 1;
  min-width: 0;
}

.main-title {
  font-size: 28px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 10px 0;
  line-height: 1.4;
}

.sub-title {
  font-size: 16px;
  color: #7f8c8d;
  font-weight: 400;
  margin: 0 0 16px 0;
  line-height: 1.5;
}

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

.tag-item {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid;
  background: transparent;
}

.tag-primary {
  color: #409eff;
  border-color: #409eff;
}

.tag-danger {
  color: #f56c6c;
  border-color: #f56c6c;
}

/* 右侧元信息 */
.meta-info {
  flex-shrink: 0;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.source-info {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #606266;
}

.source-icon {
  font-size: 18px;
  color: #8B5CF6;
}

.source-name {
  font-size: 14px;
  color: #606266;
  font-weight: 500;
}

.publish-date {
  color: #606266;
  font-size: 14px;
  font-weight: 400;
}

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

.tabs-container {
  max-width: var(--max-width);
  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: var(--max-width);
  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: 20px 16px 0;
  }
  
  .header-content {
    flex-direction: column;
    gap: 20px;
  }
  
  .cover-image-area {
    align-self: center;
  }
  
  .book-cover {
    width: 100px;
    height: 140px;
  }
  
  .title-area {
    text-align: center;
  }
  
  .main-title {
    font-size: 22px;
  }
  
  .sub-title {
    font-size: 14px;
  }
  
  .tags-area {
    justify-content: center;
  }
  
  .meta-info {
    align-items: center;
    text-align: center;
  }
  
  .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: 16px 12px 0;
  }
  
  .book-cover {
    width: 80px;
    height: 120px;
    padding: 12px 8px;
  }
  
  .cover-title {
    font-size: 11px;
  }
  
  .cover-subtitle {
    font-size: 8px;
  }
  
  .cover-globe {
    width: 45px;
    height: 45px;
    bottom: 15px;
  }
  
  .main-title {
    font-size: 20px;
  }
  
  .sub-title {
    font-size: 13px;
  }
  
  .tag-item {
    font-size: 12px;
    padding: 3px 10px;
  }
  
  .source-icon {
    font-size: 16px;
  }
  
  .source-name {
    font-size: 13px;
  }
  
  .publish-date {
    font-size: 13px;
  }
  
  .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;
  }
  
  .action-buttons {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .action-buttons .el-button {
    font-size: 12px;
  }
}
</style>