import { Search } from "lucide-react" import { useState } from "react" interface SearchFormProps { onSearch: (results: any[]) => void; onSearchingChange: (isSearching: boolean) => void; } export function SearchForm({ onSearch, onSearchingChange }: SearchFormProps) { const [query, setQuery] = useState("") const [error, setError] = useState(null) const handleSearch = async (e: React.FormEvent) => { e.preventDefault() if (!query.trim()) return setError(null) onSearchingChange(true) try { const response = await fetch("/api/search", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ query: query.trim() }), }) if (!response.ok) { throw new Error("Search failed") } const data = await response.json() onSearch(data.results || []) } catch (error) { console.error("Search error:", error) onSearch([]) setError("Failed to perform search. Please try again.") } finally { onSearchingChange(false) } } return (
setQuery(e.target.value)} placeholder="e.g. plumbers in Denver, CO" className="w-full px-4 py-3 text-lg rounded-lg border border-border bg-background focus:outline-none focus:ring-2 focus:ring-primary" />
{error && (

{error}

)}

Try searching for: restaurants, dentists, electricians, etc.

) }