<script setup lang="ts">
import { Bot, Code2, Server, Shield, Search, Terminal } from '@lucide/vue'

defineProps<{
  id: string
  name: string
  role: string
  description: string
  icon: string
  color: string
  tags: string[]
  hero?: boolean
}>()

defineEmits<{
  click: [id: string]
}>()

function resolveIcon(iconName: string) {
  switch (iconName) {
    case 'bot': return Bot
    case 'code': return Code2
    case 'server': return Server
    case 'shield': return Shield
    case 'search': return Search
    case 'terminal': return Terminal
    default: return Bot
  }
}
</script>

<template>
  <article
    :class="['agent-card', { 'hero-card': hero }]"
    :style="{ '--card-color': color }"
    @click="$emit('click', id)"
  >
    <div class="card-main">
      <div class="card-icon-wrap" :style="{ background: `${color}18`, color: color }">
        <component :is="resolveIcon(icon)" :size="hero ? 20 : 18" />
      </div>
      <div class="card-body">
        <div class="card-name-row">
          <h3 class="card-name">{{ name }}</h3>
          <span class="card-role-tag" :style="{ background: `${color}18`, color: color, borderColor: `${color}30` }">{{ role }}</span>
        </div>
        <p class="card-desc">{{ description }}</p>
        <div class="card-tags">
          <span v-for="tag in tags" :key="tag" class="card-tag" :style="{ background: `${color}18`, color: color }">{{ tag }}</span>
        </div>
      </div>
    </div>
    <div class="card-footer-action">
      <span>ROLE CARD</span>
      <span class="arrow">&rarr;</span>
    </div>
  </article>
</template>

<style scoped>
.agent-card {
  background: var(--panel, #11141b);
  border: 1px solid var(--line, #1f2330);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
  position: relative;
}
.agent-card:hover {
  border-color: var(--card-color, #8b7cf6);
  box-shadow: 0 0 16px color-mix(in srgb, var(--card-color, #8b7cf6) 10%, transparent);
}
.hero-card {
  border-color: rgba(139, 124, 246, 0.2);
  box-shadow: 0 0 20px rgba(139, 124, 246, 0.06);
}
.hero-card:hover {
  border-color: #8b7cf6;
  box-shadow: 0 0 24px rgba(139, 124, 246, 0.12);
}
.card-main {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.card-icon-wrap {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  flex-shrink: 0;
}
.card-body {
  flex: 1;
  min-width: 0;
}
.card-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.card-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #e8eaf0;
}
.card-role-tag {
  display: inline-block;
  font-size: 8.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.card-desc {
  font-size: 10.5px;
  color: #7e8799;
  line-height: 1.5;
  margin: 0 0 8px;
}
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.card-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
  letter-spacing: 0.02em;
}
.card-footer-action {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line, #1f2330);
  font-size: 9px;
  font-weight: 600;
  color: #6b7385;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.card-footer-action .arrow {
  font-size: 13px;
  line-height: 1;
}
.agent-card:hover .card-footer-action {
  color: var(--card-color, #8b7cf6);
}
</style>
