"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderComponent = renderComponent;
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 componentFromUnitSpec_1 = require("../componentFromUnitSpec");
const context_1 = require("../context");
const renderFrame_1 = require("../renderFrame");
const spec_1 = require("../spec");
function renderComponent(root, system, $component) {
    let unlisten = NOOP_1.NOOP;
    $component.$getUnitBundleSpec({}, (bundle) => {
        var _a;
        const { unit } = bundle;
        const { id } = unit;
        const specs = (0, weakMerge_1.weakMerge)(system.specs, (_a = bundle.specs) !== null && _a !== void 0 ? _a : {});
        const component = (0, componentFromUnitSpec_1.componentFromUnitSpec)(system, specs, unit);
        const spec = (0, spec_1.getSpec)(specs, id);
        const { type = '`U`' } = spec;
        const _ = type.split('&').map((type) => type.slice(1, -1));
        const context = (0, renderFrame_1.renderFrame)(system, null, root, {});
        const frame = new Component_1.default({}, system);
        frame.appendChild(component);
        root.appendChild(frame.$element);
        const removeChild = (0, context_1.appendChild)(context, frame);
        (0, context_1.mount)(context);
        component.connect($component);
        component.focus();
        unlisten = (0, callAll_1.callAll)([removeChild]);
    });
    return () => {
        unlisten();
    };
}
//# sourceMappingURL=renderComponent.js.map