import { useEffect, useRef, type ReactNode } from 'react' import { Boxes, Milestone, X } from 'lucide-react' import type { WorkflowNodeDefinition } from '../../api/workflows' import type { WorkflowGraphFamily } from './workflowNodeLibrary' import { WorkflowAuthoringSectionContent } from './WorkflowAuthoringSectionContent' import { WorkflowAuthoringSectionSelector } from './WorkflowAuthoringSectionSelector' import { type WorkflowAuthoringActions, type WorkflowAuthoringPosition, } from './workflowAuthoringActions' import { useWorkflowAuthoringSurface } from './workflowAuthoringSurface' export const NODE_COMMAND_MENU_WIDTH = 380 interface NodeCommandMenuProps { definitions: WorkflowNodeDefinition[] graphFamily: WorkflowGraphFamily activeSteps?: string[] actions: WorkflowAuthoringActions preferredPosition?: WorkflowAuthoringPosition onClose: () => void renderIcon: (iconName?: string, size?: number) => ReactNode } export function NodeCommandMenu({ definitions, graphFamily, activeSteps = [], actions, preferredPosition, onClose, renderIcon, }: NodeCommandMenuProps) { const containerRef = useRef(null) const { activeSection, activeSectionDetail, chrome, insertBindings, plan, sections, setActiveSection } = useWorkflowAuthoringSurface({ definitions, graphFamily, activeSteps, actions, preferredPosition, onAfterInsert: onClose, }) useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') { onClose() } } window.addEventListener('keydown', handleKeyDown) return () => window.removeEventListener('keydown', handleKeyDown) }, [onClose]) useEffect(() => { const handlePointerDown = (event: PointerEvent) => { if (!containerRef.current) return if (containerRef.current.contains(event.target as Node)) return onClose() } window.addEventListener('pointerdown', handlePointerDown) return () => window.removeEventListener('pointerdown', handlePointerDown) }, [onClose]) return (

{chrome.menuTitle}

{activeSteps.length} on canvas {plan.referenceBundles.length > 0 && ( {plan.referenceBundles.length} paths )} {plan.moduleBundles.length > 0 && ( {plan.moduleBundles.length} modules )} Esc closes

{chrome.menuHelper}

{chrome.guideEyebrow}

{activeSectionDetail?.helper ?? chrome.guideHelper}

{activeSectionDetail?.label ?? activeSectionDetail?.tone ?? 'Guided'}
) }