File size: 8,079 Bytes
1794757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
"use client";

import { useRef, useState, useEffect } from "react";
import {
  Users,
  ChevronLeft,
  ChevronRight,
  Shield,
  TrendingDown,
  TrendingUp,
} from "lucide-react";
import gsap from "gsap";
import { cn } from "@/src/lib/utils";
import { GlowingEffect } from "@/src/components/ui/glowing-effect";
import type { ActivityItem } from "./GlobePage";

const COLLAPSED_WIDTH = 48;
const EXPANDED_WIDTH = 360;

const AGENT_COLORS: Record<string, string> = {
  us: "#e53935",
  israel: "#64b5f6",
  iran: "#689f38",
  hezbollah: "#ffa000",
  gulf: "#a1887f",
  oversight: "#b0b0b0",
};

const ACTION_LABELS: Record<string, string> = {
  negotiate: "NEGOTIATE",
  defend: "DEFEND",
  intel_query: "INTEL",
  hold: "HOLD",
  strike: "STRIKE",
  sanction: "SANCTION",
  mobilize: "MOBILIZE",
  deceive: "DECEIVE",
  oversight_review: "REVIEW",
};

function AgentDot({ agent }: { agent: string }) {
  const color = AGENT_COLORS[agent] ?? "#888";
  return (
    <div
      className="h-2 w-2 shrink-0 rounded-full"
      style={{ backgroundColor: color }}
    />
  );
}

function TensionIndicator({ delta }: { delta: number }) {
  if (Math.abs(delta) < 0.1) return null;
  if (delta > 0) {
    return <TrendingUp className="h-3 w-3 text-primary" />;
  }
  return <TrendingDown className="h-3 w-3 text-secondary" />;
}

export function ActivityLog({ items, onRegisterToggle }: { items: ActivityItem[]; onRegisterToggle?: (fn: (collapsed: boolean) => void) => void }) {
  const [collapsed, setCollapsed] = useState(false);
  const panelRef = useRef<HTMLDivElement>(null);

  const applyCollapse = (next: boolean) => {
    setCollapsed(next);
    if (panelRef.current) {
      gsap.to(panelRef.current, {
        width: next ? COLLAPSED_WIDTH : EXPANDED_WIDTH,
        duration: 0.4,
        ease: "power2.inOut",
      });
    }
  };

  useEffect(() => {
    onRegisterToggle?.(applyCollapse);
  }, []);

  const toggle = () => applyCollapse(!collapsed);

  return (
    <div
      ref={panelRef}
      className="absolute top-6 bottom-6 right-4 z-20 select-none"
      style={{ width: EXPANDED_WIDTH }}
    >
      <div className="relative h-full rounded-md border-[0.75px] border-border/30 p-0">
        <GlowingEffect
          spread={40}
          glow={true}
          disabled={false}
          proximity={64}
          inactiveZone={0.01}
          borderWidth={2}
        />
        <div
          className="relative flex h-full overflow-hidden rounded-[inherit] bg-card/25 backdrop-blur-lg"
          style={{
            boxShadow:
              "0 0 8px rgba(0,0,0,0.03), 0 2px 6px rgba(0,0,0,0.08), inset 0 0 6px 6px rgba(255,255,255,0.04), 0 0 12px rgba(0,0,0,0.15)",
          }}
        >
          {/* Edge toggle bar — always visible, full height, LEFT side for right panel */}
          <button
            onClick={toggle}
            className="flex w-[48px] shrink-0 cursor-pointer flex-col items-center justify-center gap-2 border-r border-border/20 text-muted-foreground transition-colors hover:bg-muted/10 hover:text-foreground"
            title={collapsed ? "Expand panel" : "Collapse panel"}
          >
            {collapsed ? (
              <>
                <ChevronLeft className="h-4 w-4" />
                <span className="text-[9px] font-mono tracking-wider uppercase [writing-mode:vertical-lr]">
                  Activity
                </span>
              </>
            ) : (
              <ChevronRight className="h-4 w-4" />
            )}
          </button>

          {/* Content area — hidden when collapsed via overflow */}
          <div className={cn(
            "flex min-w-0 flex-1 flex-col transition-opacity duration-300",
            collapsed ? "opacity-0 pointer-events-none" : "opacity-100"
          )}>
            {/* Header */}
            <div className="flex items-center gap-2 border-b border-border/30 px-4 py-3">
              <Users className="h-3.5 w-3.5 shrink-0 text-primary" />
              <span className="whitespace-nowrap text-[10px] font-semibold tracking-[0.2em] text-foreground/80 uppercase font-sans">
                Agent Activity
              </span>
              <span className="ml-auto text-[9px] font-mono text-muted-foreground">
                {items.length}
              </span>
            </div>

            {/* Scrollable list */}
            <div className="flex-1 overflow-y-auto scrollbar-thin">
              {items.length === 0 ? (
                <div className="flex h-full items-center justify-center p-6">
                  <p className="text-center text-xs font-mono text-muted-foreground">
                    No agent actions recorded.
                    <br />
                    Awaiting simulation step.
                  </p>
                </div>
              ) : (
                <div className="divide-y divide-border/20">
                  {items.map((item) => (
                    <div
                      key={item.id}
                      className="group px-4 py-3 transition-colors hover:bg-muted/20"
                    >
                      <div className="flex items-start gap-2.5">
                        <div className="mt-1 shrink-0">
                          <AgentDot agent={item.agent} />
                        </div>
                        <div className="min-w-0 flex-1">
                          <div className="mb-1 flex items-center gap-2">
                            <span className="text-[10px] font-semibold uppercase tracking-wider text-foreground/80 font-sans">
                              {item.agent}
                            </span>
                            <ChevronRight className="h-2.5 w-2.5 text-muted-foreground" />
                            <span className="inline-flex items-center border border-border/50 px-1.5 py-0.5 text-[9px] font-mono uppercase tracking-wider text-muted-foreground">
                              {ACTION_LABELS[item.actionType] ??
                                item.actionType.toUpperCase()}
                            </span>
                            {item.target && (
                              <>
                                <ChevronRight className="h-2.5 w-2.5 text-muted-foreground/50" />
                                <span className="text-[9px] font-mono text-accent">
                                  {item.target}
                                </span>
                              </>
                            )}
                          </div>

                          <p className="mb-1.5 text-xs leading-relaxed text-foreground/80 font-sans">
                            {item.summary}
                          </p>

                          <div className="flex items-center gap-3 text-[9px] font-mono text-muted-foreground">
                            <span>T{item.turn}</span>
                            {item.rewardTotal !== null && (
                              <span
                                className={cn(
                                  item.rewardTotal >= 0
                                    ? "text-secondary"
                                    : "text-primary"
                                )}
                              >
                                {item.rewardTotal >= 0 ? "+" : ""}
                                {item.rewardTotal.toFixed(2)}
                              </span>
                            )}
                            <TensionIndicator delta={item.tensionDelta} />
                            {item.oversightTriggered && (
                              <div className="flex items-center gap-1 text-primary">
                                <Shield className="h-2.5 w-2.5" />
                                <span>OVERSIGHT</span>
                              </div>
                            )}
                          </div>
                        </div>
                      </div>
                    </div>
                  ))}
                </div>
              )}
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}