<template>
  <div class="faculty-page">
    <!-- 横幅图片区域 -->
    <div class="page-header">
      <div class="banner-image-container">
        <!-- 实际图片 -->
        <img
          v-if="hasBannerImage"
          :src="bannerImageSrc"
          alt="师资力量横幅"
          class="banner-image"
        />
        <!-- 图片占位区域 -->
        <div v-else class="banner-placeholder">
          <div class="placeholder-content">
            <div class="placeholder-icon">🖼️</div>
            <div class="placeholder-text">师资力量横幅图片占位</div>
            <div class="placeholder-desc">请提供横幅图片</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <div class="container">
        <!-- 筛选标签栏 -->
        <div class="filter-tabs">
          <button 
            v-for="tab in filterTabs" 
            :key="tab.id"
            :class="['filter-tab', { active: activeTab === tab.id }]"
            @click="activeTab = tab.id"
          >
            {{ tab.name }}
          </button>
        </div>

        <!-- 师资卡片网格 -->
        <div class="faculty-grid">
          <div 
            v-for="teacher in paginatedTeachers" 
            :key="teacher.id"
            class="faculty-card"
          >
            <div class="card-header">
              <div class="avatar-container">
                <!-- 头像占位 -->
                <div class="avatar-placeholder"></div>
                <div v-if="teacher.featured" class="featured-badge">金牌讲师</div>
              </div>
              <div class="card-arrow">
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
                  <path d="M6 4L10 8L6 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
              </div>
            </div>
            <div class="card-content">
              <h3 class="teacher-name">{{ teacher.name }}</h3>
              <p class="teacher-title">{{ teacher.title }}</p>
              <p class="teacher-description">{{ teacher.description }}</p>
              <div class="teacher-tags">
                <span v-for="tag in teacher.tags" :key="tag" class="tag">{{ tag }}</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 分页组件 -->
        <div class="pagination">
          <button class="page-btn" :disabled="currentPage === 1" @click="goToPage(currentPage - 1)">
            上一页
          </button>
          <button
            v-for="page in visiblePages"
            :key="page"
            :class="['page-btn', { active: currentPage === page }]"
            @click="typeof page === 'number' ? goToPage(page) : null"
            :disabled="typeof page !== 'number'"
          >
            {{ page }}
          </button>
          <button class="page-btn" :disabled="currentPage === totalPages" @click="goToPage(currentPage + 1)">
            下一页
          </button>
          <span class="page-info">共{{ totalPages }}页</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'

// 横幅图片相关
const bannerImageSrc = ref('')
const hasBannerImage = computed(() => bannerImageSrc.value.trim() !== '')

// 设置横幅图片的方法（供后续使用）
const setBannerImage = (imagePath: string) => {
  bannerImageSrc.value = imagePath
}

// 筛选标签数据
const filterTabs = ref([
  { id: 'all', name: '全部讲师' },
  { id: 'main', name: '主讲' },
  { id: 'international', name: '注册国际讲师' },
  { id: 'consultant', name: '咨询师' },
  { id: 'expert', name: '专家顾问' },
  { id: 'senior', name: '资深讲师' },
  { id: 'featured', name: '金牌讲师' },
  { id: 'enterprise', name: '企业导师' }
])

const activeTab = ref('all')

// 师资数据
const teachers = ref([
  {
    id: 1,
    name: '黄天羽',
    title: '注册国际人才测评师资格认证',
    description: '注册国际企业学习设计师 认证',
    tags: ['主讲', '资深人才测评师'],
    featured: true
  },
  {
    id: 2,
    name: '蓝天',
    title: '北京理工大学MBA企业文化专家顾问',
    description: '多家知名上市企业高管',
    tags: ['主讲', 'MBA企业文化专家']
  },
  {
    id: 3,
    name: '万精云',
    title: '中国人事科学',
    description: '中国科学院博士',
    tags: ['主讲', '人事专家']
  },
  {
    id: 4,
    name: '张庆勋',
    title: '北京大学博士',
    description: '内蒙古财经大学',
    tags: ['主讲', '金牌讲师']
  },
  {
    id: 5,
    name: '程毅',
    title: '中国科技大学博士研究生',
    description: '',
    tags: ['主讲', '科技专家']
  },
  {
    id: 6,
    name: '王德华',
    title: '数字经济与金融研究中心专家',
    description: '多家知名上市企业高级管理顾问',
    tags: ['主讲', '数字经济专家']
  },
  {
    id: 7,
    name: '马前程',
    title: '清华大学管理学院',
    description: '多家一线互联网企业高级管理顾问',
    tags: ['主讲', '清华大学管理专家']
  },
  {
    id: 8,
    name: '陈宇',
    title: '知名上市企业高级管理顾问专家',
    description: '多家一线互联网企业高级管理顾问',
    tags: ['主讲', '企业管理专家']
  }
])

