<template>
  <div class="dashboard-page">
    <div class="stat-cards">
      <div class="stat-card">
        <div class="stat-icon users"><el-icon><User /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.users }}</p>
          <p class="stat-label">用户数</p>
        </div>
      </div>
      <div class="stat-card">
        <div class="stat-icon products"><el-icon><Goods /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.products }}</p>
          <p class="stat-label">商品数</p>
        </div>
      </div>
      <div class="stat-card">
        <div class="stat-icon orders"><el-icon><List /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.orders }}</p>
          <p class="stat-label">订单数</p>
        </div>
      </div>
      <div class="stat-card">
        <div class="stat-icon revenue"><el-icon><Money /></el-icon></div>
        <div class="stat-info">
          <p class="stat-value">{{ stats.revenue }}</p>
          <p class="stat-label">营收</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { User, Goods, List, Money } from '@element-plus/icons-vue'
import { adminApi } from '../../api'

const stats = ref({ users: '--', products: '--', orders: '--', revenue: '--' })

onMounted(async () => {
  try {
    const res: any = await adminApi.getStats()
    if (res.data) {
      stats.value.users = res.data.users || 0
      stats.value.products = res.data.products || 0
      stats.value.orders = res.data.orders || 0
      stats.value.revenue = '¥' + (res.data.revenue || 0).toFixed(2)
    }
  } catch (e) {
    console.error('获取统计数据失败:', e)
  }
})
</script>

<style scoped lang="scss">
.dashboard-page { padding: 0; }

.stat-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.stat-card {
  background: #2d2d44;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 200px;
  min-width: 200px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.stat-icon.users { background: rgba(78, 110, 242, 0.15); color: #4e6ef2; }
.stat-icon.products { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.stat-icon.orders { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.stat-icon.revenue { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.stat-info { flex: 1; }
.stat-value { font-size: 28px; font-weight: 700; color: #fff; }
.stat-label { font-size: 14px; color: rgba(255, 255, 255, 0.5); margin-top: 4px; }

@media (max-width: 768px) {
  .stat-cards {
    gap: 12px;
  }
  
  .stat-card {
    padding: 16px;
    gap: 12px;
    flex: 1 1 calc(50% - 6px);
    min-width: 140px;
  }
  
  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
    border-radius: 10px;
  }
  
  .stat-value {
    font-size: 22px;
  }
  
  .stat-label {
    font-size: 12px;
  }
}
</style>
