<template>
  <div class="page-container">
    <!-- Header 占满宽度 -->
    <header class="think-tank-header">
      <div class="header-container">
        <div class="header-left">
          <el-image :src="$withFallbackImage(summary.logo, summary.name) " :alt="summary.name" class="logo" />
          <div class="info">
            <h1 class="title"> {{ summary.name  }} <span class="subtitle">{{ summary.ename }}</span></h1>
            <p class="description">
              {{ summary.describe }}
            </p>
            <div class="tags">
              <el-tag effect="light" class="custom-tag" v-for="tag in summary.tags" :key="tag">{{ tag }}</el-tag>
            </div>
          </div>
        </div>
        <div class="header-right">
          <el-button type="primary" :icon="Collection">查看报告合集</el-button>
        </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="reports"></el-tab-pane>
            <el-tab-pane label="政策追踪" name="policy"></el-tab-pane>
            <el-tab-pane label="智库百科" name="wiki"></el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </header>

    <!-- Main Content 最大宽度1000px并居中 -->
    <main class="main-content">
      <div class="content-container">
        <!-- 根据activeTab切换组件 -->
        <component :is="currentComponent" :thinkTankName="summary.name" />
      </div>
    </main>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';
import { Collection } from '@element-plus/icons-vue';
import ReportTab from './ReportTab.vue';
import PolicyTab from '@/components/PolicyTab.vue';
import DescTab from './DescTab.vue';
import { getThinkTankSummary } from '@/api';
import { useRoute } from 'vue-router';

// --- Component State ---
const activeTab = ref('reports');
const route = useRoute();

// --- Component Map ---
const componentMap = {
  reports: ReportTab,
  policy: PolicyTab,
  wiki: DescTab
};

const summary = ref({
  name: '',
  describe: '',
  ename: '',
  url: '',
  tags: []
});
// --- Computed Properties ---
const currentComponent = computed(() => {
  return componentMap[activeTab.value] || ReportTab;
});

onMounted(() => {
  getThinkTankSummary({ id: route.params.id }).then(res => {
    console.log(res.data);
    summary.value = res.data || {};
  });
});
</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 - 占满宽度 */
.think-tank-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;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

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

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

.header-tab-nav {
  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;
}

.header-left {
  display: flex;
  align-items: flex-start;
}

.logo {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  margin-right: 20px;
  flex-shrink: 0;
}

.info .title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 8px 0;
}

.info .subtitle {
  font-size: 14px;
  color: #909399;
  font-weight: normal;
  margin-left: 8px;
}

.info .description {
  font-size: 14px;
  color: #606266;
  line-height: 1.6;
  margin: 0 0 12px 0;
  max-width: 600px;
}

.custom-tag {
  background-color: #ecf5ff;
  border-color: #d9ecff;
  color: #409eff;
  margin-right: 8px;
}

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

.content-container {
  max-width: 1200px;
  width: 100%;
  background-color: #fff;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}


/* 响应式设计 */
@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 {
    flex-direction: column;
    gap: 16px;
    padding: 16px 16px 0;
  }
  
  .tabs-container {
    padding: 0 16px;
  }
  
  .header-tab-nav :deep(.el-tabs__item) {
    padding: 12px 16px;
    font-size: 14px;
  }
  
  .header-left {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .logo {
    margin-right: 0;
    margin-bottom: 12px;
  }
  
  .header-right {
    align-self: flex-start;
  }
  
  .content-container {
    margin: 0 16px;
    padding: 16px;
  }
  
  .info .description {
    max-width: none;
  }
}

@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;
  }
  
  .info .title {
    font-size: 18px;
  }
  
  .info .subtitle {
    display: block;
    margin-left: 0;
    margin-top: 4px;
  }
}
</style>