"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "rootComparator", {
    enumerable: true,
    get: function() {
        return rootComparator;
    }
});
const _registry = require("../columnSorting/sortService/registry");
const _engine = require("../columnSorting/sortService/engine");
function rootComparator(sortingOrders, columnMetas) {
    return function(rowIndexWithValues, nextRowIndexWithValues) {
        // We sort array of arrays. Single array is in form [rowIndex, ...values].
        // We compare just values, stored at second index of array.
        const [, ...values] = rowIndexWithValues;
        const [, ...nextValues] = nextRowIndexWithValues;
        return function getCompareResult(column) {
            const sortingOrder = sortingOrders[column];
            const columnMeta = columnMetas[column];
            const value = values[column];
            const nextValue = nextValues[column];
            const pluginSettings = columnMeta.multiColumnSorting;
            const compareFunctionFactory = pluginSettings.compareFunctionFactory ? pluginSettings.compareFunctionFactory : (0, _registry.getCompareFunctionFactory)(columnMeta.type);
            const compareResult = compareFunctionFactory(sortingOrder, columnMeta, pluginSettings)(value, nextValue);
            if (compareResult === _engine.DO_NOT_SWAP) {
                const nextSortedColumn = column + 1;
                if (typeof columnMetas[nextSortedColumn] !== 'undefined') {
                    return getCompareResult(nextSortedColumn);
                }
            }
            return compareResult;
        }(0);
    };
}
