"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const _ids_1 = require("../../../../_ids");
class ParentChild extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['parent', 'at'],
            fo: ['child'],
            i: [],
        }, {
            input: {
                parent: {
                    ref: true,
                },
            },
            output: {
                child: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_PARENT_CHILD);
    }
    f({ parent, at }, done) {
        const child = parent.refChild(at);
        if (!child) {
            this.err('no child at this position');
            return;
        }
        const remove_child_at_listener = () => {
            this._forward_empty('child');
            this.err('no child at this position');
        };
        parent.addListener(`remove_child_at_${at}`, remove_child_at_listener);
        this._unlisten = () => {
            parent.removeListener(`remove_child_at_${at}`, remove_child_at_listener);
        };
        done({
            child,
        });
    }
    d() {
        if (this._unlisten) {
            this._unlisten();
            this._unlisten = undefined;
        }
    }
}
exports.default = ParentChild;
//# sourceMappingURL=index.js.map