"use client"; import React from "react"; import { Loader2 } from "lucide-react"; import ExplorerLoading from "@/components/explorer/states/ExplorerLoading"; import ExplorerEmpty from "@/components/explorer/states/ExplorerEmpty"; import ExplorerError from "@/components/explorer/states/ExplorerError"; import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { sortSearchItems, SEARCH_RESULTS_SORT, } from "@/lib/frontend/search/resultsSorting"; import { useDebouncedVisibility } from "@/lib/frontend/hooks/useDebouncedVisibility"; import SearchResultsToolbar from "@/components/search/SearchResultsToolbar"; import SearchResultsTable from "@/components/search/SearchResultsTable"; const LOADING_DELAY_MS = 300; export default function SearchResults({ branch, status, items, total, error, onRetry, nextCursor, onLoadMore, isLoadingMore, loadMoreError, needsBranchSelection = false, }) { const [sortMode, setSortMode] = React.useState(SEARCH_RESULTS_SORT.RELEVANCE); const showLoadingUi = useDebouncedVisibility(status === "loading", { delayMs: LOADING_DELAY_MS, minVisibleMs: 0, }); const sortedItems = React.useMemo(() => { return sortSearchItems(items, sortMode); }, [items, sortMode]); if (status === "idle") { if (needsBranchSelection) { return ( ); } return ( ); } if (status === "error" && error) { // Validation errors are rendered in the SearchForm (near the inputs). if (error.kind === "validation") { return ( ); } return ( ); } // Debounced loading UI: // - If loading is very fast, do not show skeletons (prevents flicker). if (showLoadingUi) { return ; } if (status === "loading") { return