<script setup lang="ts">
defineProps<{
  total: number
  loading?: boolean
}>()
</script>

<template>
  <section class="device-total-card">
    <div class="card-top">
      <div class="metric-icon">
        <Icon icon="ep:histogram" :size="26" />
      </div>
      <div class="metric-meta">
        <span>设备总览</span>
        <strong>设备总数</strong>
      </div>
    </div>

    <div class="metric-value">
      <span v-if="!loading">{{ total }}</span>
      <span v-else class="value-skeleton"></span>
    </div>

    <div class="metric-footer">
      <span class="trend-pill">
        <Icon icon="ep:top" :size="12" />
        设备台账
      </span>
    </div>
  </section>
</template>

<style scoped lang="scss">
.device-total-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 164px;
  padding: 12px 14px;
  overflow: hidden;
  color: #172033;
  background: #fff;
  border: 1px solid #e8edf5;
  border-radius: 16px;
  box-shadow: 0 10px 26px rgb(15 23 42 / 8%);
  flex-direction: column;
  justify-content: space-between;
}

.device-total-card::before,
.device-total-card::after {
  position: absolute;
  pointer-events: none;
  border-radius: 999px;
  content: '';
}

.device-total-card::before {
  right: -36px;
  bottom: -54px;
  width: 132px;
  height: 132px;
  background: rgb(27 132 255 / 8%);
  border: 1px solid rgb(27 132 255 / 12%);
}

.device-total-card::after {
  top: 12px;
  right: 14px;
  width: 56px;
  height: 56px;
  background: #f0f7ff;
  border: 1px solid #dcecff;
}

.card-top,
.metric-footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-top {
  justify-content: flex-start;
  gap: 14px;
}

.metric-icon {
  display: flex;
  width: 40px;
  height: 40px;
  color: #1288ff;
  background: #edf7ff;
  border: 1px solid #d8ecff;
  border-radius: 16px;
  align-items: center;
  justify-content: center;
}

.metric-meta {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.metric-meta span,
.metric-footer {
  font-size: 13px;
  color: #7b8798;
}

.metric-meta strong {
  font-size: 17px;
  font-weight: 700;
  color: #172033;
}

.metric-value {
  position: relative;
  z-index: 1;
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
}

.trend-pill {
  display: inline-flex;
  padding: 4px 9px;
  font-size: 12px;
  color: #0d8a59;
  background: #e8f8ef;
  border-radius: 999px;
  align-items: center;
  gap: 3px;
}

.value-skeleton {
  display: block;
  width: 96px;
  height: 44px;
  background: #eef4fb;
  border-radius: 10px;
}
</style>
