import { jsx as _jsx } from "react/jsx-runtime";
import { useEditContext } from "../client/editContext";
import { SimpleTable } from "../ui/SimpleTable";
export function Sessions() {
    const editContext = useEditContext();
    if (!editContext)
        return null;
    const sessions = [...editContext.activeSessions].sort((left, right) => {
        const byUser = (left.user?.name ?? "").localeCompare(right.user?.name ?? "");
        return byUser || left.sessionId.localeCompare(right.sessionId);
    });
    const columns = [
        {
            body: (session) => (_jsx("span", { "data-testid": `session-user-${session.sessionId}`, children: session.user?.name })),
            header: "User",
        },
        {
            body: (session) => (_jsx("a", { "data-testid": `session-page-${session.sessionId}`, href: "#", onClick: (event) => {
                    event.preventDefault();
                    if (session.item)
                        editContext?.loadItem(session.item);
                }, children: session.item?.name })),
            header: "Page",
        },
        {
            body: (session) => (_jsx("span", { "data-testid": `session-language-${session.sessionId}`, children: session.item?.language })),
            header: "Language",
        },
        {
            body: (session) => (_jsx("span", { "data-testid": `session-version-${session.sessionId}`, children: session.item?.version })),
            header: "Version",
        },
    ];
    return (_jsx(SimpleTable, { "data-testid": "sessions-table", items: sessions, columns: columns, rowTestId: (session) => `session-row-${session.sessionId}`, rowKey: (session) => session.sessionId }));
}
//# sourceMappingURL=Sessions.js.map