<script lang="ts" setup>
/**
 * KPI 统计卡：小图标 + 大数字 + 小标签，整卡可点跳转业务页
 * Premium 视觉：tinted 图标容器、hover 轻抬升 + primary 描边透出；颜色全走主题变量，亮/暗自适应
 */
import { IconifyIcon as VbenIcon } from '@vben/icons';

interface Props {
  /** 指标标签 */
  label: string;
  /** 指标值（数字或金额字符串） */
  value: number | string;
  /** 高亮强调（如待办数 > 0 时用主题色） */
  highlight?: boolean;
  /** iconify 图标名（可选） */
  icon?: string;
}

withDefaults(defineProps<Props>(), {
  highlight: false,
  icon: '',
});

defineEmits(['click']);
</script>

<template>
  <div class="stat-chip" :class="{ 'stat-chip--hl': highlight }" @click="$emit('click')">
    <div v-if="icon" class="stat-chip__icon-box">
      <VbenIcon :icon="icon" class="stat-chip__icon" />
    </div>
    <div class="stat-chip__meta">
      <span class="stat-chip__value">{{ value }}</span>
      <span class="stat-chip__label">{{ label }}</span>
    </div>
  </div>
</template>

<style scoped>
.stat-chip {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 128px;
  padding: 14px 16px;
  cursor: pointer;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: 12px;
  transition:
    transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.stat-chip:hover {
  transform: translateY(-1px);
  border-color: hsl(var(--primary) / 0.35);
  box-shadow:
    0 1px 2px hsl(var(--foreground) / 0.04),
    0 8px 24px hsl(var(--primary) / 0.08);
}

/* 高亮卡：待办类指标底色轻着色，暗色下同样柔和 */
.stat-chip--hl {
  background: linear-gradient(
    135deg,
    hsl(var(--primary) / 0.08),
    hsl(var(--card)) 65%
  );
  border-color: hsl(var(--primary) / 0.25);
}

.stat-chip__icon-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: hsl(var(--primary) / 0.1);
  border-radius: 10px;
  flex-shrink: 0;
  transition: background-color 0.2s ease;
}

.stat-chip:hover .stat-chip__icon-box {
  background: hsl(var(--primary) / 0.16);
}

.stat-chip__icon {
  width: 20px;
  height: 20px;
  color: hsl(var(--primary));
}

.stat-chip__meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.stat-chip__value {
  overflow: hidden;
  font-size: 22px;
  font-weight: 650;
  line-height: 1.2;
  color: hsl(var(--foreground));
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-chip--hl .stat-chip__value {
  color: hsl(var(--primary));
}

.stat-chip__label {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

/* 用户偏好减少动效时关闭位移动画 */
@media (prefers-reduced-motion: reduce) {
  .stat-chip {
    transition: none;
  }

  .stat-chip:hover {
    transform: none;
  }
}
</style>
