"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get COLUMN_DATA_TYPE () {
        return COLUMN_DATA_TYPE;
    },
    get compareFunctionFactory () {
        return compareFunctionFactory;
    }
});
const _mixed = require("../../../helpers/mixed");
const _sortService = require("../sortService");
function compareFunctionFactory(sortOrder, columnMeta, columnPluginSettings) {
    return function(value, nextValue) {
        const parsedFirstValue = parseFloat(value);
        const parsedSecondValue = parseFloat(nextValue);
        const { sortEmptyCells } = columnPluginSettings;
        // Watch out when changing this part of code! Check below returns 0 (as expected) when comparing empty string, null, undefined
        if (parsedFirstValue === parsedSecondValue || isNaN(parsedFirstValue) && isNaN(parsedSecondValue)) {
            return _sortService.DO_NOT_SWAP;
        }
        if (sortEmptyCells) {
            if ((0, _mixed.isEmpty)(value)) {
                return sortOrder === 'asc' ? _sortService.FIRST_BEFORE_SECOND : _sortService.FIRST_AFTER_SECOND;
            }
            if ((0, _mixed.isEmpty)(nextValue)) {
                return sortOrder === 'asc' ? _sortService.FIRST_AFTER_SECOND : _sortService.FIRST_BEFORE_SECOND;
            }
        }
        if (isNaN(parsedFirstValue)) {
            return _sortService.FIRST_AFTER_SECOND;
        }
        if (isNaN(parsedSecondValue)) {
            return _sortService.FIRST_BEFORE_SECOND;
        }
        if (parsedFirstValue < parsedSecondValue) {
            return sortOrder === 'asc' ? _sortService.FIRST_BEFORE_SECOND : _sortService.FIRST_AFTER_SECOND;
        } else if (parsedFirstValue > parsedSecondValue) {
            return sortOrder === 'asc' ? _sortService.FIRST_AFTER_SECOND : _sortService.FIRST_BEFORE_SECOND;
        }
        return _sortService.DO_NOT_SWAP;
    };
}
const COLUMN_DATA_TYPE = 'numeric';
