"use client"; import { useState, type FormEvent } from "react"; import type { SearchEngine, Widget } from "@/lib/config/schema"; import { WidgetCard } from "@/components/widgets/WidgetCard"; 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=", }; const ENGINE_LABEL: Record = { duckduckgo: "DuckDuckGo", google: "Google", bing: "Bing", }; 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 (
Search
setQuery(event.target.value)} placeholder="Search the web…" autoComplete="off" className="min-h-9 w-full rounded-md border border-border bg-bg px-2.5 py-1.5 text-sm text-fg outline-none placeholder:text-fg-muted focus-visible:border-accent" /> {widget.engines.length > 1 && (
{widget.engines.map((option) => ( ))}
)}
); }