"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlertsPanel = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const UIHelper_1 = require("../UIHelper");
const ButtonPreviewDelete_1 = tslib_1.__importDefault(require("../Components/Buttons/ButtonPreviewDelete"));
const PanelWithButton_1 = require("../Components/Panels/PanelWithButton");
const StringExtensions_1 = require("../../Utilities/Extensions/StringExtensions");
const rebass_1 = require("rebass");
const icons_1 = require("../../components/icons");
const ListGroupItem_1 = tslib_1.__importDefault(require("../../components/List/ListGroupItem"));
const ListGroup_1 = tslib_1.__importDefault(require("../../components/List/ListGroup"));
const SimpleButton_1 = tslib_1.__importDefault(require("../../components/SimpleButton"));
class AlertsPanel extends React.Component {
    componentWillUnmount() {
        this.props.onRender?.();
    }
    render() {
        let alerts = this.props.Alerts.map((alert, index) => {
            let alertHasHeader = StringExtensions_1.StringExtensions.IsNotNullOrEmpty(alert.header);
            const textColor = UIHelper_1.UIHelper.getColorByMessageType(alert.alertDefinition.MessageType);
            const textStyle = {
                color: textColor,
                fill: textColor,
            };
            const iconName = UIHelper_1.UIHelper.getGlyphByMessageType(alert.alertDefinition.MessageType);
            const IconCmp = icons_1.allIcons[iconName];
            const icon = IconCmp ? React.createElement(IconCmp, null) : null;
            let alertText = (React.createElement("div", { key: alert.Uuid, style: { maxWidth: '600px', width: '100%' } },
                React.createElement(rebass_1.Flex, { alignItems: "center", width: "100%" },
                    React.createElement(rebass_1.Text, { style: textStyle }, icon),
                    alertHasHeader ? (React.createElement("b", { style: { flex: 1 } }, alert.header)) : (React.createElement("div", { style: { fontSize: 10, flex: 1, display: 'inline-block' } }, alert.message)),
                    React.createElement(ButtonPreviewDelete_1.default, { onClick: () => this.props.onClearAlert(alert), tooltip: "Clear Alert", disabled: false, style: { float: 'left' }, accessLevel: 'Full' })),
                React.createElement("div", null, alertHasHeader && React.createElement("span", { style: { fontSize: 10 } }, alert.message))));
            return (React.createElement(ListGroupItem_1.default, { factory: "div", key: alert.Uuid || index }, alertText));
        });
        let clearAllButton = (React.createElement(SimpleButton_1.default, { onClick: () => this.props.onClearAllAlerts(this.props.Alerts), variant: "raised", tone: "neutral", accessLevel: 'Full' }, "Clear All"));
        return (React.createElement(PanelWithButton_1.PanelWithButton, { variant: "default", bodyProps: { padding: 0 }, headerText: 'Alerts', button: clearAllButton },
            React.createElement(ListGroup_1.default, null, alerts)));
    }
}
exports.AlertsPanel = AlertsPanel;
