"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderBundle = void 0;
const start_1 = require("../../../start");
const _classes_1 = require("../../../system/_classes");
const _components_1 = require("../../../system/_components");
const _specs_1 = require("../../../system/_specs");
const AsyncGraph_1 = require("../../../types/interface/async/AsyncGraph");
const callAll_1 = require("../../../util/call/callAll");
const weakMerge_1 = require("../../../weakMerge");
const render_1 = require("../../render");
const boot_1 = require("./boot");
const init_1 = require("./init");
function render(bundle, bootOpt) {
    const { spec = {}, specs = {} } = bundle;
    const system = (0, boot_1.default)(Object.assign({ specs: (0, weakMerge_1.weakMerge)(specs, _specs_1.default), classes: _classes_1.default, components: _components_1.default }, bootOpt));
    if (!spec.id || !system.hasSpec(spec.id)) {
        system.newSpec(spec);
    }
    const graph = (0, start_1.start)(system, bundle);
    const $graph = (0, AsyncGraph_1.AsyncGraph)(graph);
    const webUnlisten = (0, init_1.default)(system, window, system.root);
    const renderUnlisten = (0, render_1.render)(system, $graph);
    const unlisten = (0, callAll_1.callAll)([webUnlisten, renderUnlisten]);
    return [graph, system, unlisten];
}
exports.default = render;
function renderBundle(root, bundle, opt) {
    // console.log('renderBundle')
    const system = (0, boot_1.webBoot)(window, root, opt);
    const graph = (0, start_1.start)(system, bundle);
    const $graph = (0, AsyncGraph_1.AsyncGraph)(graph);
    (0, render_1.render)(system, $graph);
    return [system, graph];
}
exports.renderBundle = renderBundle;
//# sourceMappingURL=render.js.map