<template>
  <home-card :title="title" :desc="desc">
    <div class="system-panel">
      <div class="chart-container">
        <el-progress
          type="dashboard"
          :percentage="parseInt(value)"
          :color="getProgressColor"
          :stroke-width="10"
        >
          <template #default>
            <div class="progress-content">
              <span class="progress-value">{{ parseInt(value) }}%</span>
              <span class="progress-text">{{ subtext }}</span>
            </div>
          </template>
        </el-progress>
      </div>
      <div class="info-list">
        <div class="info-item" v-for="(item, index) in list" :key="index">
          <div class="info-label">
            <span class="color-dot" :style="{ background: item.color }"></span>
            <span>{{ item.name }}</span>
          </div>
          <div class="info-value">{{ item.value }}</div>
        </div>
      </div>
    </div>
  </home-card>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import HomeCard from './HomeCard.vue'

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  desc: {
    type: String,
    default: ''
  },
  list: {
    type: Array as () => {color: string, name: string, value: string}[],
    default: () => []
  },
  value: {
    type: String,
    default: 0
  },
  subtext: {
    type: String,
    default: ''
  }
})

const getProgressColor = computed(() => {
  const value = parseInt(props.value as string)
  if (value < 60) {
    return '#67C23A'
  } else if (value < 80) {
    return '#E6A23C'
  } else {
    return '#F56C6C'
  }
})
</script>

<style lang="scss" scoped>
.system-panel {
  display: flex;
  flex-wrap: wrap;
  
  .chart-container {
    flex: 0 0 200px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .progress-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    
    .progress-value {
      font-size: 24px;
      font-weight: bold;
    }
    
    .progress-text {
      font-size: 12px;
      color: #909399;
      margin-top: 5px;
    }
  }
  
  .info-list {
    flex: 1;
    margin-left: 20px;
    
    .info-item {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      font-size: 14px;
      
      .info-label {
        color: #606266;
        display: flex;
        align-items: center;
        
        .color-dot {
          width: 10px;
          height: 10px;
          border-radius: 50%;
          margin-right: 8px;
        }
      }
      
      .info-value {
        font-weight: 500;
        color: #303133;
      }
    }
  }
}

@media (max-width: 768px) {
  .system-panel {
    flex-direction: column;
    
    .chart-container {
      flex: none;
      margin-bottom: 20px;
    }
    
    .info-list {
      margin-left: 0;
    }
  }
}
</style>
