import { useEffect, useRef } from "react"; import type { AgentProfile } from "../types"; import type { RosterLayout } from "../rosterLayout"; import { AgentRoster } from "./AgentRoster"; interface Props { agents: AgentProfile[]; defaultModel?: string; open: boolean; onOpenChange: (open: boolean) => void; dragActive?: boolean; dropHighlight?: boolean; rosterRef: React.RefObject; rosterLayout: RosterLayout; sectionDropHoverId?: string | null; onAgentDragStart?: (e: React.MouseEvent, agentId: string, color?: string) => void; onAgentEdit?: (agent: AgentProfile) => void; onDefaultEdit?: () => void; onCreateAgent?: () => void; } const HEADER_H = 57; export function AgentRosterMenu({ agents, defaultModel, open, onOpenChange, dragActive, dropHighlight, rosterRef, rosterLayout, sectionDropHoverId, onAgentDragStart, onAgentEdit, onDefaultEdit, onCreateAgent, }: Props) { const wrapRef = useRef(null); const highlighted = Boolean(dragActive && dropHighlight); useEffect(() => { if (dragActive && dropHighlight) onOpenChange(true); }, [dragActive, dropHighlight, onOpenChange]); useEffect(() => { if (!open || dragActive) return; function onDoc(e: MouseEvent) { const t = e.target as Node; if (wrapRef.current?.contains(t)) return; if (rosterRef.current?.contains(t)) return; onOpenChange(false); } window.addEventListener("mousedown", onDoc); return () => window.removeEventListener("mousedown", onDoc); }, [open, dragActive, onOpenChange, rosterRef]); return ( <>
{open && ( <>
{ if (!dragActive) onOpenChange(false); }} />
} style={{ position: "fixed", top: HEADER_H, right: 0, bottom: 0, zIndex: 500, width: "min(380px, 92vw)", borderLeft: highlighted ? "2px dashed var(--accent2)" : "1px solid #2a3558", background: "#16213e", boxShadow: "-8px 0 32px rgba(0,0,0,0.45)", display: "flex", flexDirection: "column", animation: "rosterSlideIn 0.22s ease-out", }} >
Agent Profiles
)} ); }