import { useState } from 'react'; import { EXAMPLE_QUERIES } from '../constants'; interface QueryInputProps { onSearch: (query: string, intent?: string) => void; disabled: boolean; } export default function QueryInput({ onSearch, disabled }: QueryInputProps) { const [query, setQuery] = useState(''); const [intent, setIntent] = useState(''); const [showIntent, setShowIntent] = useState(false); function handleSubmit(e: React.FormEvent) { e.preventDefault(); const trimmed = query.trim(); if (trimmed) onSearch(trimmed, intent.trim() || undefined); } function handleExample(q: string, exIntent?: string) { setQuery(q); if (exIntent) { setIntent(exIntent); setShowIntent(true); } else { setIntent(''); setShowIntent(false); } onSearch(q, exIntent); } return (
setQuery(e.target.value)} disabled={disabled} placeholder={disabled ? 'Loading browser models\u2026' : 'Enter a search query\u2026'} style={{ width: '100%', padding: '0.6rem 0.9rem', fontSize: '1rem', fontFamily: 'system-ui, -apple-system, sans-serif', border: '1px solid var(--input-border)', borderRadius: '6px', background: disabled ? 'var(--bg-section)' : 'var(--bg-input)', color: disabled ? 'var(--text-muted)' : 'var(--text)', outline: 'none', transition: 'border-color 0.15s', }} onFocus={e => { if (!disabled) e.target.style.borderColor = '#4285F4'; }} onBlur={e => { e.target.style.borderColor = ''; }} /> {showIntent && ( setIntent(e.target.value)} disabled={disabled} placeholder="Intent: background context to disambiguate (e.g. 'web page load times')" style={{ width: '100%', padding: '0.45rem 0.9rem', fontSize: '0.85rem', fontFamily: 'system-ui, -apple-system, sans-serif', border: '1px solid var(--input-border)', borderRadius: '6px', background: disabled ? 'var(--bg-section)' : 'var(--bg-input)', color: disabled ? 'var(--text-muted)' : 'var(--text-secondary)', outline: 'none', transition: 'border-color 0.15s', }} onFocus={e => { if (!disabled) e.target.style.borderColor = '#f57f17'; }} onBlur={e => { e.target.style.borderColor = ''; }} /> )}
{!showIntent && ( )} {showIntent && !intent.trim() && ( )} Demo queries: {EXAMPLE_QUERIES.map(ex => ( ))}
); }