import * as React from 'react';
import { Redirect } from 'react-router';
import { SignUpForm } from '../auth/SignUpPage';
import { eventLogger } from '../tracking/eventLogger';
/**
 * A page that is shown when the Sourcegraph instance has not yet been initialized.
 * Only the person who first accesses the instance will see this.
 */
export class SiteInitPage extends React.Component {
    constructor() {
        super(...arguments);
        this.doSiteInit = (args) => fetch('/-/site-init', {
            credentials: 'same-origin',
            method: 'POST',
            headers: Object.assign({}, window.context.xhrHeaders, { Accept: 'application/json', 'Content-Type': 'application/json' }),
            body: JSON.stringify(args),
        }).then(resp => {
            if (resp.status !== 200) {
                return resp.text().then(text => Promise.reject(new Error(text)));
            }
            eventLogger.log('ServerInstallationComplete', {
                server: {
                    email: args.email,
                    appId: window.context.siteID,
                },
            });
            window.location.replace('/site-admin');
            return Promise.resolve();
        });
    }
    render() {
        if (!window.context.showOnboarding) {
            return React.createElement(Redirect, { to: "/search" });
        }
        return (React.createElement("div", { className: "site-init-page" },
            React.createElement("div", { className: "site-init-page__content" },
                React.createElement("img", { className: "site-init-page__logo", src: `${window.context.assetsRoot}/img/sourcegraph-light-head-logo.svg` }),
                this.props.user ? (
                // If there's already a user but the site is not initialized, then the we're in an
                // unexpected state, likely because of a previous bug or because someone manually modified
                // the site_config DB table.
                React.createElement("p", null,
                    "You're signed in as ",
                    React.createElement("strong", null, this.props.user.username),
                    ". A site admin must initialize Sourcegraph before you can continue.")) : (React.createElement(React.Fragment, null,
                    React.createElement("h2", { className: "site-init-page__header" }, "Welcome"),
                    React.createElement("p", null, "Create an admin account to start using Sourcegraph."),
                    React.createElement(SignUpForm, { buttonLabel: "Create admin account & continue", doSignUp: this.doSiteInit, location: this.props.location, history: this.props.history }))))));
    }
}
//# sourceMappingURL=SiteInitPage.js.map