import * as tslib_1 from "tslib";
import React, { useState } from 'react';
import classNames from 'classnames';
import { CSSTransition } from 'react-transition-group';
import Overlay from '../overlay';
import Button from '../button';
var defaultProps = {
    visible: false,
    width: 520,
    centered: false,
    closable: true,
    unmountOnClose: true,
    maskType: 'default',
    maskClosable: true,
    prefixCls: 'ty-modal',
    confirmText: 'OK',
    cancelText: 'Cancel',
    confirmLoading: false,
    animation: 'slide',
    zIndex: 1000,
    onConfirm: function () {
    },
    onCancel: function () {
    },
};
var Modal = function (props) {
    var _a;
    var width = props.width, centered = props.centered, top = props.top, header = props.header, footer = props.footer, visible = props.visible, closable = props.closable, maskType = props.maskType, maskClosable = props.maskClosable, unmountOnClose = props.unmountOnClose, afterClose = props.afterClose, confirmText = props.confirmText, cancelText = props.cancelText, onConfirm = props.onConfirm, onCancel = props.onCancel, confirmLoading = props.confirmLoading, confirmButtonProps = props.confirmButtonProps, cancelButtonProps = props.cancelButtonProps, animation = props.animation, zIndex = props.zIndex, prefixCls = props.prefixCls, className = props.className, children = props.children, style = props.style, maskStyle = props.maskStyle, headerStyle = props.headerStyle, bodyStyle = props.bodyStyle, footerStyle = props.footerStyle;
    var _b = useState(visible), modalVisible = _b[0], setModalVisible = _b[1];
    var cls = classNames(prefixCls, className, (_a = {}, _a[prefixCls + "_centered"] = centered, _a));
    var _renderFooter = function () {
        if (React.isValidElement(footer)) {
            return footer;
        }
        else if (footer === null) {
            return null;
        }
        else {
            return (React.createElement("div", { className: prefixCls + "__footer", style: footerStyle },
                React.createElement(Button, tslib_1.__assign({}, cancelButtonProps, { onClick: onCancel, className: prefixCls + "__footer-btn" }), cancelText),
                React.createElement(Button, tslib_1.__assign({ loading: confirmLoading, onClick: onConfirm, color: "primary", className: prefixCls + "__footer-btn" }, confirmButtonProps), confirmText)));
        }
    };
    return (React.createElement(Overlay, { onEnter: function () { return setModalVisible(true); }, onExit: function () { return setModalVisible(false); }, zIndex: zIndex, type: maskType, unmountOnExit: unmountOnClose, isShow: visible, onExited: afterClose, clickCallback: function () { return (maskClosable && onCancel()); }, style: maskStyle },
        React.createElement("div", { className: cls, style: { top: top } },
            React.createElement("div", { style: tslib_1.__assign({ width: width }, style) },
                React.createElement(CSSTransition, { appear: true, in: modalVisible, classNames: prefixCls + "__content_" + animation, timeout: 0 },
                    React.createElement("div", { className: prefixCls + "__content", onClick: function (e) { return e.stopPropagation(); } },
                        closable && React.createElement("div", { className: prefixCls + "__close-btn", onClick: onCancel }, "\u2715"),
                        header && (React.createElement("div", { className: prefixCls + "__header", style: headerStyle },
                            React.createElement("div", { className: prefixCls + "__title" }, header))),
                        React.createElement("div", { className: prefixCls + "__body", style: bodyStyle }, children),
                        _renderFooter()))))));
};
Modal.defaultProps = defaultProps;
export default Modal;
//# sourceMappingURL=index.js.map