"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const _ids_1 = require("../../../../_ids");
class Child extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['parent', 'at'],
            fo: ['child'],
            i: [],
            o: ['done'],
        }, {
            input: {
                parent: {
                    ref: true,
                },
            },
            output: {
                child: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_CHILD);
    }
    f({ parent, at }, done, fail) {
        const child = parent.refChild(at);
        if (!child) {
            fail('no child at this position');
            return;
        }
        const remove_child_at_listener = () => {
            this._forward_empty('child');
            this._functional.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;
        }
    }
    b() {
        this._output.done.push(true);
    }
}
exports.default = Child;
//# sourceMappingURL=index.js.map