"use client" import { useState, useEffect } from "react" import { motion, AnimatePresence, Reorder } from "framer-motion" import { Trash2, MessageSquare, GripVertical } from "lucide-react" import type { PinnedAgent } from "@/lib/types" import { Button } from "@/components/ui/button" interface PinnedAgentsDrawerProps { isOpen: boolean onClose: () => void onSelectAgent: (agent: PinnedAgent) => void activeAgentId?: string // Highlight the currently active agent } export function PinnedAgentsDrawer({ isOpen, onClose, onSelectAgent, activeAgentId }: PinnedAgentsDrawerProps) { const [agents, setAgents] = useState([]) const [isMobile, setIsMobile] = useState(true) // Assume mobile until we can check const [draggingId, setDraggingId] = useState(null) // Detect mobile vs desktop useEffect(() => { const checkMobile = () => { setIsMobile(window.innerWidth < 640) } // Check immediately on mount if (typeof window !== "undefined") { checkMobile() } window.addEventListener("resize", checkMobile) return () => window.removeEventListener("resize", checkMobile) }, []) // Load pinned agents from localStorage useEffect(() => { if (isOpen) { const stored = localStorage.getItem("pinned-agents") if (stored) { try { const parsed = JSON.parse(stored) setTimeout(() => { setAgents(parsed) }, 0) } catch (error) { console.error("Failed to parse pinned agents:", error) } } } }, [isOpen]) // Save agents to localStorage when order changes const handleReorder = (newOrder: PinnedAgent[]) => { setAgents(newOrder) localStorage.setItem("pinned-agents", JSON.stringify(newOrder)) } // Remove agent from pinned list const handleRemove = (agentId: string) => { const updated = agents.filter((a) => a.agentId !== agentId) setAgents(updated) localStorage.setItem("pinned-agents", JSON.stringify(updated)) } // Start chat with selected agent const handleStartChat = (agent: PinnedAgent) => { onSelectAgent(agent) onClose() } return ( {isOpen && ( <> {/* Backdrop - mobile only */} {/* Drawer */} {/* Drag handle indicator - mobile only */}
{/* Header */}

Pinned Agents

{agents.length} {agents.length === 1 ? "correspondent" : "correspondents"}

{/* Agent list */}
{agents.length === 0 ? (

No pinned agents yet

Ask Morgan to create a custom agent and pin it for quick access

) : ( {agents.map((agent) => ( setDraggingId(agent.agentId)} onDragEnd={() => setDraggingId(null)} > {/* Drag handle */}
{/* Agent header */}
{agent.recommendedIcon || "🤖"}

{agent.displayName}

{/* Handle & Summary - shown on hover */}

@{agent.agentId}

{agent.summary && (

{agent.summary}

)}
{/* Action button */}
))}
)}
)} ) }