<template>
  <div class="info-cards">
    <div class="info-title">
      数据简报
    </div>
    <div class="custom-line"></div>
    <div class="card-grid">
      
      <div
        v-for="(item, index) in infoList"
        :key="index"
        class="card"
        @click="handleClick(item)"
      >
      <el-icon :size="40" class="card-icon" :style="{ color: item.color }">
        <component :is="item.icon" />
      </el-icon>

        <div class="card-value">{{ item.value }}</div>
        <div class="card-label">{{ item.label }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts"  name="InfoCards">
import {
  Goods, Box, Collection, Timer, RefreshRight,
  DataLine, User
} from '@element-plus/icons-vue'
import { defineProps,computed } from 'vue'

const props = defineProps({
  summaryData: {
    type: Object,
    required: true
  }
})

const infoList = computed(()=>[
  { label: '设备总数', value: props.summaryData.total_devices, icon: Goods, color: '#409EFF' },
  { label: '在借数', value: props.summaryData.borrowed_devices, icon: Box, color: '#F56C6C' },
  { label: '在库数', value: props.summaryData.available_devices, icon: Collection, color: '#67C23A' },
  { label: '今日借出', value: props.summaryData.today_borrowed, icon: Timer, color: '#E6A23C' },
  { label: '今日归还', value: props.summaryData.today_returned, icon: RefreshRight, color: '#909399' },
  { label: '累计借用次数', value: props.summaryData.total_borrows, icon: DataLine, color: '#9B59B6' },
  { label: '累计借用人数', value: props.summaryData.total_borrowers, icon: User, color: '#3498DB' },
]);
function handleClick(item: any) {
  console.log('点击信息卡片:', item.label);
}
</script>

<style scoped>
.custom-line {
  height: 1px;
  background-color: #ccc;
  width: 100%;
  margin: 10px 0;
}

.info-title{
  padding-left: 10%;
  padding-top:10px;
  font-size: 30px;
}
.info-cards{
  background: #fff;
  height: 400px;
}
.card-grid {
  padding:30px;
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}
.card {
  width: calc(20% - 12px); 
  align-items: center;
  text-align: center;
  padding: 10px;
  cursor: pointer;
 border: none !important;
}
.card-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
}
.card-value {
  font-size: 20px;
  font-weight: bold;
  color: #67C23A;
}
.card-label {
  font-size: 14px;
  color: #666;
  margin-top: 4px;
}
</style>