// 分页相关
const currentPage = ref(1)
const pageSize = 8
const totalPages = computed(() => Math.ceil(teachers.value.length / pageSize))

const paginatedTeachers = computed(() => {
  const start = (currentPage.value - 1) * pageSize
  const end = start + pageSize
  return teachers.value.slice(start, end)
})

const visiblePages = computed(() => {
  const pages = []
  const total = totalPages.value
  const current = currentPage.value
  
  if (total <= 7) {
    for (let i = 1; i <= total; i++) {
      pages.push(i)
    }
  } else {
    if (current <= 4) {
      for (let i = 1; i <= 5; i++) {
        pages.push(i)
      }
      pages.push('...')
      pages.push(total)
    } else if (current >= total - 3) {
      pages.push(1)
      pages.push('...')
      for (let i = total - 4; i <= total; i++) {
        pages.push(i)
      }
    } else {
      pages.push(1)
      pages.push('...')
      for (let i = current - 1; i <= current + 1; i++) {
        pages.push(i)
      }
      pages.push('...')
      pages.push(total)
    }
  }
  
  return pages
})

const goToPage = (page: number) => {
  if (page >= 1 && page <= totalPages.value) {
    currentPage.value = page
  }
}
</script>

<style scoped>
.faculty-page {
  min-height: 100vh;
  background: #f6f6f6;
}

/* 横幅图片区域 */
.page-header {
  width: 100%;
  position: relative;
  overflow: hidden;
}

.banner-image-container {
  width: 100%;
  height: 400px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.banner-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.banner-placeholder::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
  opacity: 0.3;
}

.placeholder-content {
  text-align: center;
  color: white;
  position: relative;
  z-index: 1;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.8;
}

.placeholder-text {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}

.placeholder-desc {
  font-size: 16px;
  opacity: 0.8;
}

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

/* 主要内容区域 */
.main-content {
  padding: 40px 0 80px;
}

/* 筛选标签栏 */
.filter-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 40px;
  background: white;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.filter-tab {
  padding: 12px 24px;
  border: none;
  background: transparent;
  color: #666;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.3s;
  white-space: nowrap;
}

.filter-tab:hover {
  background: #f8f9fa;
  color: #333;
}

.filter-tab.active {
  background: #4A90E2;
  color: white;
}

/* 师资卡片网格 */
.faculty-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  margin-bottom: 40px;
}

.faculty-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s;
  cursor: pointer;
}

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

.card-header {
  position: relative;
  height: 200px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.avatar-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e0e0e0 0%, #f0f0f0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-placeholder::after {
  content: '头像占位';
  color: #999;
  font-size: 14px;
}

.featured-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: #FF6B35;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.card-arrow {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  color: #4A90E2;
  background: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-content {
  padding: 20px;
}

.teacher-name {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0 0 8px 0;
}

.teacher-title {
  font-size: 14px;
  color: #666;
  margin: 0 0 8px 0;
  line-height: 1.4;
}

.teacher-description {
  font-size: 13px;
  color: #999;
  margin: 0 0 12px 0;
  line-height: 1.4;
  min-height: 18px;
}

.teacher-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  background: #f0f8ff;
  color: #4A90E2;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid #e6f3ff;
}

/* 分页组件 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 40px;
}

.page-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: white;
  color: #666;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
  min-width: 40px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-btn:hover:not(:disabled) {
  background: #f8f9fa;
  border-color: #4A90E2;
  color: #4A90E2;
}

.page-btn.active {
  background: #4A90E2;
  border-color: #4A90E2;
  color: white;
}

.page-btn:disabled {
  background: #f5f5f5;
  color: #ccc;
  cursor: not-allowed;
  border-color: #eee;
}

.page-info {
  margin-left: 16px;
  color: #666;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .faculty-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1024px) {
  .banner-image-container {
    height: 350px;
  }

  .placeholder-icon {
    font-size: 40px;
  }

  .placeholder-text {
    font-size: 20px;
  }
}

@media (max-width: 768px) {
  .faculty-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .filter-tabs {
    flex-wrap: wrap;
    gap: 8px;
  }

  .filter-tab {
    padding: 8px 16px;
    font-size: 13px;
  }

  .banner-image-container {
    height: 300px;
  }

  .placeholder-icon {
    font-size: 36px;
  }

  .placeholder-text {
    font-size: 18px;
  }

  .placeholder-desc {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .faculty-grid {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 0 16px;
  }

  .main-content {
    padding: 20px 0 40px;
  }

  .banner-image-container {
    height: 250px;
  }

  .placeholder-icon {
    font-size: 32px;
  }

  .placeholder-text {
    font-size: 16px;
  }

  .placeholder-desc {
    font-size: 12px;
  }
}
</style>
