"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFacetedUniqueValues = getFacetedUniqueValues;
const utils_1 = require("../utils");
function getFacetedUniqueValues() {
    return (table, columnId) => (0, utils_1.memo)(() => { var _a; return [(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.getFacetedRowModel()]; }, (facetedRowModel) => {
        var _a;
        if (!facetedRowModel)
            return new Map();
        const facetedUniqueValues = new Map();
        for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
            const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
            for (let j = 0; j < values.length; j++) {
                const value = values[j];
                if (facetedUniqueValues.has(value)) {
                    facetedUniqueValues.set(value, ((_a = facetedUniqueValues.get(value)) !== null && _a !== void 0 ? _a : 0) + 1);
                }
                else {
                    facetedUniqueValues.set(value, 1);
                }
            }
        }
        return facetedUniqueValues;
    }, (0, utils_1.getMemoOptions)(table.options, 'debugTable', `getFacetedUniqueValues_${columnId}`));
}
