"use client"; import { useState, type FormEvent } from "react"; import type { SearchEngine, Widget } from "@/lib/config/schema"; type SearchWidget = Extract; const ENGINE_URLS: Record = { duckduckgo: "https://duckduckgo.com/?q=", google: "https://www.google.com/search?q=", bing: "https://www.bing.com/search?q=", }; export function SearchWidget({ widget }: { widget: SearchWidget }) { const [engine, setEngine] = useState(widget.defaultEngine ?? widget.engines[0]); const [query, setQuery] = useState(""); function handleSubmit(event: FormEvent) { event.preventDefault(); const trimmed = query.trim(); if (!trimmed) return; window.open(`${ENGINE_URLS[engine]}${encodeURIComponent(trimmed)}`, "_blank", "noreferrer"); } return (
{widget.engines.length > 1 && ( )} setQuery(event.target.value)} placeholder="Search..." className="flex-1 bg-transparent text-sm text-fg outline-none placeholder:text-fg-muted" />
); }