import { useState, useEffect } from 'react' interface Props { isOpen: boolean onClose: () => void onSelect: (suggestion: string) => void userInput: string } export default function SuggestionsModal({ isOpen, onClose, onSelect, userInput }: Props) { const [suggestions, setSuggestions] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState('') const fetchSuggestions = async () => { if (!userInput.trim()) return setLoading(true) setError('') try { const res = await fetch('/api/text-gen/suggest', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ input: userInput }), }) if (!res.ok) { const err = await res.json() throw new Error(err.detail || 'Failed to get suggestions') } const data = await res.json() setSuggestions(data.suggestions || []) } catch (e) { setError(e instanceof Error ? e.message : 'Failed to get suggestions') } finally { setLoading(false) } } // Auto-fetch when opened useEffect(() => { if (isOpen && suggestions.length === 0 && !loading && !error) { fetchSuggestions() } }, [isOpen]) if (!isOpen) return null return (
{/* Header */}

Prompt Suggestions

{userInput}

{/* Content */}
{loading && (
)} {error && (

{error}

)} {!loading && !error && suggestions.length === 0 && (

No suggestions yet. Click below to generate.

)}
{suggestions.map((suggestion, i) => ( ))}
) }