"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Element_ = void 0;
const method_1 = require("../../component/method");
const array_1 = require("../../util/array");
const Stateful_1 = require("../Stateful");
class Element_ extends Stateful_1.Stateful {
    constructor({ i = [], o = [] }, opt = {}, system, id) {
        super({
            i,
            o,
        }, opt, system, id);
        this.__ = ['U', 'C', 'J', 'V', 'EE'];
        this._children = [];
        this._root = [];
        this._parent_root = [];
        this._parent_children = [];
        this._slot = {};
        this._state = {};
        this.addListener('play', this._play);
        this.addListener('pause', this._pause);
        this.addListener('set', (name, data) => {
            var _a, _b;
            if (!this._forwarding) {
                this._backwarding = true;
                (_b = (_a = this._input) === null || _a === void 0 ? void 0 : _a[name]) === null || _b === void 0 ? void 0 : _b.pull();
                this._backwarding = false;
            }
        });
        this._slot = {
            default: this,
        };
    }
    registerRoot(component) {
        return (0, method_1.registerRoot)(this, this._root, component);
    }
    unregisterRoot(component) {
        return (0, method_1.unregisterRoot)(this, this._root, component);
    }
    registerParentRoot(component, slotName) {
        return (0, method_1.registerParentRoot)(this, this._parent_root, component, slotName);
    }
    unregisterParentRoot(component) {
        return (0, method_1.unregisterParentRoot)(this, this._parent_root, component);
    }
    appendParentChild(component, slotName) {
        return (0, method_1.appendParentChild)(this, this._parent_children, component, slotName);
    }
    removeParentChild(component) {
        return (0, method_1.removeParentChild)(this, this._parent_children, component);
    }
    appendChild(Bundle) {
        return (0, method_1.appendChild)(this, this._children, Bundle);
    }
    insertChild(Bundle, at) {
        throw new Error('Method not implemented.');
    }
    pushChild(Bundle) {
        return (0, method_1.pushChild)(this, this._children, Bundle);
    }
    hasChild(at) {
        return (0, method_1.hasChild)(this, this._children, at);
    }
    removeChild(at) {
        return (0, method_1.removeChild)(this, this._children, at);
    }
    pullChild(at) {
        throw (0, method_1.pullChild)(this, this._children, at);
    }
    refChild(at) {
        return (0, method_1.refChild)(this, this._children, at);
    }
    refChildren() {
        return (0, method_1.refChildren)(this, this._children);
    }
    refSlot(slotName) {
        const slot = this._slot[slotName];
        if (slot) {
            return slot;
        }
        throw new Error('Slot not found');
    }
    _play() {
        (0, array_1.forEach)(this._children, (u) => u.play());
    }
    _pause() {
        (0, array_1.forEach)(this._children, (u) => u.pause());
    }
}
exports.Element_ = Element_;
//# sourceMappingURL=index.js.map