"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 SearchResultsToolbar from "@/components/search/SearchResultsToolbar";
import SearchResultsTable from "@/components/search/SearchResultsTable";
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 sortedItems = React.useMemo(() => {
return sortSearchItems(items, sortMode);
}, [items, sortMode]);
if (status === "idle") {
if (needsBranchSelection) {
return (