'use client' import type { ReactNode } from 'react' import { useHomeSearch } from '@/components/campaign/dashboard/HomeSearchContext' import { useHomeSearchResults } from '@/components/campaign/dashboard/HomeSearchResultsContext' import { HomeSearchSuggestSkeleton } from '@/components/campaign/dashboard/HomeSearchSuggestSkeleton' import { homeSearchHasAnyHits } from '@/lib/campaignHomeSearchHits' import { HOME_SEARCH_SUGGEST_EMPTY_MESSAGE } from '@/lib/campaignHomeSearchMessages' export const HomeSearchResultsShell = ({ children }: { children: ReactNode }) => { const { query } = useHomeSearch() const { results, resultKind, isFetching } = useHomeSearchResults() const hasRenderableHits = results.status === 'success' && homeSearchHasAnyHits(results.data) const showSkeleton = isFetching && !hasRenderableHits && results.status !== 'error' const showEmpty = query.isActive && resultKind === 'search' && !hasRenderableHits // `isFetching` keeps the message out of the debounce/skeleton window: while // the user starts typing from an empty suggest, the skeleton covers the // transition and the stale empty payload must not also speak (OPS29). const showSuggestEmpty = resultKind === 'suggest' && !hasRenderableHits && !isFetching return ( <> {showSkeleton ? : null} {!showSkeleton ? children : null} {results.status === 'error' ? (

{results.message}

) : null} {showEmpty ?

Nenhum resultado.

: null} {showSuggestEmpty ? (

{HOME_SEARCH_SUGGEST_EMPTY_MESSAGE}

) : null} ) }