"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "default", {
    enumerable: true,
    get: function() {
        return _default;
    }
});
const _array = require("../../helpers/array");
/**
 * @private
 * @class DataFilter
 */ class DataFilter {
    /**
   * Filter data based on the conditions collection.
   *
   * @returns {Array}
   */ filter() {
        let filteredData = [];
        (0, _array.arrayEach)(this.conditionCollection.getFilteredColumns(), (physicalColumn, index)=>{
            let columnData = this.columnDataFactory(physicalColumn);
            if (index) {
                columnData = this._getIntersectData(columnData, filteredData);
            }
            filteredData = this.filterByColumn(physicalColumn, columnData);
        });
        return filteredData;
    }
    /**
   * Filter data based on specified physical column index.
   *
   * @param {number} column The physical column index.
   * @param {Array} [dataSource] Data source as array of objects with `value` and `meta` keys (e.g. `{value: 'foo', meta: {}}`).
   * @returns {Array} Returns filtered data.
   */ filterByColumn(column, dataSource = []) {
        const filteredData = [];
        (0, _array.arrayEach)(dataSource, (dataRow)=>{
            if (dataRow !== undefined && this.conditionCollection.isMatch(dataRow, column)) {
                filteredData.push(dataRow);
            }
        });
        return filteredData;
    }
    /**
   * Intersect data.
   *
   * @private
   * @param {Array} data The data to intersect.
   * @param {Array} needles The collection intersected rows with the data.
   * @returns {Array}
   */ _getIntersectData(data, needles) {
        const result = [];
        (0, _array.arrayEach)(needles, (needleRow)=>{
            const row = needleRow.meta.row;
            if (data[row] !== undefined) {
                result[row] = data[row];
            }
        });
        return result;
    }
    constructor(conditionCollection, columnDataFactory = ()=>[]){
        this.conditionCollection = conditionCollection;
        this.columnDataFactory = columnDataFactory;
    }
}
const _default = DataFilter;
