import {} from '../enums/field.type.js';
import { mapTempoDateFormatWithFieldType, tryParseDate } from '../services/dateUtils.js';
export function compareDates(value1, value2, sortDirection, format, strict) {
    let diff = 0;
    if (value1 === value2) {
        diff = 0;
    }
    else {
        // try to parse the Date and validate it
        // when date is invalid (false), we'll create a temporary old Date
        const date1 = tryParseDate(value1, format, strict) || new Date(1001, 1, 1);
        const date2 = tryParseDate(value2, format, strict) || new Date(1001, 1, 1);
        // we can use Date valueOf to sort
        diff = date1.valueOf() - date2.valueOf();
    }
    return sortDirection * diff;
}
/** From a FieldType, find the associated Date SortComparer */
export function getAssociatedDateSortComparer(fieldType) {
    const FORMAT = fieldType === 'date' ? undefined : mapTempoDateFormatWithFieldType(fieldType);
    return ((value1, value2, sortDirection) => {
        if (FORMAT === undefined) {
            return compareDates(value1, value2, sortDirection, FORMAT, false);
        }
        return compareDates(value1, value2, sortDirection, FORMAT, true);
    });
}
//# sourceMappingURL=dateUtilities.js.map