"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Semifunctional_1 = require("../../../../../Class/Semifunctional");
const _ids_1 = require("../../../../_ids");
class ParentChild extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['parent', 'at'],
            fo: ['child'],
            i: ['done'],
        }, {
            input: {
                parent: {
                    ref: true,
                },
            },
            output: {
                child: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_PARENT_CHILD);
        this._plunk = () => {
            if (this._unlisten) {
                this._unlisten();
                this._unlisten = undefined;
            }
            this._forward_empty('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,
        });
    }
    onIterDataInputData(name) {
        // if (name === 'done') {
        this._plunk();
        this._backward('done');
        // }
    }
}
exports.default = ParentChild;
//# sourceMappingURL=index.js.map