import { html, useState, useRef } from '../lib/preact.js'; import { getStatusMeta } from '../utils/status.js'; export function SimpleInput({ sessionId, status, onRespond }) { const [text, setText] = useState(''); const [focused, setFocused] = useState(false); const [sending, setSending] = useState(false); const [error, setError] = useState(null); const textareaRef = useRef(null); const meta = getStatusMeta(status); const handleSubmit = async (e) => { e.preventDefault(); e.stopPropagation(); if (text.trim() && !sending) { setSending(true); setError(null); try { await onRespond(sessionId, text.trim(), true, 0); setText(''); } catch (err) { setError('Failed to send message'); console.error('SimpleInput send error:', err); } finally { setSending(false); // Refocus the textarea after submission // Use setTimeout to ensure React has re-rendered with disabled=false setTimeout(() => { textareaRef.current?.focus(); }, 0); } } }; return html`
`; }