import { useEffect, useRef } from 'react' import { cn } from '@/lib/utils' interface Props { onSubmit: (query: string) => void disabled?: boolean className?: string defaultValue?: string } export function SearchBox({ onSubmit, disabled, className, defaultValue }: Props) { const ref = useRef(null) // Cmd+K / Ctrl+K → focus from anywhere useEffect(() => { const handler = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault() ref.current?.focus() } } window.addEventListener('keydown', handler) return () => window.removeEventListener('keydown', handler) }, []) const submit = () => { const value = ref.current?.value.trim() if (value) { onSubmit(value) if (ref.current) ref.current.value = '' } } return (
e.key === 'Enter' && submit()} className="flex-1 bg-transparent text-sm outline-none placeholder:text-stone-400 disabled:opacity-60" aria-label="Query input" />
) }