import marked from 'marked';
import * as React from 'react';
import { Subscription } from 'rxjs';
import { DismissibleAlert } from '../components/DismissibleAlert';
import { Markdown } from '../components/Markdown';
import { currentConfiguration } from '../settings/configuration';
import { siteFlags } from '../site/backend';
import { DockerForMacAlert } from '../site/DockerForMacAlert';
import { NeedsRepositoryConfigurationAlert } from '../site/NeedsRepositoryConfigurationAlert';
import { NoRepositoriesEnabledAlert } from '../site/NoRepositoriesEnabledAlert';
import { UpdateAvailableAlert } from '../site/UpdateAvailableAlert';
import { GlobalAlert } from './GlobalAlert';
/**
 * Fetches and displays relevant global alerts at the top of the page
 */
export class GlobalAlerts extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {};
        this.subscriptions = new Subscription();
    }
    componentDidMount() {
        this.subscriptions.add(siteFlags.subscribe(siteFlags => this.setState({ siteFlags })));
        this.subscriptions.add(currentConfiguration.subscribe(mergedSettings => this.setState({ mergedSettings })));
    }
    componentWillUnmount() {
        this.subscriptions.unsubscribe();
    }
    render() {
        return (React.createElement("div", { className: "global-alerts" },
            this.state.siteFlags && (React.createElement(React.Fragment, null,
                this.state.siteFlags.needsRepositoryConfiguration ? (React.createElement(NeedsRepositoryConfigurationAlert, { className: "global-alerts__alert" })) : (this.state.siteFlags.noRepositoriesEnabled && (React.createElement(NoRepositoriesEnabledAlert, { className: "global-alerts__alert" }))),
                this.props.isSiteAdmin &&
                    this.state.siteFlags.updateCheck &&
                    !this.state.siteFlags.updateCheck.errorMessage &&
                    this.state.siteFlags.updateCheck.updateVersionAvailable && (React.createElement(UpdateAvailableAlert, { className: "global-alerts__alert", updateVersionAvailable: this.state.siteFlags.updateCheck.updateVersionAvailable })),
                window.context.likelyDockerOnMac &&
                    !this.state.siteFlags.noRepositoriesEnabled && (React.createElement(DockerForMacAlert, { className: "global-alerts__alert" })),
                this.state.siteFlags.alerts.map((alert, i) => (React.createElement(GlobalAlert, { key: i, alert: alert, className: "global-alerts__alert" }))))),
            this.state.mergedSettings &&
                this.state.mergedSettings.motd &&
                Array.isArray(this.state.mergedSettings.motd) &&
                this.state.mergedSettings.motd.map(m => (React.createElement(DismissibleAlert, { key: m, partialStorageKey: `motd.${m}`, className: "alert alert-info global-alerts__alert" },
                    React.createElement(Markdown, { dangerousInnerHTML: marked(m, { gfm: true, breaks: true, sanitize: true }) }))))));
    }
}
//# sourceMappingURL=GlobalAlerts.js.map