"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) {
    const locale = columnMeta.locale;
    return function(value, nextValue) {
        const { sortEmptyCells } = columnPluginSettings;
        if (typeof value === 'string') {
            value = value.toLocaleLowerCase(locale);
        }
        if (typeof nextValue === 'string') {
            nextValue = nextValue.toLocaleLowerCase(locale);
        }
        if (value === nextValue) {
            return _sortService.DO_NOT_SWAP;
        }
        if ((0, _mixed.isEmpty)(value)) {
            if ((0, _mixed.isEmpty)(nextValue)) {
                return _sortService.DO_NOT_SWAP;
            }
            // Just fist value is empty and `sortEmptyCells` option was set
            if (sortEmptyCells) {
                return sortOrder === 'asc' ? _sortService.FIRST_BEFORE_SECOND : _sortService.FIRST_AFTER_SECOND;
            }
            return _sortService.FIRST_AFTER_SECOND;
        }
        if ((0, _mixed.isEmpty)(nextValue)) {
            // Just second value is empty and `sortEmptyCells` option was set
            if (sortEmptyCells) {
                return sortOrder === 'asc' ? _sortService.FIRST_AFTER_SECOND : _sortService.FIRST_BEFORE_SECOND;
            }
            return _sortService.FIRST_BEFORE_SECOND;
        }
        if (isNaN(value) && !isNaN(nextValue)) {
            return sortOrder === 'asc' ? _sortService.FIRST_AFTER_SECOND : _sortService.FIRST_BEFORE_SECOND;
        } else if (!isNaN(value) && isNaN(nextValue)) {
            return sortOrder === 'asc' ? _sortService.FIRST_BEFORE_SECOND : _sortService.FIRST_AFTER_SECOND;
        } else if (!(isNaN(value) || isNaN(nextValue))) {
            value = parseFloat(value);
            nextValue = parseFloat(nextValue);
        }
        if (value < nextValue) {
            return sortOrder === 'asc' ? _sortService.FIRST_BEFORE_SECOND : _sortService.FIRST_AFTER_SECOND;
        }
        if (value > nextValue) {
            return sortOrder === 'asc' ? _sortService.FIRST_AFTER_SECOND : _sortService.FIRST_BEFORE_SECOND;
        }
        return _sortService.DO_NOT_SWAP;
    };
}
const COLUMN_DATA_TYPE = 'default';
