import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEditContext } from "../client/editContext";
import { User } from "./User";
import { Popover, PopoverContent, PopoverTrigger, } from "../../components/ui/popover";
import { AboutDialog } from "../client/AboutDialog";
import { Info, LogOut } from "lucide-react";
import { cn } from "../../lib/utils";
/**
 * UserMenu component - displays current user info with dropdown menu
 * Extracted from ActiveUsers for reuse in GlobalMenuBar
 */
export function UserMenu() {
    const editContext = useEditContext();
    if (!editContext)
        return null;
    const mySession = editContext.activeSessions.find((x) => x.sessionId === editContext.sessionId);
    if (!mySession)
        return null;
    const userName = mySession.user.fullName || mySession.user.name;
    const idxBackslash = userName.indexOf("\\");
    const displayName = idxBackslash >= 0
        ? userName.substring(idxBackslash + 1)
        : userName;
    const userEmail = mySession.user.email?.trim();
    const handleAbout = () => {
        editContext.openDialog(AboutDialog, {});
    };
    const handleLogout = () => {
        window.location.href = "/sitecore/login?action=logout";
    };
    return (_jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { className: cn("flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-gray-100 transition-colors", "focus:outline-none focus:ring-2 focus:ring-purple-400 focus:ring-offset-1"), "aria-label": "User menu", children: [_jsx(User, { session: mySession }), _jsxs("div", { className: "hidden sm:block text-left", children: [_jsx("div", { className: "text-xs font-medium text-gray-900 leading-tight", children: displayName }), userEmail && (_jsx("div", { className: "text-[10px] text-gray-500 leading-tight", children: userEmail }))] })] }) }), _jsx(PopoverContent, { className: "w-64 p-1", align: "end", children: _jsxs("div", { className: "space-y-1", children: [_jsx("div", { className: "px-2 py-2 border-b border-gray-200", children: _jsxs("div", { className: "flex items-center gap-3", children: [_jsx(User, { session: mySession }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "text-sm font-medium text-gray-900 truncate", children: displayName }), userEmail && (_jsx("div", { className: "text-xs text-gray-500 truncate", children: userEmail }))] })] }) }), _jsxs("div", { className: "space-y-1", children: [_jsxs("button", { className: "flex w-full cursor-pointer items-center gap-3 rounded px-2 py-1.5 hover:bg-gray-50 text-left", onClick: handleAbout, children: [_jsx("div", { className: "flex h-8 w-8 items-center justify-center", children: _jsx(Info, { className: "h-4 w-4 text-gray-600" }) }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx("div", { className: "text-sm font-medium text-gray-900", children: "About" }) })] }), _jsxs("button", { className: "flex w-full cursor-pointer items-center gap-3 rounded px-2 py-1.5 hover:bg-gray-50 text-left", onClick: handleLogout, children: [_jsx("div", { className: "flex h-8 w-8 items-center justify-center", children: _jsx(LogOut, { className: "h-4 w-4 text-gray-600" }) }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx("div", { className: "text-sm font-medium text-gray-900", children: "Log Out" }) })] })] })] }) })] }));
}
//# sourceMappingURL=UserMenu.js.map