import React from 'react';
import { useState, useRef } from 'react';
import classNames from 'classnames';
import { CSSTransition } from 'react-transition-group';
import Icon from '../icon';
var defaultProps = {
    prefixCls: 'ty-alert',
    type: 'info',
    iconSize: 14,
};
var IconType = {
    success: 'check-fill',
    info: 'info-fill',
    warning: 'warn-fill',
    error: 'close-fill',
};
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 title = props.title, type = props.type, icon = props.icon, iconSize = props.iconSize, closeText = props.closeText, closable = props.closable, afterClose = props.afterClose, onClose = props.onClose, children = props.children, className = props.className, prefixCls = props.prefixCls, style = props.style;
    var _a = useState(true), isShow = _a[0], setShow = _a[1];
    var ref = useRef(null);
    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", { className: prefixCls + "__close-btn", onClick: closeBtnOnClick }, closeText || '✕'));
    var renderIcon = function () {
        if (typeof icon === 'boolean') {
            return React.createElement(Icon, { type: IconType[type], size: iconSize, className: prefixCls + "__icon" });
        }
        return icon;
    };
    return (React.createElement(CSSTransition, { unmountOnExit: true, timeout: 300, in: isShow, onExited: afterClose, classNames: prefixCls + "_slide-up" },
        React.createElement("div", { className: cls, style: style, ref: ref },
            icon && renderIcon(),
            React.createElement("div", null,
                title && React.createElement("p", { className: prefixCls + "__title" }, title),
                children),
            closeIcon)));
};
Alert.defaultProps = defaultProps;
export default Alert;
//# sourceMappingURL=index.js.map