import React from 'react'; import { Keyboard, ScrollView, Text, TextInput, View } from 'react-native'; import { ChevronDown, ChevronLeft, ChevronRight, ChevronUp } from 'lucide-react-native'; import { conversationStyles } from '../../features/conversation/conversationStyles'; import { themedColor } from '../../theme'; import type { SuperagentToolCall, SuperagentToolRendererProps } from '../../types'; import { toolWidgetStyles } from '../primitives/toolWidgetStyles'; import { FallbackActionCard, SelectableOptionRow, TinyIconButton, WidgetActionButton, } from '../widgets/interactiveWidgetParts'; import { changeCustomText, getRegularOptions, isOptionSelected, selectOption } from './questionsUtils'; import { useClarifyingQuestions } from './useClarifyingQuestions'; /** * The clarification form, rendered in place of the composer while a question is * pending (ConversationChat) as it is on web — so the question can't scroll away, * its free-text field gets the composer's keyboard handling, and the user can't * start a turn the backend has parked behind this answer. */ export function ClarifyingQuestionsCard({ isCollapsed = false, isKeyboardVisible, maxHeight, onToggleCollapsed, submitToolCallInput, toolCall, }: { /** Minimized to just the question — owned by the caller, which swaps in the composer. */ isCollapsed?: boolean; /** Hides the description and nav row while typing "Something else", to free up space above the keyboard. */ isKeyboardVisible?: boolean; /** Caps the whole card so it can't push its nav row off-screen; only the option list scrolls. */ maxHeight?: number; onToggleCollapsed?: () => void; submitToolCallInput: SuperagentToolRendererProps['submitToolCallInput']; toolCall: SuperagentToolCall; }) { const { canAct, collapseForKeyboard, currentIndex, customInputRef, error, goBack, goNext, isComplete, isFirst, isLast, isSubmitting, onCustomInputBlur, onCustomInputFocus, pressCustomRow, question, questions, scrollRef, skipCurrent, somethingElse, state, submitAnswers, updateCurrent, } = useClarifyingQuestions({ isKeyboardVisible, submitToolCallInput, toolCall }); if (!question) { return ( ); } const options = getRegularOptions(question); return ( {question.question || 'A quick question'} {})} /> {isCollapsed ? null : ( {question.description ? ( {question.description} ) : null} {options.map((option) => ( { // keyboardShouldPersistTaps="handled" lets this row's press through without // dismissing the "Something else" input first — do it explicitly. Keyboard.dismiss(); updateCurrent(selectOption(question, state, option.label)); }} selected={isOptionSelected(question, state, option.label)} subtitle={option.description ?? option.subtitle ?? null} /> ))} updateCurrent(changeCustomText(question, state, text))} onFocus={onCustomInputFocus} placeholder="Write your own answer here" ref={customInputRef} placeholderTextColor={themedColor('#6F6F76')} style={[conversationStyles.toolApprovalInput, toolWidgetStyles.clarifyingCustomInput]} value={state.customText} /> )} {collapseForKeyboard || isCollapsed ? null : ( {questions.length > 1 ? ( <> {currentIndex + 1}/{questions.length} ) : null} )} {error ? {error} : null} ); }