<template>
  <el-card class="stat-card" shadow="hover">
    <div class="stat-header">
      <div class="stat-title">
        <i :class="icon" :style="{ color: iconColor }"></i>
        <span>{{ title }}</span>
      </div>
    </div>
    <div class="stat-main">
      <div class="main-value">
        <count-to
          :start-val="0"
          :end-val="mainValue"
          :duration="2000"
          class="main-count"
        />
        <div class="main-label">{{ mainLabel }}</div>
      </div>
    </div>
    <div class="stat-footer">
      <div v-for="(item, index) in items" :key="index" class="footer-item">
        <span class="item-label">{{ item.label }}</span>
        <count-to
          :start-val="0"
          :end-val="item.value"
          :duration="2000"
          class="item-value"
        />
      </div>
    </div>
  </el-card>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  name: 'StatCard',
  components: {
    CountTo
  },
  props: {
    title: {
      type: String,
      required: true
    },
    icon: {
      type: String,
      required: true
    },
    iconColor: {
      type: String,
      default: '#409EFF'
    },
    mainValue: {
      type: Number,
      default: null,
    },
    mainLabel: {
      type: String,
      required: true
    },
    items: {
      type: Array,
      default: () => []
    }
  }
}
</script>

<style lang="scss" scoped>
.stat-card {
  height: 100%;
  .stat-header {
    margin-bottom: 20px;
    .stat-title {
      display: flex;
      align-items: center;
      font-size: 16px;
      i {
        margin-right: 8px;
        font-size: 20px;
      }
    }
  }
  .stat-main {
    margin-bottom: 20px;
    .main-value {
      text-align: center;
      .main-count {
        font-size: 36px;
        font-weight: bold;
        color: #303133;
        line-height: 1.2;
      }
      .main-label {
        margin-top: 8px;
        font-size: 14px;
        color: #909399;
      }
    }
  }
  .stat-footer {
    display: flex;
    justify-content: space-between;
    .footer-item {
      text-align: center;
      .item-label {
        display: block;
        font-size: 12px;
        color: #909399;
        margin-bottom: 4px;
      }
      .item-value {
        font-size: 16px;
        color: #606266;
      }
    }
  }
}
</style> 