<template>
  <div class="thinktank-page">
    <div class="page-header">
      <h1 class="page-title">智库观察</h1>
      <p class="page-desc">汇聚专家智慧，洞察发展趋势，提供决策支持</p>
    </div>

    <!-- 分类标签 -->
    <div class="category-tabs">
      <a-radio-group v-model:value="activeType" button-style="solid" @change="handleTypeChange">
        <a-radio-button value="">全部</a-radio-button>
        <a-radio-button value="intro">智库介绍</a-radio-button>
        <a-radio-button value="view">智库视角</a-radio-button>
      </a-radio-group>
    </div>

    <!-- 内容 -->
    <div class="content-grid">
      <div v-for="item in items" :key="item.id" class="content-card" @click="handleView(item)">
        <div class="card-image" v-if="item.image">
          <img :src="item.image" :alt="item.title" />
        </div>
        <div class="card-body">
          <h3 class="card-title">{{ item.title }}</h3>
          <p class="card-overview">{{ item.overview }}</p>
          <div class="card-meta">
            <span>{{ item.publishTime }}</span>
          </div>
        </div>
      </div>

      <div v-if="loading" class="loading-placeholder">
        <a-spin size="large" />
      </div>

      <div v-if="!loading && items.length === 0" class="empty-placeholder">
        <a-empty description="暂无内容" />
      </div>
    </div>

    <!-- 分页 -->
    <div class="pagination-wrap" v-if="total > pageSize">
      <a-pagination
        v-model:current="currentPage"
        :total="total"
        :page-size="pageSize"
        @change="handlePageChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { message } from 'ant-design-vue'

useHead({ title: '智库观察 - 决策咨询网' })

const router = useRouter()

const activeType = ref((useRoute().query.type as string) || '')
const currentPage = ref(1)
const pageSize = ref(9)
const total = ref(0)
const loading = ref(false)
const items = ref<any[]>([])

async function loadItems() {
  loading.value = true
  try {
    // TODO: 接入实际API
  } catch (e: any) {
    message.error('加载失败')
  } finally {
    loading.value = false
  }
}

function handleTypeChange() {
  currentPage.value = 1
  loadItems()
}

function handlePageChange(page: number) {
  currentPage.value = page
  loadItems()
}

function handleView(item: any) {
  router.push(`/think-tank/${item.id}`)
}

onMounted(() => {
  loadItems()
})
</script>

<style scoped>
.thinktank-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  color: #1f2937;
  margin: 0 0 12px;
}

.page-desc {
  font-size: 16px;
  color: #6b7280;
  margin: 0;
}

.category-tabs {
  margin-bottom: 32px;
  text-align: center;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.content-card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: all 0.2s;
}

.content-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transform: translateY(-4px);
}

.card-image {
  width: 100%;
  height: 180px;
  overflow: hidden;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  padding: 16px;
}

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

.card-overview {
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 12px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 12px;
  color: #9ca3af;
}

.loading-placeholder,
.empty-placeholder {
  grid-column: 1 / -1;
  padding: 60px 0;
  text-align: center;
}

.pagination-wrap {
  margin-top: 40px;
  text-align: center;
}

@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}
</style>
