"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFacetedMinMaxValues = getFacetedMinMaxValues;
const utils_1 = require("../utils");
function getFacetedMinMaxValues() {
    return (table, columnId) => (0, utils_1.memo)(() => { var _a; return [(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.getFacetedRowModel()]; }, (facetedRowModel) => {
        if (!facetedRowModel)
            return undefined;
        const uniqueValues = facetedRowModel.flatRows
            .flatMap((flatRow) => { var _a; return (_a = flatRow.getUniqueValues(columnId)) !== null && _a !== void 0 ? _a : []; })
            .map(Number)
            .filter((value) => !Number.isNaN(value));
        if (!uniqueValues.length)
            return;
        let facetedMinValue = uniqueValues[0];
        let facetedMaxValue = uniqueValues[uniqueValues.length - 1];
        for (const value of uniqueValues) {
            if (value < facetedMinValue)
                facetedMinValue = value;
            else if (value > facetedMaxValue)
                facetedMaxValue = value;
        }
        return [facetedMinValue, facetedMaxValue];
    }, (0, utils_1.getMemoOptions)(table.options, 'debugTable', 'getFacetedMinMaxValues'));
}
