import { ChangeEvent, KeyboardEvent, useCallback, useEffect, useRef } from 'react' import { Button, ExpandingTextArea } from 'ui' interface AskAIWidgetProps { value: string onChange: (value: string) => void onSubmit: (prompt: string) => void onAccept?: () => void onReject?: () => void onCancel?: () => void isDiffVisible: boolean isLoading?: boolean } export const AskAIWidget = ({ value, onChange, onSubmit, onAccept, onReject, onCancel, isDiffVisible, isLoading = false, }: AskAIWidgetProps) => { const textAreaRef = useRef(null) useEffect(() => { setTimeout(() => { textAreaRef.current?.focus() textAreaRef.current?.setSelectionRange(value.length, value.length) }, 100) }, []) const handleSubmit = useCallback(() => { if (value.trim() && !isLoading) { onSubmit(value) } }, [value, isLoading, onSubmit]) const handleChange = useCallback( (e: ChangeEvent) => { onChange(e.target.value) }, [onChange] ) const handleKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey && !e.metaKey && !e.ctrlKey) { e.preventDefault() handleSubmit() } }, [handleSubmit] ) return (
{isDiffVisible ? (
) : (
)}
) }