import { memo, type PointerEventHandler } from "react"; import { ChevronDownIcon, ChevronLeftIcon } from "lucide-react"; import { cn } from "~/lib/utils"; import { Button } from "../ui/button"; import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu"; interface PendingActionState { questionIndex: number; isLastQuestion: boolean; canAdvance: boolean; isResponding: boolean; isComplete: boolean; } interface ComposerPrimaryActionsProps { compact: boolean; pendingAction: PendingActionState | null; isRunning: boolean; showPlanFollowUpPrompt: boolean; promptHasText: boolean; isSendBusy: boolean; isConnecting: boolean; isEnvironmentUnavailable: boolean; isPreparingWorktree: boolean; hasSendableContent: boolean; preserveComposerFocusOnPointerDown?: boolean; onPreviousPendingQuestion: () => void; onInterrupt: () => void; onImplementPlanInNewThread: () => void; } export const formatPendingPrimaryActionLabel = (input: { compact: boolean; isLastQuestion: boolean; isResponding: boolean; questionIndex: number; }) => { if (input.isResponding) { return "Submitting..."; } if (input.compact) { return input.isLastQuestion ? "Submit" : "Next"; } if (!input.isLastQuestion) { return "Next question"; } return input.questionIndex > 0 ? "Submit answers" : "Submit answer"; }; const preventPointerFocus: PointerEventHandler = (event) => { event.preventDefault(); }; export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({ compact, pendingAction, isRunning, showPlanFollowUpPrompt, promptHasText, isSendBusy, isConnecting, isEnvironmentUnavailable, isPreparingWorktree, hasSendableContent, preserveComposerFocusOnPointerDown = false, onPreviousPendingQuestion, onInterrupt, onImplementPlanInNewThread, }: ComposerPrimaryActionsProps) { const pointerFocusProps = preserveComposerFocusOnPointerDown ? { onPointerDown: preventPointerFocus } : undefined; if (pendingAction) { return (
{pendingAction.questionIndex > 0 ? ( compact ? ( ) : ( ) ) : null}
); } if (isRunning) { return ( ); } if (showPlanFollowUpPrompt) { if (promptHasText) { return ( ); } return (
} > void onImplementPlanInNewThread()} > Implement in a new thread
); } return ( ); });