'use client' import type { ReactNode } from 'react' import { useHomeSearch } from '@/components/campaign/dashboard/HomeSearchContext' import { CampaignSearchInput } from '@/components/campaign/shared/CampaignSearchInput' import { HOME_SEARCH_QUERY_MAX_LENGTH } from '@/lib/schemas/homeSearch' const HOME_SEARCH_INPUT_ID = 'homeSearchQuery' const HOME_SEARCH_LABEL = 'Buscar na campanha' export const CampaignHomeSearch = ({ children, resultsBusy, }: { children?: ReactNode /** When set, must already fold debounce (see `useHomeSearchResultsState.isFetching`). */ resultsBusy?: boolean }) => { const { query, setRaw, clear, isDebouncing, setInputFocused } = useHomeSearch() const ariaBusy = (resultsBusy ?? isDebouncing) || undefined return (
setRaw(event.target.value)} onFocus={() => setInputFocused(true)} onBlur={() => { if (!query.isActive) { setInputFocused(false) } }} onKeyDown={(event) => { if (event.key === 'Escape') { event.preventDefault() clear() } }} autoComplete="off" enterKeyHint="search" aria-busy={ariaBusy} maxLength={HOME_SEARCH_QUERY_MAX_LENGTH} />
{children}
) }