"use client";
import React from "react";
import Link from "next/link";
import { Eye, FolderOpen } from "lucide-react";
import { dayPath } from "@/lib/frontend/routes";
import { buildPdfUrl } from "@/lib/frontend/explorer/pdfUrl";
import { formatSearchItemDateDe } from "@/lib/frontend/search/resultsSorting";
import { Button } from "@/components/ui/button";
import {
Table,
TableBody,
TableCaption,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
export default function SearchResultsTable({ routeBranch, scope, items }) {
// NOTE:
// - We intentionally keep the column set stable:
// Branch | Date | File | Path | Actions
// - For single-scope searches, all rows will show the same branch (routeBranch),
// but the consistent layout improves scanability and avoids “column jumping”.
const list = Array.isArray(items) ? items : [];
return (
Hinweis: PDFs werden in einem neuen Tab geöffnet.
{/* Fixed-width columns keep the layout stable and prevent “action column drift”. */}
Niederlassung
Datum
{/* Flexible columns: these must truncate to prevent horizontal scrolling. */}
Datei
Pfad
{/* Fixed actions column so buttons are always reachable without scrolling. */}
Aktionen
{list.map((it) => {
const itemBranch = String(it?.branch || routeBranch);
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 || "");
// Binary PDF endpoint: open in a new tab (do NOT fetch via apiClient).
const pdfUrl = buildPdfUrl({
branch: itemBranch,
year,
month,
day,
filename,
});
const dayHref = dayPath(itemBranch, year, month, day);
// Stable key: relativePath is best; fallback is deterministic.
const key =
relativePath || `${itemBranch}/${year}/${month}/${day}/${filename}`;
return (
{itemBranch}
{formatSearchItemDateDe(it)}
{/* File column: must be shrinkable so truncate works in table-fixed layout. */}
{filename}
{/* Mobile: show path as secondary line instead of a dedicated column */}
{relativePath}
{/* Path column (desktop): always truncate + title for full hover read. */}
{relativePath}
{/* Actions: fixed-width column, buttons stacked to keep width small and stable. */}
);
})}
);
}