/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

import { __extends, __rest, __assign } from 'tslib';
import React__default from 'react';
import { themeable, localeable } from 'amis-core';
import Transition, { ENTERED, EXITING, EXITED, ENTERING } from 'react-transition-group/Transition';
import Portal from 'react-overlays/Portal';
import { Icon } from './icons.js';
import Button from './Button.js';

/**
 * @file PopUp
 * @description
 * @author fex
 */
var _a;
var fadeStyles = (_a = {},
    _a[ENTERED] = '',
    _a[EXITING] = 'out',
    _a[EXITED] = '',
    _a[ENTERING] = 'in',
    _a);
var PopUp = /** @class */ (function (_super) {
    __extends(PopUp, _super);
    function PopUp() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.scrollTop = 0;
        return _this;
    }
    PopUp.prototype.componentDidUpdate = function () {
        if (this.props.isShow) {
            this.scrollTop =
                document.body.scrollTop || document.documentElement.scrollTop;
            document.body.style.overflow = 'hidden';
        }
        else {
            document.body.style.overflow = 'auto';
            document.body.scrollTop = this.scrollTop;
        }
    };
    PopUp.prototype.componentWillUnmount = function () {
        document.body.style.overflow = 'auto';
        document.body.scrollTop = this.scrollTop;
    };
    PopUp.prototype.handleClick = function (e) {
        e.stopPropagation();
    };
    PopUp.prototype.render = function () {
        var _this = this;
        var _a = this.props, style = _a.style, title = _a.title, children = _a.children, overlay = _a.overlay, onHide = _a.onHide, onConfirm = _a.onConfirm, ns = _a.classPrefix, cx = _a.classnames, className = _a.className, isShow = _a.isShow, container = _a.container, showConfirm = _a.showConfirm, __ = _a.translate, showClose = _a.showClose, header = _a.header, _b = _a.placement, placement = _b === void 0 ? 'center' : _b, onEntered = _a.onEntered, onExited = _a.onExited, rest = __rest(_a, ["style", "title", "children", "overlay", "onHide", "onConfirm", "classPrefix", "classnames", "className", "isShow", "container", "showConfirm", "translate", "showClose", "header", "placement", "onEntered", "onExited"]);
        var outerStyle = __assign({}, style);
        delete outerStyle.top;
        return (React__default.createElement(Portal, { container: container },
            React__default.createElement(Transition, { onEntered: onEntered, onExit: onExited, mountOnEnter: true, unmountOnExit: true, in: isShow, timeout: 500, appear: true }, function (status) {
                return (React__default.createElement("div", __assign({ className: cx("".concat(ns, "PopUp"), className, fadeStyles[status]), style: outerStyle }, rest, { onClick: _this.handleClick }),
                    overlay && (React__default.createElement("div", { className: "".concat(ns, "PopUp-overlay"), onClick: onHide })),
                    React__default.createElement("div", { className: cx("".concat(ns, "PopUp-inner")) },
                        !showConfirm && showClose ? (React__default.createElement("div", { className: cx("".concat(ns, "PopUp-closeWrap")) },
                            header,
                            React__default.createElement("span", { className: cx("PopUp-closeBox"), onClick: onHide },
                                React__default.createElement(Icon, { icon: "close", className: cx('icon', "".concat(ns, "PopUp-close")) })))) : null,
                        showConfirm && (React__default.createElement("div", { className: cx("".concat(ns, "PopUp-toolbar")) },
                            React__default.createElement(Button, { className: cx("".concat(ns, "PopUp-cancel")), level: "link", onClick: onHide }, __('cancel')),
                            title && (React__default.createElement("span", { className: cx("".concat(ns, "PopUp-title")) }, title)),
                            React__default.createElement(Button, { className: cx("".concat(ns, "PopUp-confirm")), level: "link", onClick: onConfirm }, __('confirm')))),
                        React__default.createElement("div", { className: cx("".concat(ns, "PopUp-content"), "justify-".concat(placement)) }, isShow ? children : null),
                        React__default.createElement("div", { className: cx("PopUp-safearea") }))));
            })));
    };
    PopUp.defaultProps = {
        className: '',
        overlay: true,
        isShow: false,
        container: document.body,
        showClose: true,
        onConfirm: function () { }
    };
    return PopUp;
}(React__default.PureComponent));
var PopUp$1 = themeable(localeable(PopUp));

export { PopUp, PopUp$1 as default };
