'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Star } from 'lucide-react';
import { btnGhostIcon } from './primitives.js';
export function formatEntryDateTime(iso) {
    if (!iso)
        return '—';
    const d = new Date(iso);
    if (Number.isNaN(d.getTime()))
        return '—';
    return d.toLocaleString(undefined, {
        month: 'short',
        day: 'numeric',
        year: 'numeric',
        hour: 'numeric',
        minute: '2-digit',
    });
}
export function EntriesTable({ entries, selected, allSelected, onToggleSelectAll, onToggleSelect, onOpen, onToggleStar, showForm = false, onOpenForm, ariaLabel = 'Submissions', footer, }) {
    return (_jsxs("div", { className: "border-border bg-card rounded-lg border", children: [_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: `w-full ${showForm ? 'min-w-[860px]' : 'min-w-[720px]'} text-sm`, "aria-label": ariaLabel, children: [_jsx("thead", { children: _jsxs("tr", { className: "border-border text-muted-foreground border-b text-left text-xs", children: [_jsx("th", { scope: "col", className: "w-10 px-4 py-2.5", children: _jsx("input", { type: "checkbox", checked: allSelected, onChange: onToggleSelectAll, "aria-label": "Select all submissions", className: "border-border text-primary focus-visible:ring-ring h-4 w-4 rounded" }) }), _jsx("th", { scope: "col", className: "px-4 py-2.5 font-medium", children: "Sender" }), showForm && (_jsx("th", { scope: "col", className: "px-4 py-2.5 font-medium whitespace-nowrap", children: "Form" })), _jsx("th", { scope: "col", className: "px-4 py-2.5 font-medium", children: "Submission" }), _jsx("th", { scope: "col", className: "px-4 py-2.5 font-medium whitespace-nowrap", children: "Submitted" }), _jsx("th", { scope: "col", className: "w-10 px-4 py-2.5 text-center font-medium", children: _jsx("span", { className: "sr-only", children: "Starred" }) })] }) }), _jsx("tbody", { children: entries.map((entry) => {
                                const isSelected = selected.has(entry.id);
                                const name = entry.senderName || 'Anonymous';
                                return (_jsxs("tr", { className: `border-border hover:bg-accent/40 group cursor-pointer border-b transition-colors last:border-b-0 ${isSelected ? 'bg-accent/30' : ''}`, onClick: () => onOpen(entry.id), children: [_jsx("td", { className: "px-4 py-3", onClick: (e) => e.stopPropagation(), children: _jsx("input", { type: "checkbox", checked: isSelected, onChange: () => onToggleSelect(entry.id), "aria-label": `Select submission from ${name}`, className: "border-border text-primary focus-visible:ring-ring h-4 w-4 rounded" }) }), _jsx("td", { className: "px-4 py-3", children: _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("span", { className: "bg-muted text-muted-foreground flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-xs font-medium", "aria-hidden": true, children: name.charAt(0).toUpperCase() }), _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2", children: [entry.unread && (_jsx("span", { className: "bg-primary h-1.5 w-1.5 shrink-0 rounded-full", "aria-label": "Unread" })), _jsx("span", { className: `text-foreground truncate ${entry.unread ? 'font-semibold' : 'font-medium'}`, children: name })] }), entry.senderEmail && (_jsx("span", { className: "text-muted-foreground block truncate text-xs", children: entry.senderEmail }))] })] }) }), showForm && (_jsx("td", { className: "px-4 py-3 whitespace-nowrap", onClick: (e) => e.stopPropagation(), children: onOpenForm ? (_jsx("button", { type: "button", onClick: () => onOpenForm(entry.formId), className: "text-muted-foreground hover:text-primary focus-visible:ring-ring rounded text-sm focus-visible:ring-2 focus-visible:outline-none", children: entry.formName || '—' })) : (_jsx("span", { className: "text-muted-foreground text-sm", children: entry.formName || '—' })) })), _jsx("td", { className: "px-4 py-3", children: _jsx("span", { className: "text-muted-foreground line-clamp-1 max-w-md", children: entry.preview || '—' }) }), _jsx("td", { className: "text-muted-foreground px-4 py-3 whitespace-nowrap", children: formatEntryDateTime(entry.submittedAt) }), _jsx("td", { className: "px-4 py-3 text-center", onClick: (e) => e.stopPropagation(), children: _jsx("button", { type: "button", className: btnGhostIcon, "aria-pressed": entry.starred, "aria-label": entry.starred ? 'Unstar submission' : 'Star submission', onClick: () => onToggleStar(entry), children: _jsx(Star, { className: `h-4 w-4 ${entry.starred ? 'fill-warning text-warning' : ''}`, "aria-hidden": true }) }) })] }, entry.id));
                            }) })] }) }), footer] }));
}
//# sourceMappingURL=EntriesTable.js.map