<script setup lang="ts">
import type { Component } from 'vue';

defineProps<{
  eyebrow: string;
  value: string | number;
  label: string;
  tone?: "neutral" | "brand" | "success" | "warn" | "danger" | "info";
  icon?: Component;
}>();
</script>

<template>
  <article class="metric-card" :class="tone ?? 'neutral'">
    <div class="metric-header">
      <div v-if="icon" class="metric-icon-wrapper" :class="tone ?? 'neutral'">
        <component :is="icon" />
      </div>
      <div class="metric-title-group">
        <p class="eyebrow">{{ eyebrow }}</p>
        <strong class="value">{{ value }}</strong>
      </div>
    </div>
    <p class="label">{{ label }}</p>
  </article>
</template>

<style scoped>
.metric-card {
  padding: 20px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #f0f3fa;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}

.metric-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  transform: translateY(-2px);
}

.metric-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.metric-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.metric-icon-wrapper.neutral { background: #f0f2f5; color: #595959; }
.metric-icon-wrapper.brand { background: #e6f4ff; color: #1677ff; }
.metric-icon-wrapper.success { background: #f6ffed; color: #52c41a; }
.metric-icon-wrapper.warn { background: #fffbe6; color: #faad14; }
.metric-icon-wrapper.danger { background: #fff2f0; color: #ff4d4f; }
.metric-icon-wrapper.info { background: #e6f7ff; color: #1890ff; }

.metric-title-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.eyebrow,
.label {
  margin: 0;
}

.eyebrow {
  color: #8c8c8c;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.value {
  display: block;
  font-size: 24px;
  font-weight: 800;
  color: #141414;
  line-height: 1.1;
}

.label {
  color: #8c8c8c;
  font-size: 12px;
  line-height: 1.5;
  border-top: 1px solid #f0f0f0;
  padding-top: 12px;
  margin-top: auto;
}

html[data-theme="dark"] .metric-card {
  background: #141414;
  border-color: #303030;
}
html[data-theme="dark"] .metric-icon-wrapper.neutral { background: #262626; color: rgba(255, 255, 255, 0.45); }
html[data-theme="dark"] .metric-icon-wrapper.brand { background: rgba(22, 119, 255, 0.2); color: #177ddc; }
html[data-theme="dark"] .metric-icon-wrapper.success { background: rgba(82, 196, 26, 0.2); color: #49aa19; }
html[data-theme="dark"] .metric-icon-wrapper.warn { background: rgba(250, 173, 20, 0.2); color: #d89614; }
html[data-theme="dark"] .metric-icon-wrapper.danger { background: rgba(255, 77, 79, 0.2); color: #a61d24; }
html[data-theme="dark"] .metric-icon-wrapper.info { background: rgba(24, 144, 255, 0.2); color: #177ddc; }
html[data-theme="dark"] .eyebrow,
html[data-theme="dark"] .label { color: rgba(255, 255, 255, 0.45); }
html[data-theme="dark"] .value { color: rgba(255, 255, 255, 0.85); }
html[data-theme="dark"] .label { border-top-color: #303030; }
</style>
