"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, 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 : [];
// UI fix:
// - In `table-fixed` layouts, the action column must be wide enough for two buttons.
// - We keep the buttons content-sized (no hard w-36 per button) and prevent shrink.
const ACTIONS_COL_WIDTH = "w-56"; // ~14rem (tweak to w-52/w-60 if you prefer)
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: wide enough for two buttons side-by-side */}
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: side-by-side, right-aligned, no fixed per-button width */}
);
})}
);
}