<template>
  <el-row :gutter="20" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" v-for="(item, index) in list" :key="index">
      <div class="card-panel">
        <div class="card-panel-content">
          <div class="card-panel-text">{{ item.title || '-' }}</div>
          <div class="card-panel-num">{{ item.value || 0 }}</div>
          <div class="card-panel-sub">
            <span class="sub-item" v-if="item.mom != null">
              环比: <span :class="item.mom >= 0 ? 'text-green' : 'text-red'">
                <i :class="item.mom >= 0 ? 'el-icon-top' : 'el-icon-bottom'" />
                {{ Math.abs(item.mom * 100).toFixed(0) }}%
              </span>
            </span>
            <span class="sub-item" v-if="item.yoy != null">
              同比: <span :class="item.yoy >= 0 ? 'text-green' : 'text-red'">
                <i :class="item.yoy >= 0 ? 'el-icon-top' : 'el-icon-bottom'" />
                {{ Math.abs(item.yoy * 100).toFixed(0) }}%
              </span>
            </span>
          </div>
        </div>
        <div class="card-panel-icon-wrapper" :class="`icon-${item.key}`">
          <!-- We can use a generic icon or specific svg here based on key -->
          <i v-if="item.key === 'shipProductCount'" class="el-icon-s-data icon-green" />
          <i v-else-if="item.key === 'workOrderCount'" class="el-icon-s-marketing icon-blue" />
          <i v-else-if="item.key === 'wipCount'" class="el-icon-pie-chart icon-cyan" />
          <i v-else-if="item.key === 'ngCount'" class="el-icon-warning-outline icon-red" />
          <i v-else class="el-icon-s-data icon-green" />
        </div>
        <div class="card-panel-arrow">
          <i class="el-icon-arrow-right" />
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: 'OverviewCards',
  props: {
    list: {
      type: Array,
      default: () => []
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 20px;
  }

  .card-panel {
    height: 120px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,21,41,.08);
    border-radius: 6px;
    border: 1px solid #ebeef5;
    display: flex;
    justify-content: space-between;
    padding: 20px;

    &:hover {
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
    }

    .card-panel-content {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

    .card-panel-text {
      color: #909399;
      font-size: 14px;
      font-weight: bold;
    }

    .card-panel-num {
      font-size: 26px;
      color: #303133;
      font-weight: bold;
      margin: 8px 0;
    }

    .card-panel-sub {
      color: #909399;
      font-size: 12px;
      display: flex;
      gap: 12px;

      .text-green {
        color: #16c784;
        font-weight: bold;
      }
      .text-red {
        color: #f56c6c;
        font-weight: bold;
      }
    }

    .card-panel-icon-wrapper {
      padding: 10px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
      font-size: 40px;
      
      .icon-green { color: #16c784; }
      .icon-blue { color: #409EFF; }
      .icon-cyan { color: #00b4ad; }
      .icon-red { color: #f56c6c; }
    }

    .card-panel-arrow {
      position: absolute;
      right: 15px;
      bottom: 15px;
      font-size: 14px;
      color: #c0c4cc;
    }
  }
}
</style>
