"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterFns = void 0;
const includesString = (row, columnId, filterValue) => {
    var _a, _b, _c, _d;
    const search = (_a = filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
    return Boolean((_d = (_c = (_b = row.getValue(columnId)) === null || _b === void 0 ? void 0 : _b.toString()) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === null || _d === void 0 ? void 0 : _d.includes(search));
};
includesString.autoRemove = (val) => testFalsey(val);
const includesStringSensitive = (row, columnId, filterValue) => {
    var _a, _b;
    return Boolean((_b = (_a = row.getValue(columnId)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.includes(filterValue));
};
includesStringSensitive.autoRemove = (val) => testFalsey(val);
const equalsString = (row, columnId, filterValue) => {
    var _a, _b;
    return (((_b = (_a = row.getValue(columnId)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toLowerCase()));
};
equalsString.autoRemove = (val) => testFalsey(val);
const arrIncludes = (row, columnId, filterValue) => {
    var _a;
    return (_a = row.getValue(columnId)) === null || _a === void 0 ? void 0 : _a.includes(filterValue);
};
arrIncludes.autoRemove = (val) => testFalsey(val);
const arrIncludesAll = (row, columnId, filterValue) => {
    return !filterValue.some((val) => { var _a; return !((_a = row.getValue(columnId)) === null || _a === void 0 ? void 0 : _a.includes(val)); });
};
arrIncludesAll.autoRemove = (val) => testFalsey(val) || !(val === null || val === void 0 ? void 0 : val.length);
const arrIncludesSome = (row, columnId, filterValue) => {
    return filterValue.some((val) => { var _a; return (_a = row.getValue(columnId)) === null || _a === void 0 ? void 0 : _a.includes(val); });
};
arrIncludesSome.autoRemove = (val) => testFalsey(val) || !(val === null || val === void 0 ? void 0 : val.length);
const equals = (row, columnId, filterValue) => {
    return row.getValue(columnId) === filterValue;
};
equals.autoRemove = (val) => testFalsey(val);
const weakEquals = (row, columnId, filterValue) => {
    // 保持弱相等语义：null/undefined 等视为相等
    // eslint-disable-next-line eqeqeq
    return row.getValue(columnId) == filterValue;
};
weakEquals.autoRemove = (val) => testFalsey(val);
const inNumberRange = (row, columnId, filterValue) => {
    const [min, max] = filterValue;
    const rowValue = row.getValue(columnId);
    return rowValue >= min && rowValue <= max;
};
inNumberRange.resolveFilterValue = (val) => {
    const [unsafeMin, unsafeMax] = val;
    const parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
    const parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
    let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
    let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
    if (min > max) {
        const temp = min;
        min = max;
        max = temp;
    }
    return [min, max];
};
inNumberRange.autoRemove = (val) => testFalsey(val) || (testFalsey(val[0]) && testFalsey(val[1]));
// Export
exports.filterFns = {
    includesString,
    includesStringSensitive,
    equalsString,
    arrIncludes,
    arrIncludesAll,
    arrIncludesSome,
    equals,
    weakEquals,
    inNumberRange,
};
// Utils
function testFalsey(val) {
    return val === undefined || val === null || val === '';
}
