import MapSearchIcon from 'mdi-react/MapSearchIcon';
import * as React from 'react';
import { Route, Switch } from 'react-router';
import { Redirect } from 'react-router-dom';
import { HeroPage } from '../components/HeroPage';
import { SiteAdminSidebar } from './SiteAdminSidebar';
const NotFoundPage = () => (React.createElement(HeroPage, { icon: MapSearchIcon, title: "404: Not Found", subtitle: "Sorry, the requested site admin page was not found." }));
const NotSiteAdminPage = () => (React.createElement(HeroPage, { icon: MapSearchIcon, title: "403: Forbidden", subtitle: "Only site admins are allowed here." }));
/**
 * Renders a layout of a sidebar and a content area to display site admin information.
 */
export class SiteAdminArea extends React.Component {
    render() {
        // If not logged in, redirect to sign in.
        if (!this.props.user) {
            const newUrl = new URL(window.location.href);
            newUrl.pathname = '/sign-in';
            // Return to the current page after sign up/in.
            newUrl.searchParams.set('returnTo', window.location.href);
            return React.createElement(Redirect, { to: newUrl.pathname + newUrl.search });
        }
        // If not site admin, redirect to sign in.
        if (!this.props.user.siteAdmin) {
            return React.createElement(NotSiteAdminPage, null);
        }
        const context = {
            user: this.props.user,
            extensions: this.props.extensions,
            isLightTheme: this.props.isLightTheme,
            site: { __typename: 'Site', id: window.context.siteGQLID },
            overviewComponents: this.props.overviewComponents,
        };
        return (React.createElement("div", { className: "site-admin-area area" },
            React.createElement(SiteAdminSidebar, { className: "area__sidebar", groups: this.props.sideBarGroups }),
            React.createElement("div", { className: "area__content" },
                React.createElement(Switch, null,
                    this.props.routes.map(({ render, path, exact, condition = () => true }) => condition(context) && (React.createElement(Route
                    // see https://github.com/ReactTraining/react-router/issues/4578#issuecomment-334489490
                    , { 
                        // see https://github.com/ReactTraining/react-router/issues/4578#issuecomment-334489490
                        key: "hardcoded-key", path: this.props.match.url + path, exact: exact, 
                        // tslint:disable-next-line:jsx-no-lambda RouteProps.render is an exception
                        render: routeComponentProps => render(Object.assign({}, context, routeComponentProps)) }))),
                    React.createElement(Route, { component: NotFoundPage })))));
    }
}
//# sourceMappingURL=SiteAdminArea.js.map