<!-- 统计卡片组件 -->
<template>
  <div class="stats-container">
    <div class="stat-cards">
      <div
        v-for="(stat, index) in stats"
        :key="index"
        class="stat-card"
        :class="{'active': modelValue === index}"
        @click="$emit('update:modelValue', index)"
      >
        <div class="stat-icon" :style="{ backgroundColor: getIconBgColor(index) }">
          <img :src="stat.icon" alt="icon" style="width: 60%; height: 60%; object-fit: contain;" />
        </div>
        <div class="stat-info">
          <div class="stat-title">{{ stat.title }}</div>
          <div class="stat-bottom">
            <div class="stat-value">{{ stat.value }}</div>
            <div class="stat-change">
              <span class="percent">+{{ stat.change }}%</span>
              <el-icon><ArrowUp /></el-icon>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ArrowUp } from '@element-plus/icons-vue';

defineProps({
  stats: {
    type: Array,
    required: true
  },
  modelValue: {
    type: Number,
    default: 0
  }
});

defineEmits(['update:modelValue']);

// 根据索引获取不同的图标背景色
function getIconBgColor(index) {
  const colors = [
    'rgba(86, 108, 255, 0.15)',  // 紫色背景
    'rgba(57, 196, 106, 0.15)',  // 绿色背景
    'rgba(255, 168, 0, 0.15)',   // 橙色背景
    'rgba(255, 86, 86, 0.15)'    // 红色背景
  ];
  return colors[index] || colors[0];
}
</script>

<style scoped>
.stats-container {
  width: 100%;
  margin-bottom: 20px;
  background-color: #272B38;
  border-radius: 8px;
  padding: 15px;
}

.stat-cards {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 16px;
}

.stat-card {
  flex: 1;
  background-color: #292C38;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: center;
  color: #fff;
  height: 100%;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 200px;
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
}

.stat-info {
  flex: 1;
}

.stat-title {
  font-size: 14px;
  color: #96A0B5;
  margin-bottom: 8px;
}

.stat-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-value {
  font-size: 26px;
  font-weight: bold;
  margin-bottom: 4px;
}

.stat-change {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #67C23A;
}

.percent {
  margin-right: 4px;
}

@media (max-width: 1200px) {
  .stat-cards {
    flex-wrap: wrap;
  }
  
  .stat-card {
    min-width: calc(50% - 8px);
    margin-bottom: 16px;
  }
}

@media (max-width: 768px) {
  .stat-card {
    min-width: 100%;
  }
}
</style> 