"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destroyFns = void 0;
const tslib_1 = require("tslib");
const CloseOutlined_1 = tslib_1.__importDefault(require("@ant-design/icons/CloseOutlined"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const prop_types_1 = tslib_1.__importDefault(require("prop-types"));
const rc_dialog_1 = tslib_1.__importDefault(require("rc-dialog"));
const addEventListener_1 = tslib_1.__importDefault(require("rc-util/lib/Dom/addEventListener"));
const react_1 = tslib_1.__importDefault(require("react"));
const button_1 = require("../button");
const locale_1 = require("./locale");
let mousePosition;
exports.destroyFns = [];
// ref: https://github.com/ant-design/ant-design/issues/15795
const getClickPosition = (e) => {
    mousePosition = {
        x: e.pageX,
        y: e.pageY,
    };
    // 100ms 内发生过点击事件，则从点击位置动画展示
    // 否则直接 zoom 展示
    // 这样可以兼容非点击方式展开
    setTimeout(() => (mousePosition = null), 100);
};
// 只有点击事件支持从鼠标位置动画展开
if (typeof window !== 'undefined' && window.document && window.document.documentElement) {
    (0, addEventListener_1.default)(document.documentElement, 'click', getClickPosition);
}
class Modal extends react_1.default.Component {
    constructor() {
        super(...arguments);
        this.handleCancel = (e) => {
            const { onCancel } = this.props;
            if (onCancel) {
                onCancel(e);
            }
        };
        this.handleOk = (e) => {
            const { onOk } = this.props;
            if (onOk) {
                onOk(e);
            }
        };
        this.renderFooter = (locale) => {
            const { okText, okType, cancelText, confirmLoading } = this.props;
            return (react_1.default.createElement("div", null,
                react_1.default.createElement(button_1.Button, { onClick: this.handleCancel, ...this.props.cancelButtonProps }, cancelText || locale.cancelText),
                react_1.default.createElement(button_1.Button, { type: okType, loading: confirmLoading, onClick: this.handleOk, ...this.props.okButtonProps }, okText || locale.okText)));
        };
        this.renderModal = () => {
            const { prefixCls: customizePrefixCls, footer, visible, wrapClassName, centered, getContainer, closeIcon, closable = true, ...restProps } = this.props;
            const prefixCls = customizePrefixCls || 'kt-modal';
            const defaultFooter = this.renderFooter((0, locale_1.getConfirmLocale)());
            const closeIconToRender = (react_1.default.createElement("span", { className: `${prefixCls}-close-x` }, closeIcon || react_1.default.createElement(CloseOutlined_1.default, { className: `${prefixCls}-close-icon` })));
            return (react_1.default.createElement(rc_dialog_1.default, { ...restProps, animation: this.props.animation, getContainer: getContainer, prefixCls: prefixCls, wrapClassName: (0, classnames_1.default)({ [`${prefixCls}-centered`]: !!centered }, wrapClassName), footer: footer === undefined ? defaultFooter : footer, visible: visible, mousePosition: mousePosition, onClose: this.handleCancel, closeIcon: closeIconToRender }));
        };
    }
    render() {
        return this.renderModal();
    }
}
Modal.defaultProps = {
    width: 520,
    confirmLoading: false,
    visible: false,
    okType: 'primary',
};
Modal.propTypes = {
    prefixCls: prop_types_1.default.string,
    onOk: prop_types_1.default.func,
    onCancel: prop_types_1.default.func,
    okText: prop_types_1.default.node,
    cancelText: prop_types_1.default.node,
    centered: prop_types_1.default.bool,
    width: prop_types_1.default.oneOfType([prop_types_1.default.number, prop_types_1.default.string]),
    confirmLoading: prop_types_1.default.bool,
    visible: prop_types_1.default.bool,
    footer: prop_types_1.default.node,
    title: prop_types_1.default.node,
    closable: prop_types_1.default.bool,
    closeIcon: prop_types_1.default.node,
};
exports.default = Modal;
//# sourceMappingURL=Modal.js.map