import { forwardRef, memo, useCallback, useState } from "react"; import { ChevronRight } from "lucide-react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Tooltip, TooltipContent, TooltipTrigger } from "@tutti-os/ui-system"; import { BareIconButton, type BareIconButtonProps } from "@tutti-os/ui-system/components"; import { CreateChatIcon, FolderIcon, FolderOpenLinedIcon, MoreHorizontalIcon } from "@tutti-os/ui-system/icons"; import type { ConversationSection } from "../agentGuiNodeViewConversation"; import styles from "../AgentGUINode.styles"; import type { AgentGUIConversationRailLabels } from "./agentGUIConversationRailLabels"; import { useAgentGUIConversationRailSectionBatchDeletionDisabled, useAgentGUIConversationRailSectionProjectActionLocked, useAgentGUIConversationRailSectionProjectDragDisabled } from "./agentGUIConversationRailSectionPresentationContext"; interface AgentGUIConversationRailSectionHeaderProps { canCreateConversation: boolean; createConversationDisabled: boolean; createConversationLabel: string; hasProjectId: boolean; hasProjectPath: boolean; isSectionCollapsed: boolean; kind: ConversationSection["kind"]; labels: AgentGUIConversationRailLabels; onCreateConversation: () => void; onOpenProjectFiles?: (() => void) | null; onProjectDragEnd: () => void; onProjectDragStart: (event: React.DragEvent) => void; onProjectMenuOpenChange: (open: boolean) => void; onRemoveProject: () => void; onRequestBatchDeletion: () => void; onToggleCollapsed: () => void; onToggleProjectPinned: () => void; projectPinned: boolean; projectId: string | null; sectionLabel: string; } interface HeaderFrameProps { children: React.ReactNode; isProjectSection: boolean; onProjectDragEnd: () => void; onProjectDragStart: (event: React.DragEvent) => void; } function HeaderFrame({ children, isProjectSection, onProjectDragEnd, onProjectDragStart }: HeaderFrameProps): React.JSX.Element { const projectDragDisabled = useAgentGUIConversationRailSectionProjectDragDisabled(); return (
{children}
); } interface HeaderIdentityProps { isProjectSection: boolean; isSectionCollapsed: boolean; labels: AgentGUIConversationRailLabels; onToggleCollapsed: () => void; projectPinned: boolean; sectionLabel: string; } const HeaderIdentity = memo(function HeaderIdentity({ isProjectSection, isSectionCollapsed, labels, onToggleCollapsed, projectPinned, sectionLabel }: HeaderIdentityProps): React.JSX.Element { "use memo"; if (!isProjectSection) { return (
{sectionLabel}
); } return ( ); }); interface CreateActionProps { createConversationDisabled: boolean; createConversationLabel: string; onCreateConversation: () => void; projectId: string | null; } const CreateAction = memo(function CreateAction({ createConversationDisabled, createConversationLabel, onCreateConversation, projectId }: CreateActionProps): React.JSX.Element { "use memo"; const button = ( ); return ( {button} {createConversationLabel} ); }); interface ProjectMenuTriggerProps { labels: AgentGUIConversationRailLabels; } type ProjectMenuButtonProps = Omit< BareIconButtonProps, "aria-label" | "children" | "size" > & { accessibleName: string; }; const ProjectMenuButton = forwardRef( function ProjectMenuButton( { accessibleName, disabled, ...props }, ref ): React.JSX.Element { const projectActionLocked = useAgentGUIConversationRailSectionProjectActionLocked(); return ( ); } ); ProjectMenuButton.displayName = "ProjectMenuButton"; function ProjectMenuTrigger({ labels }: ProjectMenuTriggerProps): React.JSX.Element { const accessibleName = labels.projectSectionMoreActions; return ( {accessibleName} ); } interface ProjectMenuContentProps { hasProjectId: boolean; labels: AgentGUIConversationRailLabels; onOpenProjectFiles?: (() => void) | null; onRemoveProject: () => void; onRequestBatchDeletion: () => void; onToggleProjectPinned: () => void; projectPinned: boolean; } function ProjectMenuContent({ hasProjectId, labels, onOpenProjectFiles, onRemoveProject, onRequestBatchDeletion, onToggleProjectPinned, projectPinned }: ProjectMenuContentProps): React.JSX.Element { const batchDeletionDisabled = useAgentGUIConversationRailSectionBatchDeletionDisabled(); const projectActionLocked = useAgentGUIConversationRailSectionProjectActionLocked(); return ( {labels.projectSectionViewFiles} {projectPinned ? labels.unpinProject : labels.pinProject} {labels.batchDeleteProjectSessions} {labels.removeProject} ); } interface ProjectMenuProps extends ProjectMenuContentProps { onOpenChange: (open: boolean) => void; open: boolean; } const ProjectMenu = memo(function ProjectMenu({ hasProjectId, labels, onOpenChange, onOpenProjectFiles, onRemoveProject, onRequestBatchDeletion, onToggleProjectPinned, open, projectPinned }: ProjectMenuProps): React.JSX.Element { "use memo"; return ( {open ? ( ) : null} ); }); interface ConversationMenuTriggerProps { labels: AgentGUIConversationRailLabels; } function ConversationMenuTrigger({ labels }: ConversationMenuTriggerProps): React.JSX.Element { const accessibleName = labels.conversationsSectionMoreActions; return ( {accessibleName} ); } interface ConversationMenuContentProps { labels: AgentGUIConversationRailLabels; onRequestBatchDeletion: () => void; } function ConversationMenuContent({ labels, onRequestBatchDeletion }: ConversationMenuContentProps): React.JSX.Element { const batchDeletionDisabled = useAgentGUIConversationRailSectionBatchDeletionDisabled(); return ( {labels.batchDeleteConversations} ); } interface ConversationMenuProps extends ConversationMenuContentProps { onOpenChange: (open: boolean) => void; open: boolean; } function ConversationMenu({ labels, onOpenChange, onRequestBatchDeletion, open }: ConversationMenuProps): React.JSX.Element { return ( {open ? ( ) : null} ); } export const AgentGUIConversationRailSectionHeader = memo( function AgentGUIConversationRailSectionHeader({ canCreateConversation, createConversationDisabled, createConversationLabel, hasProjectId, hasProjectPath, isSectionCollapsed, kind, labels, onCreateConversation, onOpenProjectFiles, onProjectDragEnd, onProjectDragStart, onProjectMenuOpenChange, onRemoveProject, onRequestBatchDeletion, onToggleCollapsed, onToggleProjectPinned, projectPinned, projectId, sectionLabel }: AgentGUIConversationRailSectionHeaderProps): React.JSX.Element { "use memo"; const [projectMenuOpen, setProjectMenuOpen] = useState(false); const [conversationMenuOpen, setConversationMenuOpen] = useState(false); const handleProjectMenuOpenChange = useCallback( (open: boolean) => { setProjectMenuOpen(open); onProjectMenuOpenChange(open); }, [onProjectMenuOpenChange] ); const isProjectSection = kind === "project"; return ( {canCreateConversation ? (
{hasProjectPath ? ( ) : null} {!hasProjectPath && kind === "conversations" ? ( ) : null}
) : null}
); } );