<script setup lang="ts">
import { computed } from 'vue'
import { Clock, ChevronRight } from '@lucide/vue'
import type { MissionData } from '../../composables/useDashboardData'

const props = defineProps<{
  mission: MissionData
}>()

const statusColor: Record<string, string> = {
  healthy: '#22c55e',
  attention: '#eab308',
  blocked: '#ef4444',
  paused: '#6b7280',
}

const statusLabel = computed(() => {
  const map: Record<string, string> = {
    healthy: 'Healthy',
    attention: 'Warning',
    blocked: 'Blocked',
    paused: 'Paused',
  }
  return map[props.mission.status] ?? props.mission.status
})
</script>

<template>
  <article class="mission-card" tabindex="0">
    <div class="mission-head">
      <h3>{{ mission.name }}</h3>
      <span
        class="mission-status"
        :style="{ color: statusColor[mission.status] }"
      >
        {{ statusLabel }}
      </span>
    </div>

    <div class="progress-track">
      <div
        class="progress-fill"
        :style="{
          width: `${mission.progress}%`,
          background: `linear-gradient(90deg, ${statusColor[mission.status]}, color-mix(in srgb, ${statusColor[mission.status]} 65%, #fff))`,
        }"
      ></div>
    </div>

    <div class="mission-body">
      <div class="mission-detail">
        <span class="detail-label">Current Task</span>
        <span class="detail-value">{{ mission.currentTask }}</span>
      </div>

      <div class="mission-footer">
        <div class="mission-meta">
          <Clock :size="10" />
          <span>{{ mission.lastActivity }}</span>
        </div>
        <div class="mission-tasks">
          <span class="tasks-count">{{ mission.remainingTasks }}</span>
          <span class="tasks-label">remaining</span>
        </div>
      </div>
    </div>

    <div class="mission-arrow">
      <ChevronRight :size="14" />
    </div>
  </article>
</template>

<style scoped>
.mission-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: rgba(22, 27, 34, 0.65);
  border: 1px solid rgba(139, 124, 246, 0.08);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.mission-card:hover {
  border-color: rgba(139, 124, 246, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.mission-card:focus-visible {
  outline: 2px solid #a78bfa;
  outline-offset: 2px;
}

.mission-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.mission-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: #e8eaf0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mission-status {
  font-size: 8px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.progress-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.mission-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mission-detail {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.detail-label {
  font-size: 8px;
  color: #6b7385;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.detail-value {
  font-size: 10px;
  color: #7e8799;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mission-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mission-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: #6b7385;
}
.mission-tasks {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tasks-count {
  font-size: 12px;
  font-weight: 700;
  color: #a78bfa;
  font-variant-numeric: tabular-nums;
}
.tasks-label {
  font-size: 8px;
  color: #6b7385;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mission-arrow {
  position: absolute;
  right: 10px;
  bottom: 10px;
  color: #6b7385;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.mission-card:hover .mission-arrow {
  opacity: 1;
  transform: translateX(2px);
}
</style>
