"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderGraph = void 0;
const NOOP_1 = require("../../NOOP");
const Component_1 = require("../../system/platform/component/Frame/Component");
const callAll_1 = require("../../util/call/callAll");
const weakMerge_1 = require("../../weakMerge");
const componentFromSpec_1 = require("../componentFromSpec");
const context_1 = require("../context");
const renderFrame_1 = require("../renderFrame");
const watchGraphComponent_1 = require("./watchGraphComponent");
function renderGraph(root, system, $graph) {
    // console.log('renderGraph')
    let unlisten = NOOP_1.NOOP;
    $graph.$getBundle({}, (bundle) => {
        var _a;
        const { spec } = bundle;
        const component = (0, componentFromSpec_1.componentFromSpec)(system, spec, (0, weakMerge_1.weakMerge)(system.specs, (_a = bundle.specs) !== null && _a !== void 0 ? _a : {}));
        const context = (0, renderFrame_1.renderFrame)(system, null, root, {});
        const frame = new Component_1.default({}, system);
        frame.appendChild(component);
        root.appendChild(frame.$element);
        const remove_child = (0, context_1.appendChild)(context, frame);
        (0, context_1.mount)(context);
        const unlisten_graph = (0, watchGraphComponent_1.watchGraphComponent)(system, $graph, component);
        component.connect($graph);
        component.focus();
        unlisten = (0, callAll_1.callAll)([remove_child, unlisten_graph]);
    });
    return unlisten;
}
exports.renderGraph = renderGraph;
//# sourceMappingURL=renderGraph.js.map