<template>
  <div class="admin-dashboard">
    <!-- 左侧导航栏 -->
    <aside class="sidebar">
      <div class="logo">
        <span class="logo-text">LOGO</span>
      </div>
      
      <nav class="nav-menu">
        <div class="nav-item active">
          <el-icon><Grid /></el-icon>
          <span>数据仪表台</span>
        </div>
        <div class="nav-item" @click="goToUsers">
          <el-icon><User /></el-icon>
          <span>会员管理</span>
        </div>
        <div class="nav-item" @click="goToOrders">
          <el-icon><ShoppingCart /></el-icon>
          <span>订单管理</span>
        </div>
        <div class="nav-item">
          <el-icon><Document /></el-icon>
          <span>API管理</span>
        </div>
        <div class="nav-item">
          <el-icon><Briefcase /></el-icon>
          <span>生成任务记录</span>
        </div>
        <div class="nav-item">
          <el-icon><Setting /></el-icon>
          <span>系统设置</span>
        </div>
      </nav>
      
      <div class="sidebar-footer">
        <div class="online-users">
          <span>当前在线用户: </span>
          <span class="online-count">87/500</span>
        </div>
        <div class="system-uptime">
          <span>系统运行时间: 48小时32分</span>
        </div>
      </div>
    </aside>

    <!-- 主内容区域 -->
    <main class="main-content">
      <!-- 顶部搜索栏 -->
      <header class="top-header">
        <div class="search-bar">
          <el-icon class="search-icon"><Search /></el-icon>
          <input type="text" placeholder="搜索你的想要的内容" class="search-input">
        </div>
        <div class="header-right">
          <div class="notification-icon">
            <el-icon><Bell /></el-icon>
            <div class="notification-badge"></div>
          </div>
          <div class="user-avatar">
            <el-icon><Avatar /></el-icon>
            <el-icon class="arrow-down"><ArrowDown /></el-icon>
          </div>
        </div>
      </header>

      <!-- 统计卡片 -->
      <div class="stats-cards">
        <div class="stat-card">
          <div class="stat-icon users">
            <el-icon><User /></el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-title">用户总数</div>
            <div class="stat-number">12,847</div>
            <div class="stat-change positive">+12% 较上月同期</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon paid-users">
            <el-icon><User /></el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-title">付费用户数</div>
            <div class="stat-number">3,215</div>
            <div class="stat-change negative">-5% 较上月同期</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon revenue">
            <el-icon><Money /></el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-title">今日收入</div>
            <div class="stat-number">¥28,450</div>
            <div class="stat-change positive">+15% 较上月同期</div>
          </div>
        </div>
      </div>

      <!-- 图表区域 -->
      <div class="charts-section">
        <!-- 日活用户趋势 -->
        <div class="chart-card">
          <div class="chart-header">
            <h3>日活用户趋势</h3>
            <el-select v-model="selectedYear" class="year-select">
              <el-option label="2025年" value="2025"></el-option>
              <el-option label="2024年" value="2024"></el-option>
            </el-select>
          </div>
          <div class="chart-content">
            <div class="chart-placeholder">
              <div class="chart-title">日活用户趋势图</div>
              <div class="chart-description">显示每日活跃用户数量变化趋势</div>
            </div>
          </div>
        </div>

        <!-- 用户转化率 -->
        <div class="chart-card">
          <div class="chart-header">
            <h3>用户转化率</h3>
            <el-select v-model="selectedYear2" class="year-select">
              <el-option label="2025年" value="2025"></el-option>
              <el-option label="2024年" value="2024"></el-option>
            </el-select>
          </div>
          <div class="chart-content">
            <div class="chart-placeholder">
              <div class="chart-title">用户转化率图</div>
              <div class="chart-description">显示各月份用户转化率情况</div>
            </div>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  Grid, 
  User, 
  ShoppingCart, 
  Document, 
  Briefcase, 
  Setting, 
  Search, 
  Bell, 
  Avatar, 
  ArrowDown, 
  Money 
} from '@element-plus/icons-vue'

