import { Pin, PinOff } from "lucide-react"; import { useQuery } from "@tanstack/react-query"; import { useMemo } from "react"; import { authApi } from "@/api/auth"; import { usePinnedNavigation } from "@/hooks/usePinnedNavigation"; import { queryKeys } from "@/lib/queryKeys"; import { cn } from "@/lib/utils"; export const agentChatPinKey = (companyId: string, agentId: string) => `agent-chat:${companyId}:${agentId}`; export function useAgentChatPins() { const session = useQuery({ queryKey: queryKeys.auth.session, queryFn: () => authApi.getSession() }); const userId = session.data?.user?.id ?? session.data?.session?.userId; const navigation = usePinnedNavigation(userId); const keys = useMemo(() => new Set(navigation.pins), [navigation.pins]); return { keys, toggle: navigation.toggle, canPin: navigation.canPin, error: navigation.error }; } export function AgentChatPin({ agent, pins, className }: { agent: { id: string; companyId: string; name: string }; pins: ReturnType; className?: string; }) { const key = agentChatPinKey(agent.companyId, agent.id); const pinned = pins.keys.has(key); const Icon = pinned ? PinOff : Pin; return <> {pins.error && {pins.error}} ; }