"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_STYLE = void 0;
const element_1 = require("../../../../client/element");
const parentElement_1 = require("../../../../client/platform/web/parentElement");
exports.DEFAULT_STYLE = {};
class Inherit extends element_1.Element {
    constructor(props, $system) {
        super(props, $system);
        this.$wrap = true;
        this._base = [];
        this._unlisten = [];
        this._registerChild = (child) => {
            let base = child.getRootBase();
            for (const leaf of base) {
                const [leaf_path, leaf_comp] = leaf;
                const unlisten = leaf_comp.interceptProp('style', (leaf_style) => {
                    const { style } = this.$props;
                    return Object.assign(Object.assign({}, style), leaf_style);
                });
                this._base.push(leaf_comp);
                this._unlisten.push(unlisten);
                leaf_comp.refreshProp('style');
            }
        };
        this._unregisterChild = (child) => {
            let base = child.getRootBase();
            const base_length = base.length;
            const first_leaf = base[0];
            if (first_leaf) {
                const [_, first_leaf_comp] = first_leaf;
                const first_leaf_index = this._base.indexOf(first_leaf_comp);
                for (let i = 0; i < base_length; i++) {
                    const j = first_leaf_index + i;
                    const unlisten = this._unlisten[j];
                    const leaf_comp = this._base[j];
                    unlisten();
                    leaf_comp.refreshProp('style');
                }
                this._unlisten.splice(first_leaf_index, base.length);
                this._base.splice(first_leaf_index, base.length);
            }
        };
        const $element = (0, parentElement_1.default)($system);
        $element.className = 'inherit';
        this.$element = $element;
        this.$slot = {
            default: this,
        };
    }
    domCommitAppendChild(child) {
        this._registerChild(child);
        super.domCommitAppendChild(child);
    }
    domCommitInsertChild(child, at) {
        this._registerChild(child);
        super.domCommitInsertChild(child, at);
    }
    domCommitRemoveChild(child) {
        this._unregisterChild(child);
        super.domCommitRemoveChild(child);
    }
    onPropChanged(name, style) {
        // if (name === 'style') {
        for (const leaf_comp of this._base) {
            leaf_comp.refreshProp('style');
        }
        // }
    }
}
exports.default = Inherit;
//# sourceMappingURL=Component.js.map