<script setup lang="ts">
defineProps<{
  visible: boolean
  status: 'idle' | 'active' | 'complete' | 'error'
  insight: {
    statusTitle: string
    systemSummary: string
    jarvisNote: string
  }
  activeAgent: string | null
  visitedAgents: string[]
  events: Array<{
    id: string
    startedAt: string
    status: 'active' | 'success' | 'error'
    items: Array<{
      id: string
      time: string
      label: string
      kind: 'info' | 'tool' | 'success' | 'error'
    }>
  }>
  systemTelemetry: {
    cpu: { current: number | null; series: number[]; online: boolean }
    memory: { current: number | null; series: number[]; online: boolean }
    disk: { current: number | null; series: number[]; online: boolean }
  }
  sessionTelemetry: {
    activitySeries: number[]
    eventsCount: number
    toolCount: number
    agentCount: number
  }
}>()
</script>

<template>
  <aside class="orchestration-panel" :class="{ visible }">
    <div class="panel-frame">
      <div class="panel-header">
        <div class="panel-title">RECENT EVENTS</div>
        <div class="panel-count">{{ events.length }}</div>
      </div>

      <div v-if="events.length === 0" class="feed-empty">No events yet</div>
      <div v-else class="feed-list">
        <div v-for="event in events" :key="event.id" class="feed-item" :class="event.status">
          <div class="feed-copy">
            <div class="feed-bubble-head">
              <span class="feed-time">[{{ event.startedAt }}]</span>
              <span class="feed-status">{{ event.status }}</span>
            </div>
            <div class="feed-steps">
              <div v-for="item in event.items" :key="item.id" class="feed-step" :class="item.kind">
                <span class="feed-step-time">{{ item.time }}</span>
                <span class="feed-label">{{ item.label }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </aside>
</template>

<style scoped>
.orchestration-panel {
  width: 340px;
  min-width: 340px;
  height: 100%;
  padding: 18px 18px 18px 0;
  opacity: 1;
}

.panel-frame {
  height: 100%;
  border-radius: 18px;
  border: 1px solid rgba(34, 211, 238, 0.18);
  background: linear-gradient(180deg, rgba(8, 14, 28, 0.96), rgba(6, 10, 20, 0.92));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 0 20px rgba(34, 211, 238, 0.08);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--accent-cyan);
}

.panel-count {
  min-width: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.16);
  background: rgba(34, 211, 238, 0.08);
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: center;
  color: var(--text-primary);
}

.feed-empty {
  font-size: 12px;
  color: var(--text-dim);
}

.feed-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.feed-item {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(34, 211, 238, 0.14);
  background: linear-gradient(180deg, rgba(10, 18, 32, 0.86), rgba(8, 14, 26, 0.72));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
  font-size: 12px;
  color: var(--text-secondary);
}

.feed-copy {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feed-bubble-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.feed-time {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.feed-status {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.feed-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feed-step {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.feed-step:first-child {
  padding-top: 0;
  border-top: none;
}

.feed-step-time {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

.feed-step.tool .feed-label {
  color: #fde68a;
}

.feed-step.success .feed-label {
  color: #86efac;
}

.feed-step.error .feed-label {
  color: #fda4af;
}

.feed-item.success {
  border-color: rgba(74, 222, 128, 0.22);
  background: linear-gradient(180deg, rgba(10, 34, 22, 0.8), rgba(8, 18, 14, 0.72));
}

.feed-item.error {
  border-color: rgba(255, 71, 87, 0.22);
  background: linear-gradient(180deg, rgba(42, 16, 22, 0.82), rgba(24, 10, 14, 0.72));
}

.feed-label {
  line-height: 1.6;
}

@media (max-width: 960px) {
  .orchestration-panel {
    width: 100%;
    min-width: 0;
    padding: 12px 12px 12px 0;
  }
}
</style>
