var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { Dialog as NextDialog } from '@alifd/next';
import getStyleCustomWidth from './get-style-custom-width';
import setFooterShadow from './set-footer-shadow';
import { DEFAULT_FOOTER_ACTIONS } from './get-default-footer-actions';
export default function show(config) {
    var size = config.size, others = __rest(config, ["size"]);
    var _a = config.prefix, prefix = _a === void 0 ? 'next-' : _a;
    setTimeout(function () {
        var _a, _b;
        var doms = ((_a = document.getElementsByClassName('quick-show')) !== null && _a !== void 0 ? _a : []);
        var _loop_1 = function (item) {
            // 初始化判断是否有阴影
            setFooterShadow(item, prefix);
            // 绑定body监听器。监听高度变化
            var dialogBodyDom = (_b = item === null || item === void 0 ? void 0 : item.getElementsByClassName("".concat(prefix, "dialog-body"))) === null || _b === void 0 ? void 0 : _b[0];
            var observer = new MutationObserver(function () {
                setFooterShadow(item, prefix);
            });
            observer.observe(dialogBodyDom, {
                attributes: true,
                attributeFilter: ['style'],
                attributeOldValue: true,
                childList: true,
                subtree: true,
            });
            // 绑定 dialog 监听器，用于监听 dialog 被销毁时销毁所有监听器
            var domObserver = new MutationObserver(function () {
                var _a, _b;
                if (((_b = (_a = item === null || item === void 0 ? void 0 : item.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.tagName) !== 'BODY') {
                    observer.disconnect();
                    observer.takeRecords();
                    observer = null;
                    domObserver.disconnect();
                    domObserver.takeRecords();
                    domObserver = null;
                }
            });
            domObserver.observe(document.body, {
                attributes: true,
                attributeFilter: ['style'],
                attributeOldValue: true,
                childList: true,
                subtree: true,
            });
        };
        for (var _i = 0, doms_1 = doms; _i < doms_1.length; _i++) {
            var item = doms_1[_i];
            _loop_1(item);
        }
    });
    return NextDialog.show(__assign(__assign(__assign(__assign({ footerActions: DEFAULT_FOOTER_ACTIONS }, getStyleCustomWidth(size)), { shouldUpdatePosition: true }), others), { 
        // 将Dialog.show与其他quick弹窗区分出来，单独做样式覆盖，
        // 因为它的body是不包含Message的
        className: ['quick-show', config.className].filter(Boolean).join(' ') }));
}