const router = useRouter()

// 年份选择
const selectedYear = ref('2025')
const selectedYear2 = ref('2025')

// 导航函数
const goToUsers = () => {
  router.push('/admin/users')
}

const goToOrders = () => {
  router.push('/admin/orders')
}

// 页面加载时获取数据
onMounted(() => {
  console.log('后台管理页面加载完成')
})
</script>

<style scoped>
.admin-dashboard {
  display: flex;
  height: 100vh;
  background: #f8f9fa;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 左侧导航栏 */
.sidebar {
  width: 240px;
  background: #ffffff;
  border-right: 1px solid #e9ecef;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

.logo {
  padding: 24px 20px;
  border-bottom: 1px solid #e9ecef;
}

.logo-text {
  font-size: 20px;
  font-weight: bold;
  color: #3b82f6;
}

.nav-menu {
  flex: 1;
  padding: 20px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  margin: 4px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover {
  background: #f3f4f6;
  color: #374151;
}

.nav-item.active {
  background: #dbeafe;
  color: #3b82f6;
}

.nav-item .el-icon {
  margin-right: 12px;
  font-size: 16px;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid #e9ecef;
  background: #f8f9fa;
}

.online-users {
  margin-bottom: 8px;
  font-size: 13px;
  color: #6b7280;
}

.online-count {
  color: #3b82f6;
  font-weight: 600;
}

.system-uptime {
  font-size: 13px;
  color: #6b7280;
}

/* 主内容区域 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
}

/* 顶部搜索栏 */
.top-header {
  background: #ffffff;
  padding: 16px 24px;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: #9ca3af;
  font-size: 16px;
}

.search-input {
  width: 300px;
  padding: 10px 12px 10px 40px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-input::placeholder {
  color: #9ca3af;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.notification-icon {
  position: relative;
  padding: 8px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s ease;
}

.notification-icon:hover {
  background: #f3f4f6;
}

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
}

.user-avatar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s ease;
}

.user-avatar:hover {
  background: #f3f4f6;
}

.arrow-down {
  font-size: 12px;
  color: #6b7280;
}

/* 统计卡片 */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  padding: 24px;
}

.stat-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.stat-icon.users {
  background: #fef3c7;
  color: #f59e0b;
}

.stat-icon.paid-users {
  background: #dbeafe;
  color: #3b82f6;
}

.stat-icon.revenue {
  background: #fce7f3;
  color: #ec4899;
}

.stat-content {
  flex: 1;
}

.stat-title {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 8px;
  font-weight: 500;
}

.stat-number {
  font-size: 28px;
  font-weight: bold;
  color: #111827;
  margin-bottom: 4px;
}

.stat-change {
  font-size: 13px;
  font-weight: 500;
}

.stat-change.positive {
  color: #059669;
}

.stat-change.negative {
  color: #dc2626;
}

/* 图表区域 */
.charts-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 0 24px 24px;
}

.chart-card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.chart-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}

.year-select {
  width: 100px;
}

.chart-content {
  padding: 24px;
  height: 300px;
}

.chart-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border-radius: 8px;
  border: 2px dashed #d1d5db;
}

.chart-title {
  font-size: 16px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 8px;
}

.chart-description {
  font-size: 14px;
  color: #6b7280;
  text-align: center;
}

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

@media (max-width: 768px) {
  .admin-dashboard {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: auto;
  }
  
  .stats-cards {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  
  .charts-section {
    padding: 0 16px 16px;
  }
  
  .search-input {
    width: 200px;
  }
  
  .top-header {
    padding: 12px 16px;
  }
}

@media (max-width: 480px) {
  .stat-card {
    padding: 16px;
  }
  
  .stat-number {
    font-size: 24px;
  }
  
  .chart-content {
    padding: 16px;
    height: 250px;
  }
}
</style>
