<template>
  <section class="glass-panel score-board">
    <div>
      <p class="panel-eyebrow">Efficiency Score</p>
      <h3>{{ templateName || '运行能效评分' }}</h3>
      <p class="score-desc">{{ analysisConclusion || '评分结果仅用于工况横向比较。' }}</p>
    </div>

    <div class="score-ring">
      <div class="score-label">综合评分</div>
      <div class="score-value">{{ formatNumber(overallScore) }}</div>
      <div class="score-foot">100 分制</div>
    </div>

    <div class="score-items">
      <div v-for="item in metricScores.slice(0, 4)" :key="item.metricCode" class="score-item">
        <span>{{ item.metricName }}</span>
        <strong>{{ formatNumber(item.score) }}</strong>
      </div>
    </div>
  </section>
</template>

<script setup lang="ts">
import type { EfficiencyMetricScoreVO } from '@/api/ems/types';

defineOptions({
  name: 'EfficiencyScoreBoard'
});

defineProps<{
  overallScore?: number | string;
  templateName?: string;
  analysisConclusion?: string;
  metricScores: EfficiencyMetricScoreVO[];
}>();

const formatNumber = (value: unknown) => {
  if (value === null || value === undefined || value === '') {
    return '--';
  }
  const numberValue = Number(value);
  return Number.isNaN(numberValue) ? '--' : numberValue.toFixed(2);
};
</script>

<style scoped>
.glass-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px minmax(220px, 280px);
  gap: 18px;
  align-items: center;
  padding: 20px;
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

.panel-eyebrow {
  margin: 0 0 6px;
  color: #2563eb;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.glass-panel h3 {
  margin: 0;
}

.score-desc {
  margin: 10px 0 0;
  color: #64748b;
  line-height: 1.7;
}

.score-ring {
  display: grid;
  place-items: center;
  min-height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.1) 0%, rgba(15, 118, 110, 0.16) 100%);
}

.score-label,
.score-foot {
  color: #64748b;
  font-size: 13px;
}

.score-value {
  margin-top: 8px;
  font-size: 44px;
  font-weight: 700;
  color: #0f172a;
}

.score-items {
  display: grid;
  gap: 12px;
}

.score-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.98), rgba(241, 245, 249, 0.96));
}

.score-item span {
  color: #475569;
}

.score-item strong {
  color: #0f172a;
}

@media (max-width: 992px) {
  .glass-panel {
    grid-template-columns: 1fr;
  }
}
</style>
