import { __assign, __rest } from "tslib";
import React, { useState, useRef, useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { CheckCircle, CloseCircle, InfoCircle, WarningCircle } from '../_utils/components';
import Transition from '../transition';
var setClosedStyle = function (node) {
    node.style.borderTopWidth = '0';
    node.style.paddingTop = '0';
    node.style.marginTop = '0';
    node.style.height = '0';
    node.style.paddingBottom = '0';
    node.style.borderBottomWidth = '0';
    node.style.marginBottom = '0';
};
var Alert = function (props) {
    var _a = props.type, type = _a === void 0 ? 'info' : _a, _b = props.iconSize, iconSize = _b === void 0 ? 14 : _b, customisedCls = props.prefixCls, title = props.title, icon = props.icon, closeText = props.closeText, closable = props.closable, afterClose = props.afterClose, onClose = props.onClose, children = props.children, className = props.className, style = props.style, otherProps = __rest(props, ["type", "iconSize", "prefixCls", "title", "icon", "closeText", "closable", "afterClose", "onClose", "children", "className", "style"]);
    var _c = useState(true), isShow = _c[0], setShow = _c[1];
    var ref = useRef(null);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('alert', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, [prefixCls + "_" + type]);
    var closeBtnOnClick = function (e) {
        ref.current && setClosedStyle(ref.current);
        setShow(false);
        onClose && onClose(e);
    };
    var closeIcon = (closable || closeText) && (React.createElement("span", { role: "button", className: prefixCls + "__close-btn", onClick: closeBtnOnClick }, closeText || '✕'));
    var renderIcon = function () {
        if (typeof icon === 'boolean') {
            switch (type) {
                case 'success':
                    return React.createElement(CheckCircle, { size: iconSize, className: prefixCls + "__icon" });
                case 'info':
                    return React.createElement(InfoCircle, { size: iconSize, className: prefixCls + "__icon" });
                case 'warning':
                    return React.createElement(WarningCircle, { size: iconSize, className: prefixCls + "__icon" });
                case 'error':
                    return React.createElement(CloseCircle, { size: iconSize, className: prefixCls + "__icon" });
            }
        }
        return icon;
    };
    return (React.createElement(Transition, { timeout: 300, in: isShow, onExited: afterClose },
        React.createElement("div", __assign({}, otherProps, { role: "alert", className: cls, style: style, ref: ref }),
            icon && renderIcon(),
            React.createElement("div", null,
                title && React.createElement("p", { className: prefixCls + "__title" }, title),
                children),
            closeIcon)));
};
export default Alert;
//# sourceMappingURL=index.js.map