import { c as _c } from "react/compiler-runtime"; import figures from 'figures'; import React, { useCallback, useState } from 'react'; import type { KeyboardEvent } from '../../../ink/events/keyboard-event.js'; import { Box, Text } from '../../../ink.js'; import { useAppState } from '../../../state/AppState.js'; import type { Question, QuestionOption } from '../../../tools/AskUserQuestionTool/AskUserQuestionTool.js'; import type { PastedContent } from '../../../utils/config.js'; import { getExternalEditor } from '../../../utils/editor.js'; import { toIDEDisplayName } from '../../../utils/ide.js'; import type { ImageDimensions } from '../../../utils/imageResizer.js'; import { editPromptInEditor } from '../../../utils/promptEditor.js'; import { type OptionWithDescription, Select, SelectMulti } from '../../CustomSelect/index.js'; import { Divider } from '../../design-system/Divider.js'; import { FilePathLink } from '../../FilePathLink.js'; import { PermissionRequestTitle } from '../PermissionRequestTitle.js'; import { PreviewQuestionView } from './PreviewQuestionView.js'; import { QuestionNavigationBar } from './QuestionNavigationBar.js'; import type { QuestionState } from './use-multiple-choice-state.js'; type Props = { question: Question; questions: Question[]; currentQuestionIndex: number; answers: Record; questionStates: Record; hideSubmitTab?: boolean; planFilePath?: string; pastedContents?: Record; minContentHeight?: number; minContentWidth?: number; onUpdateQuestionState: (questionText: string, updates: Partial, isMultiSelect: boolean) => void; onAnswer: (questionText: string, label: string | string[], textInput?: string, shouldAdvance?: boolean) => void; onTextInputFocus: (isInInput: boolean) => void; onCancel: () => void; onSubmit: () => void; onTabPrev?: () => void; onTabNext?: () => void; onRespondToClaude: () => void; onFinishPlanInterview: () => void; onImagePaste?: (base64Image: string, mediaType?: string, filename?: string, dimensions?: ImageDimensions, sourcePath?: string) => void; onRemoveImage?: (id: number) => void; }; export function QuestionView(t0) { const $ = _c(114); const { question, questions, currentQuestionIndex, answers, questionStates, hideSubmitTab: t1, planFilePath, minContentHeight, minContentWidth, onUpdateQuestionState, onAnswer, onTextInputFocus, onCancel, onSubmit, onTabPrev, onTabNext, onRespondToClaude, onFinishPlanInterview, onImagePaste, pastedContents, onRemoveImage } = t0; const hideSubmitTab = t1 === undefined ? false : t1; const isInPlanMode = useAppState(_temp) === "plan"; const [isFooterFocused, setIsFooterFocused] = useState(false); const [footerIndex, setFooterIndex] = useState(0); const [isOtherFocused, setIsOtherFocused] = useState(false); let t2; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const editor = getExternalEditor(); t2 = editor ? toIDEDisplayName(editor) : null; $[0] = t2; } else { t2 = $[0]; } const editorName = t2; let t3; if ($[1] !== onTextInputFocus) { t3 = value => { const isOther = value === "__other__"; setIsOtherFocused(isOther); onTextInputFocus(isOther); }; $[1] = onTextInputFocus; $[2] = t3; } else { t3 = $[2]; } const handleFocus = t3; let t4; if ($[3] === Symbol.for("react.memo_cache_sentinel")) { t4 = () => { setIsFooterFocused(true); }; $[3] = t4; } else { t4 = $[3]; } const handleDownFromLastItem = t4; let t5; if ($[4] === Symbol.for("react.memo_cache_sentinel")) { t5 = () => { setIsFooterFocused(false); }; $[4] = t5; } else { t5 = $[4]; } const handleUpFromFooter = t5; let t6; if ($[5] !== footerIndex || $[6] !== isFooterFocused || $[7] !== isInPlanMode || $[8] !== onCancel || $[9] !== onFinishPlanInterview || $[10] !== onRespondToClaude) { t6 = e => { if (!isFooterFocused) { return; } if (e.key === "up" || e.ctrl && e.key === "p") { e.preventDefault(); if (footerIndex === 0) { handleUpFromFooter(); } else { setFooterIndex(0); } return; } if (e.key === "down" || e.ctrl && e.key === "n") { e.preventDefault(); if (isInPlanMode && footerIndex === 0) { setFooterIndex(1); } return; } if (e.key === "return") { e.preventDefault(); if (footerIndex === 0) { onRespondToClaude(); } else { onFinishPlanInterview(); } return; } if (e.key === "escape") { e.preventDefault(); onCancel(); } }; $[5] = footerIndex; $[6] = isFooterFocused; $[7] = isInPlanMode; $[8] = onCancel; $[9] = onFinishPlanInterview; $[10] = onRespondToClaude; $[11] = t6; } else { t6 = $[11]; } const handleKeyDown = t6; let handleOpenEditor; let questionText; let t7; if ($[12] !== onUpdateQuestionState || $[13] !== question || $[14] !== questionStates) { const textOptions = question.options.map(_temp2); questionText = question.question; const questionState = questionStates[questionText]; let t8; if ($[18] !== onUpdateQuestionState || $[19] !== question.multiSelect || $[20] !== questionText) { t8 = async (currentValue, setValue) => { const result = await editPromptInEditor(currentValue); if (result.content !== null && result.content !== currentValue) { setValue(result.content); onUpdateQuestionState(questionText, { textInputValue: result.content }, question.multiSelect ?? false); } }; $[18] = onUpdateQuestionState; $[19] = question.multiSelect; $[20] = questionText; $[21] = t8; } else { t8 = $[21]; } handleOpenEditor = t8; const t9 = question.multiSelect ? "Type something" : "Type something."; const t10 = questionState?.textInputValue ?? ""; let t11; if ($[22] !== onUpdateQuestionState || $[23] !== question.multiSelect || $[24] !== questionText) { t11 = value_0 => { onUpdateQuestionState(questionText, { textInputValue: value_0 }, question.multiSelect ?? false); }; $[22] = onUpdateQuestionState; $[23] = question.multiSelect; $[24] = questionText; $[25] = t11; } else { t11 = $[25]; } let t12; if ($[26] !== t10 || $[27] !== t11 || $[28] !== t9) { t12 = { type: "input" as const, value: "__other__", label: "Other", placeholder: t9, initialValue: t10, onChange: t11 }; $[26] = t10; $[27] = t11; $[28] = t9; $[29] = t12; } else { t12 = $[29]; } const otherOption = t12; t7 = [...textOptions, otherOption]; $[12] = onUpdateQuestionState; $[13] = question; $[14] = questionStates; $[15] = handleOpenEditor; $[16] = questionText; $[17] = t7; } else { handleOpenEditor = $[15]; questionText = $[16]; t7 = $[17]; } const options = t7; const hasAnyPreview = !question.multiSelect && question.options.some(_temp3); if (hasAnyPreview) { let t8; if ($[30] !== answers || $[31] !== currentQuestionIndex || $[32] !== hideSubmitTab || $[33] !== minContentHeight || $[34] !== minContentWidth || $[35] !== onAnswer || $[36] !== onCancel || $[37] !== onFinishPlanInterview || $[38] !== onRespondToClaude || $[39] !== onTabNext || $[40] !== onTabPrev || $[41] !== onTextInputFocus || $[42] !== onUpdateQuestionState || $[43] !== question || $[44] !== questionStates || $[45] !== questions) { t8 = ; $[30] = answers; $[31] = currentQuestionIndex; $[32] = hideSubmitTab; $[33] = minContentHeight; $[34] = minContentWidth; $[35] = onAnswer; $[36] = onCancel; $[37] = onFinishPlanInterview; $[38] = onRespondToClaude; $[39] = onTabNext; $[40] = onTabPrev; $[41] = onTextInputFocus; $[42] = onUpdateQuestionState; $[43] = question; $[44] = questionStates; $[45] = questions; $[46] = t8; } else { t8 = $[46]; } return t8; } let t8; if ($[47] !== isInPlanMode || $[48] !== planFilePath) { t8 = isInPlanMode && planFilePath && Planning: ; $[47] = isInPlanMode; $[48] = planFilePath; $[49] = t8; } else { t8 = $[49]; } let t9; if ($[50] === Symbol.for("react.memo_cache_sentinel")) { t9 = ; $[50] = t9; } else { t9 = $[50]; } let t10; if ($[51] !== answers || $[52] !== currentQuestionIndex || $[53] !== hideSubmitTab || $[54] !== questions) { t10 = ; $[51] = answers; $[52] = currentQuestionIndex; $[53] = hideSubmitTab; $[54] = questions; $[55] = t10; } else { t10 = $[55]; } let t11; if ($[56] !== question.question) { t11 = ; $[56] = question.question; $[57] = t11; } else { t11 = $[57]; } let t12; if ($[58] !== currentQuestionIndex || $[59] !== handleFocus || $[60] !== handleOpenEditor || $[61] !== isFooterFocused || $[62] !== onAnswer || $[63] !== onCancel || $[64] !== onImagePaste || $[65] !== onRemoveImage || $[66] !== onSubmit || $[67] !== onUpdateQuestionState || $[68] !== options || $[69] !== pastedContents || $[70] !== question.multiSelect || $[71] !== question.question || $[72] !== questionStates || $[73] !== questionText || $[74] !== questions.length) { t12 = {question.multiSelect ? { onUpdateQuestionState(questionText, { selectedValue: values }, true); const textInput = values.includes("__other__") ? questionStates[questionText]?.textInputValue : undefined; const finalValues = values.filter(_temp4).concat(textInput ? [textInput] : []); onAnswer(questionText, finalValues, undefined, false); }} onFocus={handleFocus} onCancel={onCancel} submitButtonText={currentQuestionIndex === questions.length - 1 ? "Submit" : "Next"} onSubmit={onSubmit} onDownFromLastItem={handleDownFromLastItem} isDisabled={isFooterFocused} onOpenEditor={handleOpenEditor} onImagePaste={onImagePaste} pastedContents={pastedContents} onRemoveImage={onRemoveImage} /> :