var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import * as classnames from "classnames";
import * as React from "react";
import * as FontAwesome from "react-fontawesome";
import { CloseIcon } from "./CloseIcon";
import { FlexBox, FlexItem } from "../flex";
import "./AlertBox.less";
var cssClass = {
    CONTAINER: "AlertBox--container",
    HEADER: "AlertBox--header",
    ICON_CONTAINER: "AlertBox--Icon--container",
    ICON: "AlertBox--Icon",
    TITLE: "AlertBox--title",
    CLOSE: "AlertBox--close",
    CHILDREN: "AlertBox--children",
};
var iconMap = {
    processing: "spinner",
    warning: "exclamation-triangle",
    success: "thumbs-up",
    error: "exclamation-circle",
    info: "bell",
};
/*
 * AlertBox is a closable, highlighted box
 */
var AlertBox = /** @class */ (function (_super) {
    __extends(AlertBox, _super);
    function AlertBox() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = { isOpen: true };
        return _this;
    }
    AlertBox.prototype.closeBox = function () {
        var onClose = this.props.onClose;
        this.setState({ isOpen: false });
        if (onClose) {
            onClose();
        }
    };
    AlertBox.prototype.render = function () {
        var _this = this;
        var _a = this.props, children = _a.children, className = _a.className, type = _a.type, title = _a.title, isClosable = _a.isClosable, _b = _a.headingLevel, headingLevel = _b === void 0 ? 3 : _b;
        var isOpen = this.state.isOpen;
        if (!isOpen) {
            return null;
        }
        return (React.createElement("div", { className: classnames("AlertBox--" + type, cssClass.CONTAINER, className) },
            React.createElement(FlexBox, { className: cssClass.HEADER },
                React.createElement(FlexItem, { className: cssClass.ICON_CONTAINER },
                    React.createElement(FontAwesome, { fixedWidth: true, size: "lg", name: iconMap[type], className: classnames("AlertBox--Icon--" + type, cssClass.ICON), spin: type === "processing" })),
                React.createElement(FlexItem, null,
                    title && (React.createElement("div", { role: "heading", "aria-level": headingLevel, className: cssClass.TITLE }, title)),
                    React.createElement("div", { className: cssClass.CHILDREN }, children)),
                React.createElement(FlexItem, { grow: true }, isClosable && (React.createElement("button", { "aria-label": "Close", className: cssClass.CLOSE, onClick: function () { return _this.closeBox(); } },
                    React.createElement(CloseIcon, null)))))));
    };
    return AlertBox;
}(React.PureComponent));
export default AlertBox;
