import { __assign, __rest } from "tslib";
import React, { useContext, useEffect, useRef } 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';
var Notification = function (props) {
    var _a = props.duration, duration = _a === void 0 ? 4500 : _a, title = props.title, description = props.description, footer = props.footer, type = props.type, icon = props.icon, willUnmount = props.willUnmount, didMount = props.didMount, onClick = props.onClick, onClose = props.onClose, className = props.className, customisedCls = props.prefixCls, otherProps = __rest(props, ["duration", "title", "description", "footer", "type", "icon", "willUnmount", "didMount", "onClick", "onClose", "className", "prefixCls"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('notification', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className);
    var ref = useRef(null);
    var timerRef = useRef();
    var height = useRef(0);
    var closeBtnOnClick = function (e) {
        timerRef.current && window.clearTimeout(timerRef.current);
        willUnmount(height.current);
        onClose && onClose(e);
    };
    var renderIcon = function () {
        if (React.isValidElement(icon)) {
            return icon;
        }
        else if (typeof type === 'string') {
            var iconSize = 40;
            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 null;
    };
    useEffect(function () {
        didMount();
        var node = ref.current;
        height.current = node ? node.offsetHeight : 0;
        if (duration !== 0) {
            timerRef.current = window.setTimeout(function () {
                willUnmount(height.current);
            }, duration);
        }
    }, [didMount, duration, willUnmount]);
    return (React.createElement("div", __assign({}, otherProps, { className: cls, onClick: onClick, ref: ref }),
        renderIcon(),
        React.createElement("div", null,
            React.createElement("div", { className: prefixCls + "__title" }, title),
            description,
            footer,
            React.createElement("div", { role: "button", className: prefixCls + "__close", onClick: closeBtnOnClick }, "\u2715"))));
};
export default Notification;
//# sourceMappingURL=notification.js.map