"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderGraph = renderGraph;
const NOOP_1 = require("../../NOOP");
const evaluateMemorySpec_1 = require("../../spec/evaluate/evaluateMemorySpec");
const callAll_1 = require("../../util/call/callAll");
const clone_1 = require("../../util/clone");
const weakMerge_1 = require("../../weakMerge");
const componentFromSpec_1 = require("../componentFromSpec");
const renderComponent_1 = require("./renderComponent");
function renderGraph(root, system, context, $graph) {
    let unlisten = NOOP_1.NOOP;
    $graph.$getBundle({ deep: true }, async (bundle) => {
        const { spec, specs } = (0, clone_1.clone)(bundle);
        for (const unitId in spec.units) {
            const unit = spec.units[unitId];
            (0, evaluateMemorySpec_1.evaluateMemorySpec)(unit.memory, (0, weakMerge_1.weakMerge)(specs, system.specs), system.classes);
        }
        const component = (0, componentFromSpec_1.componentFromSpec)(system, spec, (0, weakMerge_1.weakMerge)(system.specs, bundle.specs ?? {}));
        const disconnect = component.connect($graph, true);
        const unrender = (0, renderComponent_1.renderComponent)(system, context, root, component);
        component.focus();
        unlisten = (0, callAll_1.callAll)([disconnect, unrender]);
    });
    return unlisten;
}
//# sourceMappingURL=renderGraph.js.map