import marked from 'marked';
import ErrorIcon from 'mdi-react/ErrorIcon';
import InformationIcon from 'mdi-react/InformationIcon';
import WarningIcon from 'mdi-react/WarningIcon';
import React from 'react';
import { DismissibleAlert } from '../components/DismissibleAlert';
import { Markdown } from '../components/Markdown';
/**
 * A global alert that is shown at the top of the viewport.
 */
export const GlobalAlert = ({ alert, className: commonClassName, }) => {
    const Icon = alertIconForType(alert.type);
    const content = (React.createElement(React.Fragment, null,
        React.createElement(Icon, { className: "icon-inline mr-2 flex-shrink-0" }),
        React.createElement(Markdown, { dangerousInnerHTML: marked(alert.message, { gfm: true, breaks: true, sanitize: true }) })));
    const className = `${commonClassName} alert alert-${alertClassForType(alert.type)} d-flex`;
    if (alert.isDismissibleWithKey) {
        return (React.createElement(DismissibleAlert, { partialStorageKey: `alert.${alert.isDismissibleWithKey}`, className: className }, content));
    }
    return React.createElement("div", { className: className }, content);
};
function alertIconForType(type) {
    switch (type) {
        case "INFO" /* INFO */:
            return InformationIcon;
        case "WARNING" /* WARNING */:
            return WarningIcon;
        case "ERROR" /* ERROR */:
            return ErrorIcon;
        default:
            return WarningIcon;
    }
}
function alertClassForType(type) {
    switch (type) {
        case "INFO" /* INFO */:
            return 'info';
        case "WARNING" /* WARNING */:
            return 'warning';
        case "ERROR" /* ERROR */:
            return 'danger';
        default:
            return 'warning';
    }
}
//# sourceMappingURL=GlobalAlert.js.map