"use client" import * as React from "react" import { useRouter } from "@/lib/router-compat" import { AskLeoComposer } from "@/components/ask-leo-composer" import { cn } from "@/lib/utils" export interface DedicatedSearchUrlComposerProps { /** Serialized `URLSearchParams` for the active route (stable string from parent). */ searchParamsKey: string /** Base path for `router.replace` (no query). */ replacePath: string /** * Merge submitted text into the next query string. Hub supplies domain rules * (e.g. preserve `scope=` / toggles while updating `q=`). */ patchSearchParams: (current: URLSearchParams, submittedText: string) => URLSearchParams /** Optional — record a successful non-empty submission (e.g. recents). */ onRecordSubmission?: (trimmed: string) => void /** `hero` — centered landing; `default` — inset under a list header. */ layout?: "default" | "hero" animatedPlaceholders: readonly string[] | string[] animatedPlaceholderIntervalMs?: number animatedPlaceholderMaxLines?: 1 | 2 placeholder?: string inputLabel?: string submitAppearance?: "search" | "send" submitButtonAriaLabel?: string /** Screen-reader-only instructions for the field (not the sole format hint). */ srOnlyDescription: React.ReactNode composerClassName?: string } /** * AI-styled composer that updates the URL via `router.replace` — does not open Ask Leo. */ export function DedicatedSearchUrlComposer({ searchParamsKey, replacePath, patchSearchParams, onRecordSubmission, layout = "default", animatedPlaceholders, animatedPlaceholderIntervalMs = 4800, animatedPlaceholderMaxLines = 2, placeholder = "Search…", inputLabel = "Search", submitAppearance = "search", submitButtonAriaLabel = "Run search", srOnlyDescription, composerClassName, }: DedicatedSearchUrlComposerProps) { const router = useRouter() const sp = React.useMemo(() => new URLSearchParams(searchParamsKey), [searchParamsKey]) const qFromUrl = sp.get("q") ?? "" const [value, setValue] = React.useState(qFromUrl) const [expanded, setExpanded] = React.useState(false) React.useEffect(() => { setValue(qFromUrl) }, [qFromUrl]) const onSubmit = React.useCallback( (message: string) => { const trimmed = message.trim() if (trimmed) onRecordSubmission?.(trimmed) const next = patchSearchParams(new URLSearchParams(searchParamsKey), trimmed) const qs = next.toString() router.replace(qs ? `${replacePath}?${qs}` : replacePath) }, [onRecordSubmission, patchSearchParams, replacePath, router, searchParamsKey], ) return (
{srOnlyDescription}