<template>
  <div class="stat-card" :style="{ borderTopColor: color }">
    <div class="stat-card__header">
      <i :class="icon" class="stat-card__icon" :style="{ color }"></i>
      <div class="stat-card__title">{{ title }}</div>
    </div>
    <div class="stat-card__value">
      <count-to :start-val="0" :end-val="Number(value) || 0" :duration="duration" />
      <span v-if="suffix" class="stat-card__suffix">{{ suffix }}</span>
    </div>
    <div v-if="desc" class="stat-card__desc">{{ desc }}</div>
  </div>
</template>

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

export default {
  name: 'StatCard',
  components: { CountTo },
  props: {
    title: { type: String, required: true },
    value: { type: [Number, String], default: 0 },
    suffix: { type: String, default: '' },
    icon: { type: String, default: 'el-icon-data-line' },
    color: { type: String, default: '#409EFF' },
    desc: { type: String, default: '' },
    duration: { type: Number, default: 2000 }
  }
}
</script>

<style lang="scss" scoped>
.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
  transition: all 0.3s;
  border-top: 4px solid #ebeef5;
  min-height: 120px;

  &:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
  }

  &__header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
  }

  &__icon {
    font-size: 22px;
    margin-right: 8px;
  }

  &__title {
    font-size: 14px;
    color: #606266;
  }

  &__value {
    display: flex;
    align-items: baseline;
    font-size: 24px;
    font-weight: 700;
    color: #303133;
  }

  &__suffix {
    margin-left: 6px;
    font-size: 12px;
    color: #909399;
    font-weight: 400;
  }

  &__desc {
    margin-top: 6px;
    font-size: 12px;
    color: #909399;
  }
}
</style>