import React from 'react'; import { Checkbox } from '@/components/ui/checkbox'; import { Radio } from '@/components/ui/radio'; import { Icon } from "@/components/icon/Icon"; import { cn } from '@/lib/utils'; import { isIMECompositionEvent } from '@/lib/ime'; import { copyTextToClipboard } from '@/lib/clipboard'; import { toast } from '@/components/ui'; import type { QuestionRequest } from '@/types/question'; import { useUIStore } from '@/stores/useUIStore'; import { useSessionUIStore } from '@/sync/session-ui-store'; import { useSessions } from '@/sync/sync-context'; import * as sessionActions from '@/sync/session-actions'; import { useI18n } from '@/lib/i18n'; import { serializeQuestionAsJson, serializeQuestionAsMarkdown } from './questionSerializers'; import { QUESTION_CUSTOM_TEXTAREA_MIN_HEIGHT, getQuestionCustomTextareaHeight } from './questionTextareaSizing'; interface QuestionCardProps { question: QuestionRequest; } type TabKey = string; const SUMMARY_TAB = 'summary'; interface CustomAnswerTextareaProps { value: string; placeholder: string; disabled: boolean; onValueChange: (value: string) => void; onKeyDown: (event: React.KeyboardEvent) => void; } const CustomAnswerTextarea = React.memo(function CustomAnswerTextarea({ value, placeholder, disabled, onValueChange, onKeyDown, }: CustomAnswerTextareaProps) { const textareaRef = React.useRef(null); const [localValue, setLocalValue] = React.useState(value); const [height, setHeight] = React.useState(QUESTION_CUSTOM_TEXTAREA_MIN_HEIGHT); const [isScrollable, setIsScrollable] = React.useState(false); React.useEffect(() => { setLocalValue(value); }, [value]); React.useLayoutEffect(() => { const textarea = textareaRef.current; if (!textarea) return; const nextHeight = getQuestionCustomTextareaHeight({ scrollHeight: textarea.scrollHeight, currentHeight: height, }); const nextScrollable = textarea.scrollHeight > (nextHeight ?? height); if (isScrollable !== nextScrollable) { setIsScrollable(nextScrollable); } if (nextHeight !== null) { setHeight(nextHeight); } }, [height, isScrollable, localValue]); return (