"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// 是 iframe 环境
const react_1 = __importDefault(require("react"));
const react_dom_1 = __importDefault(require("react-dom"));
const rxjs_1 = require("rxjs");
const use_behaviorsubject_1 = require("@rcp/use.behaviorsubject");
const emotion_css_1 = require("./utils/emotion-css");
const dnd_1 = require("./runtime/dnd");
const hot_1 = require("../shared/hot");
const get_from_main_1 = require("./utils/get-from-main");
const utils_1 = require("../shared/utils");
const backlist_dom_1 = require("./config/backlist-dom");
const { selectedNodeSubject, overingNodeSubject } = (0, get_from_main_1.getSharedFromMain)();
(0, emotion_css_1.injectGlobal)(`
    body {
    padding: 30px 10px;
    }
`);
selectedNodeSubject.next(null);
overingNodeSubject.next(null);
(0, hot_1.addUpdateCallbackListener)((moduleExports, moduleId, webpackHot, refreshOverlay, isTest) => {
    // Update selectedNodeSubject for render
    const prev = selectedNodeSubject.value;
    selectedNodeSubject.next(null);
    if (prev === null || prev === void 0 ? void 0 : prev.parentNode) {
        selectedNodeSubject.next(prev);
    }
});
const lazyFloatingRender = (0, utils_1.lazy)(() => {
    const doc = (0, backlist_dom_1.lazyDomGetter)();
    react_dom_1.default.render(react_1.default.createElement(DndLayoutManager, null), doc);
});
const domSub = new rxjs_1.BehaviorSubject([]);
function DndLayoutManager() {
    const [doms] = (0, use_behaviorsubject_1.useBehaviorSubject)(domSub);
    return (react_1.default.createElement(react_1.default.Fragment, null, doms === null || doms === void 0 ? void 0 : doms.map((dom, i) => (react_1.default.createElement(dnd_1.DndLayout, { dom: dom, key: i })))));
}
setTimeout(() => {
    lazyFloatingRender();
    domSub.next([document.body]);
});
// const rawRender = require('$mometa-external:react-dom').render
// // @ts-ignore
// require('$mometa-external:react-dom').render = function _render(...argv) {
//   const [elem, dom, cb] = argv
//   return rawRender.apply(this, [
//     elem,
//     dom,
//     function () {
//       return cb?.apply(this, arguments)
//     }
//   ])
// }
if (__mometa_env_react_jsx_runtime__ && __mometa_env_is_dev__) {
    const JSXDEVRuntime = require('$mometa-external:react/jsx-dev-runtime');
    const { jsxDEV } = JSXDEVRuntime;
    // 转移 __mometa
    JSXDEVRuntime.jsxDEV = function _jsxDev() {
        let [type, props, key, isStaticChildren, source, ...rest] = arguments;
        if (props === null || props === void 0 ? void 0 : props.__mometa) {
            const __mometa = props === null || props === void 0 ? void 0 : props.__mometa;
            props === null || props === void 0 ? true : delete props.__mometa;
            source = Object.assign(Object.assign({}, source), { __mometa });
        }
        return jsxDEV.apply(this, [type, props, key, isStaticChildren, source, ...rest]);
    };
}
//# sourceMappingURL=render-register.js.map