"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.render = render;
exports.renderBundle = renderBundle;
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;
    bundle.spec = spec;
    bundle.specs = specs;
    const [system, unlistenSystem] = (0, boot_1.defaultWebBoot)({
        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.webInit)(system, window, system.root);
    const renderUnlisten = (0, render_1.render)(system, $graph);
    const unlisten = (0, callAll_1.callAll)([webUnlisten, renderUnlisten, unlistenSystem]);
    return [graph, system, unlisten];
}
function renderBundle(root, bundle, opt) {
    // console.log('renderBundle')
    const [system, unlistenSystem] = (0, boot_1.webBoot)(window, root, opt);
    const graph = (0, start_1.start)(system, bundle);
    const $graph = (0, AsyncGraph_1.AsyncGraph)(graph);
    const unlistenRender = (0, render_1.render)(system, $graph);
    const unlisten = (0, callAll_1.callAll)([unlistenRender, unlistenSystem]);
    return [system, graph, unlisten];
}
//# sourceMappingURL=render.js.map