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

const router = useRouter()

interface AgentCard {
  id: string
  name: string
  role: string
  description: string
  tags: string[]
  color: string
  icon: string
}

const agents: AgentCard[] = [
  {
    id: 'iris',
    name: 'Iris',
    role: 'Chief of Staff',
    description: 'Koordiniert, delegiert, hält das Team tight. Die erste Anlaufstelle zwischen Boss und Maschine.',
    tags: ['Orchestration', 'Delegation', 'Approval'],
    color: '#8b7cf6',
    icon: 'bot',
  },
  {
    id: 'programmer',
    name: 'Programmer',
    role: 'Lead Developer',
    description: 'Implementiert Features, schreibt Code, führt Builds und Tests aus. Arbeitet autonom im Scope.',
    tags: ['Coding', 'Development', 'Builds'],
    color: '#4d8cf6',
    icon: 'code',
  },
  {
    id: 'architekt',
    name: 'Architekt',
    role: 'Infrastructure Engineer',
    description: 'Verantwortlich für Docker, Nginx, Deployment und VPS-Infrastruktur.',
    tags: ['Infrastructure', 'Deployment', 'Docker'],
    color: '#4da8f6',
    icon: 'server',
  },
  {
    id: 'reviewer',
    name: 'Reviewer',
    role: 'Code QA',
    description: 'Prüft Code auf Bugs, Sicherheit und Wartbarkeit. Fixt Probleme eigenständig.',
    tags: ['QA', 'Security', 'Code Review'],
    color: '#f6a84d',
    icon: 'shield',
  },
  {
    id: 'researcher',
    name: 'Researcher',
    role: 'Research Analyst',
    description: 'Recherchiert, analysiert Quellen, prüft Fakten. Nur Lese-Rechte, keine Aktionen.',
    tags: ['Research', 'Analysis', 'Fact-Checking'],
    color: '#8b4df6',
    icon: 'search',
  },
  {
    id: 'executor',
    name: 'Executor',
    role: 'Host Executor',
    description: 'Führt Host-Kommandos auf dem VPS aus. Nur auf Iris-Befehl, niemals eigeninitiativ.',
    tags: ['Execution', 'Docker', 'VPS'],
    color: '#4df6d4',
    icon: 'terminal',
  },
]

function goToAgent(id: string) {
  router.push(`/agents/${id}`)
}

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>
  <div class="agents-page">
    <!-- Header -->
    <div class="page-header">
      <div class="header-icon-wrap">
        <Users :size="22" />
      </div>
      <div class="header-text">
        <h1>Agents</h1>
        <p class="header-subtitle">{{ agents.length }} AI agents — each with a real role and a real personality.</p>
      </div>
    </div>

    <!-- Agent grid -->
    <div class="agents-grid">
      <article
        v-for="agent in agents"
        :key="agent.id"
        class="agent-card"
        :style="{ '--card-color': agent.color }"
        @click="goToAgent(agent.id)"
      >
        <div class="card-stripe" :style="{ background: agent.color }"></div>
        <div class="card-content">
          <div class="card-header">
            <div class="card-icon-wrap" :style="{ background: `${agent.color}18`, color: agent.color }">
              <component :is="resolveIcon(agent.icon)" :size="18" />
            </div>
            <div class="card-info">
              <h3 class="card-name">{{ agent.name }}</h3>
              <span class="card-role">{{ agent.role }}</span>
            </div>
          </div>
          <p class="card-desc">{{ agent.description }}</p>
          <div class="card-tags">
            <span
              v-for="tag in agent.tags"
              :key="tag"
              class="card-tag"
              :style="{ background: `${agent.color}14`, color: agent.color, borderColor: `${agent.color}24` }"
            >
              {{ tag }}
            </span>
          </div>
        </div>
        <div class="card-footer">
          <span class="footer-label">View Profile</span>
          <span class="footer-arrow">&rarr;</span>
        </div>
      </article>
    </div>
  </div>
</template>

<style scoped>
.agents-page {
  max-width: 960px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}
.header-icon-wrap {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(139, 124, 246, 0.1);
  color: #8b7cf6;
  flex-shrink: 0;
}
.header-text h1 {
  margin: 0 0 2px;
  font-size: 22px;
  font-weight: 600;
  color: #e8eaf0;
}
.header-subtitle {
  margin: 0;
  font-size: 11px;
  color: #7e8799;
}

/* Agent grid */
.agents-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

/* Agent card */
.agent-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.agent-card:hover {
  border-color: var(--card-color);
  box-shadow: 0 0 20px color-mix(in srgb, var(--card-color) 10%, transparent);
  transform: translateY(-2px);
}

.card-stripe {
  height: 3px;
  flex-shrink: 0;
}

.card-content {
  padding: 16px 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.card-icon-wrap {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  flex-shrink: 0;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-name {
  margin: 0 0 1px;
  font-size: 13px;
  font-weight: 600;
  color: #e8eaf0;
}

.card-role {
  display: block;
  font-size: 9px;
  color: #7e8799;
  letter-spacing: 0.02em;
}

.card-desc {
  font-size: 10.5px;
  color: #7e8799;
  line-height: 1.5;
  margin: 0 0 10px;
  flex: 1;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.card-tag {
  display: inline-block;
  font-size: 8.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid transparent;
  letter-spacing: 0.02em;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  font-size: 9px;
  font-weight: 600;
  color: #6b7385;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: color 0.15s;
}
.agent-card:hover .card-footer {
  color: var(--card-color);
}

.footer-arrow {
  font-size: 12px;
  line-height: 1;
}

/* Responsive */
@media (max-width: 820px) {
  .agents-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 540px) {
  .agents-grid {
    grid-template-columns: 1fr;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
</style>
