/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var Transition = require('react-transition-group/Transition');
var Portal = require('react-overlays/Portal');
var icons = require('./icons.js');
var Button = require('./Button.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Transition__default = /*#__PURE__*/_interopDefaultLegacy(Transition);
var Portal__default = /*#__PURE__*/_interopDefaultLegacy(Portal);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var _a;
var fadeStyles = (_a = {},
    _a[Transition.ENTERED] = '',
    _a[Transition.EXITING] = 'out',
    _a[Transition.EXITED] = '',
    _a[Transition.ENTERING] = 'in',
    _a);
var PopUp = /** @class */ (function (_super) {
    tslib.__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 = tslib.__rest(_a, ["style", "title", "children", "overlay", "onHide", "onConfirm", "classPrefix", "classnames", "className", "isShow", "container", "showConfirm", "translate", "showClose", "header", "placement", "onEntered", "onExited"]);
        var outerStyle = tslib.__assign({}, style);
        delete outerStyle.top;
        return (_J$X_(Portal__default["default"], { container: container },
            _J$X_(Transition__default["default"], { onEntered: onEntered, onExit: onExited, mountOnEnter: true, unmountOnExit: true, in: isShow, timeout: 500, appear: true }, function (status) {
                return (_J$X_("div", tslib.__assign({ className: cx("".concat(ns, "PopUp"), className, fadeStyles[status]), style: outerStyle }, rest, { onClick: _this.handleClick }),
                    overlay && (_J$X_("div", { className: "".concat(ns, "PopUp-overlay"), onClick: onHide })),
                    _J$X_("div", { className: cx("".concat(ns, "PopUp-inner")) },
                        !showConfirm && showClose ? (_J$X_("div", { className: cx("".concat(ns, "PopUp-closeWrap")) },
                            header,
                            _J$X_("span", { className: cx("PopUp-closeBox"), onClick: onHide },
                                _J$X_(icons.Icon, { icon: "close", className: cx('icon', "".concat(ns, "PopUp-close")) })))) : null,
                        showConfirm && (_J$X_("div", { className: cx("".concat(ns, "PopUp-toolbar")) },
                            _J$X_(Button["default"], { className: cx("".concat(ns, "PopUp-cancel")), level: "link", onClick: onHide }, __('cancel')),
                            title && (_J$X_("span", { className: cx("".concat(ns, "PopUp-title")) }, title)),
                            _J$X_(Button["default"], { className: cx("".concat(ns, "PopUp-confirm")), level: "link", onClick: onConfirm }, __('confirm')))),
                        _J$X_("div", { className: cx("".concat(ns, "PopUp-content"), "justify-".concat(placement)) }, isShow ? children : null),
                        _J$X_("div", { className: cx("PopUp-safearea") }))));
            })));
    };
    PopUp.defaultProps = {
        className: '',
        overlay: true,
        isShow: false,
        container: document.body,
        showClose: true,
        onConfirm: function () { }
    };
    return PopUp;
}(React__default["default"].PureComponent));
var PopUp$1 = amisCore.themeable(amisCore.localeable(PopUp));

exports.PopUp = PopUp;
exports["default"] = PopUp$1;
