import AddIcon from 'mdi-react/AddIcon';
import ConsoleIcon from 'mdi-react/ConsoleIcon';
import LogoutIcon from 'mdi-react/LogoutIcon';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { SIDEBAR_BUTTON_CLASS, SidebarGroup, SidebarGroupHeader, SidebarGroupItems, SidebarNavItem, } from '../../components/Sidebar';
import { OrgAvatar } from '../../org/OrgAvatar';
import { SiteAdminAlert } from '../../site-admin/SiteAdminAlert';
import { eventLogger } from '../../tracking/eventLogger';
/** Sidebar for user account pages. */
export const UserAccountSidebar = props => {
    if (!props.authenticatedUser) {
        return null;
    }
    // When the site admin is viewing another user's account.
    const siteAdminViewingOtherUser = props.user.id !== props.authenticatedUser.id;
    return (React.createElement("div", { className: `user-account-sidebar ${props.className || ''}` },
        siteAdminViewingOtherUser && (React.createElement(SiteAdminAlert, { className: "sidebar__alert" },
            "Viewing account for ",
            React.createElement("strong", null, props.user.username))),
        React.createElement(SidebarGroup, null,
            React.createElement(SidebarGroupHeader, { label: "User account" }),
            React.createElement(SidebarGroupItems, null, props.items.account.map(({ label, to, exact, condition = () => true }) => condition({
                siteAdminViewingOtherUser,
                externalAuthEnabled: props.externalAuthEnabled,
            }) && (React.createElement(SidebarNavItem, { key: label, to: props.match.path + to, exact: exact }, label))))),
        (props.user.organizations.nodes.length > 0 || !siteAdminViewingOtherUser) && (React.createElement(SidebarGroup, null,
            React.createElement(SidebarGroupHeader, { label: "Organizations" }),
            React.createElement(SidebarGroupItems, null, props.user.organizations.nodes.map(org => (React.createElement(SidebarNavItem, { key: org.id, to: `/organizations/${org.name}/settings`, className: "text-truncate text-nowrap" },
                React.createElement(OrgAvatar, { org: org.name, className: "d-inline-flex" }),
                " ",
                org.name)))),
            !siteAdminViewingOtherUser && (React.createElement("div", { className: "card-body" },
                React.createElement(Link, { to: "/organizations/new", className: "btn btn-secondary btn-sm w-100" },
                    React.createElement(AddIcon, { className: "icon-inline" }),
                    " New organization"))))),
        !siteAdminViewingOtherUser && (React.createElement(Link, { to: "/api/console", className: SIDEBAR_BUTTON_CLASS },
            React.createElement(ConsoleIcon, { className: "icon-inline" }),
            " API console")),
        props.authenticatedUser.siteAdmin && (React.createElement(Link, { to: "/site-admin", className: SIDEBAR_BUTTON_CLASS }, "Site admin")),
        !siteAdminViewingOtherUser &&
            props.authenticatedUser.session &&
            props.authenticatedUser.session.canSignOut && (React.createElement("a", { href: "/-/sign-out", className: SIDEBAR_BUTTON_CLASS, onClick: logTelemetryOnSignOut },
            React.createElement(LogoutIcon, { className: "icon-inline list-group-item-action-icon" }),
            " Sign out"))));
};
function logTelemetryOnSignOut() {
    eventLogger.log('SignOutClicked');
}
//# sourceMappingURL=UserAccountSidebar.js.map