"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Semifunctional_1 = require("../../../../Class/Semifunctional");
const _ids_1 = require("../../../_ids");
class NArrayBuilder extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['n'],
            fo: ['a[]'],
            i: ['a'],
            o: [],
        }, {}, system, _ids_1.ID_N_ARRAY_BUILDER);
        this.addListener('reset', () => {
            this._n = undefined;
            this._array = [];
        });
    }
    f({ n }, done, fail) {
        if (n < 0) {
            fail('n cannot be negative');
            return;
        }
        if (n === 0) {
            this._output['a[]'].push([]);
            return;
        }
        this._n = n;
        this._array = [];
        if (this._i.a !== undefined) {
            this._loop(this._i.a);
        }
    }
    d() {
        this._n = undefined;
        this._array = [];
    }
    onIterDataInputData(name, data) {
        // console.log('NArrayBuilder', name, data)
        // if (name === 'a') {
        const a = data;
        if (this._n !== undefined) {
            this._loop(a);
        }
        // }
    }
    _loop(a) {
        this._array.push(a);
        if (this._array.length === this._n) {
            this._output['a[]'].push(this._array);
            this._n = undefined;
            this._array = [];
        }
        this._input.a.pull();
    }
}
exports.default = NArrayBuilder;
//# sourceMappingURL=Class.js.map