import React from 'react';
import { Redirect, Route, Switch } from 'react-router';
import { LinkExtension } from './extension/Link';
import { GlobalAlerts } from './global/GlobalAlerts';
import { GlobalDebug } from './global/GlobalDebug';
import { IntegrationsToast } from './marketing/IntegrationsToast';
import { GlobalNavbar } from './nav/GlobalNavbar';
import { routes } from './routes';
import { parseSearchURLQuery } from './search';
export const Layout = props => {
    const isSearchHomepage = props.location.pathname === '/search' && !parseSearchURLQuery(props.location.search);
    const needsSiteInit = window.context.showOnboarding;
    const isSiteInit = props.location.pathname === '/site-admin/init';
    // Force light theme on site init page.
    if (isSiteInit && !props.isLightTheme) {
        props.onThemeChange();
    }
    // Remove trailing slash (which is never valid in any of our URLs).
    if (props.location.pathname !== '/' && props.location.pathname.endsWith('/')) {
        return React.createElement(Redirect, { to: Object.assign({}, props.location, { pathname: props.location.pathname.slice(0, -1) }) });
    }
    return (React.createElement("div", { className: "layout" },
        React.createElement(GlobalAlerts, { isSiteAdmin: !!props.user && props.user.siteAdmin }),
        !needsSiteInit && !isSiteInit && !!props.user && React.createElement(IntegrationsToast, { history: props.history }),
        !isSiteInit && React.createElement(GlobalNavbar, Object.assign({}, props, { lowProfile: isSearchHomepage })),
        needsSiteInit && !isSiteInit && React.createElement(Redirect, { to: "/site-admin/init" }),
        React.createElement(Switch, null, routes.map((route, i) => {
            const isFullWidth = !route.forceNarrowWidth;
            return (React.createElement(Route, Object.assign({}, route, { key: "hardcoded-key" // see https://github.com/ReactTraining/react-router/issues/4578#issuecomment-334489490
                , component: undefined, 
                // tslint:disable-next-line:jsx-no-lambda
                render: routeComponentProps => (React.createElement("div", { className: [
                        'layout__app-router-container',
                        `layout__app-router-container--${isFullWidth ? 'full-width' : 'restricted'}`,
                    ].join(' ') },
                    route.render(Object.assign({}, props, routeComponentProps)),
                    !!props.user && React.createElement(LinkExtension, { user: props.user }))) })));
        })),
        React.createElement(GlobalDebug, Object.assign({}, props))));
};
//# sourceMappingURL=Layout.js.map