import * as React from 'react';
import { PageTitle } from '../components/PageTitle';
import { eventLogger } from '../tracking/eventLogger';
const validSchemes = {
    src: 'Sourcegraph Editor',
    'src-insiders': 'Sourcegraph Insiders',
    'src-oss': 'Sourcegraph OSS',
};
const localStorageKey = 'open-native-schema';
/**
 * The open in editor page
 */
export class OpenPage extends React.Component {
    constructor(props) {
        super(props);
        this.onClickLink = (e, scheme) => {
            e.preventDefault();
            // Event logging.
            const name = validSchemes[scheme];
            eventLogger.log('OpenDifferentEditorBuildClicked', {
                editorBuildName: name,
            });
            // Update local storage and component state.
            window.localStorage.setItem(localStorageKey, scheme);
            this.setState({ scheme });
        };
        // Validate scheme from local storage.
        let scheme = window.localStorage.getItem(localStorageKey);
        if (!scheme || !validSchemes[scheme]) {
            scheme = 'src-insiders';
        }
        this.state = {
            scheme,
        };
    }
    componentDidMount() {
        eventLogger.logViewEvent('Open');
    }
    render() {
        return (React.createElement("div", { className: "open-page" },
            React.createElement(PageTitle, { title: 'Open in Sourcegraph - Sourcegraph' }),
            React.createElement("h1", null,
                "Opening in ",
                validSchemes[this.state.scheme]),
            React.createElement("p", null,
                "Your should be redirected in a few seconds.",
                React.createElement("br", null),
                "Using a different build?",
                ' ',
                Object.entries(validSchemes)
                    .filter(([scheme, name]) => scheme !== this.state.scheme)
                    .map(([scheme, name], i) => (React.createElement("span", { key: name },
                    i === 0 ? '' : ', ',
                    React.createElement("a", { href: "", 
                        // tslint:disable-next-line:jsx-no-lambda
                        onClick: e => this.onClickLink(e, scheme) }, name))))),
            React.createElement("iframe", { className: "open-page__iframe", src: `${this.state.scheme}:open?${this.props.location.search}` })));
    }
}
//# sourceMappingURL=OpenPage.js.map