<template>
  <TechCard class="people-detected-card">
    <div class="card-header">
      <div class="title">检测到人数</div>
    </div>

    <div class="matrix-wrapper">
      <div class="scan-overlay" />
      <div class="matrix-scroll">
        <div class="matrix-grid">
          <div
            v-for="(item, index) in props.limit"
            :key="index"
            class="person-icon"
            :class="{ active: detectedCount > props.limit || index < detectedCount }"
          >
            <svg viewBox="0 0 64 64" class="person-svg">
              <circle cx="32" cy="12" r="6" />
              <rect x="28" y="20" width="8" height="20" rx="4" />
              <path d="M28 22 L20 32" />
              <path d="M36 22 L44 32" />
              <path d="M30 40 L26 52" />
              <path d="M34 40 L38 52" />
            </svg>
          </div>
        </div>
      </div>
    </div>

    <div class="footer">
      <div class="label">已检测人数</div>
      <div class="count">{{ detectedCount }}人</div>
    </div>
  </TechCard>
</template>

<script setup lang="ts">
import TechCard from '../TechCard/index.vue'

defineOptions({ name: 'MonitorPeopleCountCard' })

type Props = {
  detectedCount: number
  limit?: number // 限制显示的人数
}

const props = withDefaults(defineProps<Props>(), {
  detectedCount: 0,
  limit: 28,
})
</script>

<style scoped lang="less">
.people-detected-card > {
  :deep(.card-content) {
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
  }
}
.card-header {
  text-align: center;
  margin-bottom: 14px;

  .title {
    font-size: 16px;
    font-weight: bold;
    color: #00f0ff;
  }
}

.matrix-wrapper {
  position: relative;
  padding: 12px 0;
  min-height: 100px;
  max-height: 144px;
  overflow: hidden;
}

.scan-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(to right, #00f0ff, #3b9ff0);
  box-shadow: 0 0 6px #00f0ff;
  pointer-events: none;
  z-index: 1;
  animation: scanDown 2.4s linear infinite;
}

@keyframes scanDown {
  0% {
    top: 0%;
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    top: 100%;
    opacity: 0;
  }
}

.matrix-scroll {
  height: 100%;
  overflow-y: auto;

  &::-webkit-scrollbar {
    width: 4px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background-color: transparent;
    border-radius: 2px;
  }

  &:hover::-webkit-scrollbar-thumb {
    background-color: #00f0ff;
  }

  &::-webkit-scrollbar-button {
    display: none;
    height: 0;
    width: 0;
  }

  scrollbar-width: thin;
  scrollbar-color: transparent transparent;

  &:hover {
    scrollbar-color: #00f0ff transparent;
  }
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(30px, 1fr));
  grid-auto-rows: 30px;
  gap: 10px;
}

.person-icon {
  width: 100%;
  height: 36px;
  position: relative;

  .person-svg {
    width: 100%;
    height: 100%;
    stroke-width: 3.5;
    fill: none;
    stroke: #00ff9f;
    opacity: 0.3;
    transition: opacity 0.3s ease;
    filter: drop-shadow(0 0 2px #00ff9f);
  }
}

.person-icon.active .person-svg {
  stroke: #00ff9f;
  opacity: 1;
  filter: drop-shadow(0 0 6px #00ff9f);
}

@keyframes radarPulse {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: drop-shadow(0 0 4px #00ff9f);
  }
  50% {
    transform: scale(1.3);
    opacity: 0.6;
    filter: drop-shadow(0 0 12px #00ff9f);
  }
  100% {
    transform: scale(1);
    opacity: 1;
    filter: drop-shadow(0 0 4px #00ff9f);
  }
}

.person-icon.active:hover .person-svg {
  animation: radarPulse 1.5s ease-in-out infinite;
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  color: #9cc5e0;

  .count {
    font-weight: bold;
    color: #00f0ff;
    font-size: 16px;
  }
}
</style>
