"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const componentFromUnitSpec_1 = require("../../../../client/componentFromUnitSpec");
const element_1 = require("../../../../client/element");
const parentElement_1 = require("../../../../client/platform/web/parentElement");
const UCGEE_1 = require("../../../../types/interface/UCGEE");
const weakMerge_1 = require("../../../../weakMerge");
class Render extends element_1.Element {
    constructor($props, $system) {
        const $element = (0, parentElement_1.parentElement)($system);
        super($props, $system, $element);
        this.$input = {
            component: [...UCGEE_1.UCGEE, 'V'],
        };
        this.$unbundled = false;
        this.$primitive = true;
    }
    focus() {
        if (this._component) {
            this._component.focus();
            return;
        }
        const child = this.$element.childNodes.item(0);
        if (child) {
            child.focus();
        }
    }
    onPropChanged(prop, current, prev) {
        void {
            component: ($component) => {
                if (this._unlisten) {
                    this._unlisten();
                    this._unlisten = undefined;
                }
                if ($component) {
                    $component.$getUnitBundleSpec({}, (bundle) => {
                        const { unit } = bundle;
                        const specs = (0, weakMerge_1.weakMerge)(this.$system.specs, bundle.specs ?? {});
                        const component = (0, componentFromUnitSpec_1.componentFromUnitSpec)(this.$system, specs, unit);
                        component.connect($component);
                        this.setSubComponents({
                            component,
                        });
                        this.registerRoot(component);
                        this._component = component;
                        this.$slot['default'] = component;
                    });
                    this._unlisten = () => {
                        if (this._component) {
                            this.unregisterRoot(this._component);
                            this.setSubComponents({});
                            this._component = undefined;
                            this.$slot['default'] = this;
                        }
                    };
                }
            },
        }[prop](current, prev);
    }
}
exports.default = Render;
//# sourceMappingURL=Component.js.map