"use client"; import React from "react"; import Link from "next/link"; import { Eye, FolderOpen, Loader2, SlidersHorizontal } from "lucide-react"; import { SEARCH_SCOPE } from "@/lib/frontend/search/urlState"; import { dayPath } from "@/lib/frontend/routes"; import { buildPdfUrl } from "@/lib/frontend/explorer/pdfUrl"; 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 { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; const SORT = Object.freeze({ RELEVANCE: "relevance", DATE_DESC: "date_desc", FILENAME_ASC: "filename_asc", }); function toDateKey(it) { const y = String(it?.year || ""); const m = String(it?.month || "").padStart(2, "0"); const d = String(it?.day || "").padStart(2, "0"); return `${y}-${m}-${d}`; } function formatDateDe(it) { const y = String(it?.year || ""); const m = String(it?.month || "").padStart(2, "0"); const d = String(it?.day || "").padStart(2, "0"); return `${d}.${m}.${y}`; } export default function SearchResults({ branch, scope, status, items, error, onRetry, nextCursor, onLoadMore, isLoadingMore, loadMoreError, }) { const showBranchColumn = scope === SEARCH_SCOPE.ALL || scope === SEARCH_SCOPE.MULTI; const [sortMode, setSortMode] = React.useState(SORT.RELEVANCE); const sortedItems = React.useMemo(() => { const arr = Array.isArray(items) ? [...items] : []; if (sortMode === SORT.RELEVANCE) return arr; if (sortMode === SORT.DATE_DESC) { return arr.sort((a, b) => { const da = toDateKey(a); const db = toDateKey(b); if (da !== db) return da < db ? 1 : -1; const fa = String(a?.filename || ""); const fb = String(b?.filename || ""); return fa.localeCompare(fb, "de"); }); } if (sortMode === SORT.FILENAME_ASC) { return arr.sort((a, b) => String(a?.filename || "").localeCompare(String(b?.filename || ""), "de") ); } return arr; }, [items, sortMode]); if (status === "idle") { return ( ); } if (status === "loading") { return ; } if (status === "error" && error) { return ( ); } const list = Array.isArray(sortedItems) ? sortedItems : []; if (list.length === 0) { return ( ); } return (
{list.length} Treffer (aktuell geladen)
Sortierung setSortMode(value)} > Relevanz Datum (neueste zuerst) Dateiname (A–Z)
Hinweis: PDFs werden in einem neuen Tab geöffnet. {showBranchColumn ? Niederlassung : null} Datum Datei Pfad Aktion {list.map((it) => { const itemBranch = String(it?.branch || branch); const year = String(it?.year || ""); const month = String(it?.month || ""); const day = String(it?.day || ""); const filename = String(it?.filename || ""); const relativePath = String(it?.relativePath || ""); const snippet = typeof it?.snippet === "string" && it.snippet.trim() ? it.snippet.trim() : null; const pdfUrl = buildPdfUrl({ branch: itemBranch, year, month, day, filename, }); const dayHref = dayPath(itemBranch, year, month, day); return ( {showBranchColumn ? ( {itemBranch} ) : null} {formatDateDe(it)}

{filename}

{snippet ? (

{snippet}

) : null}

{relativePath}

{relativePath}
); })}
{loadMoreError ? ( {loadMoreError.title} {loadMoreError.description} ) : null} {nextCursor ? (
) : null}
); }