"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.only = void 0;
function createOnlyResult(distinctValues) {
    const value = distinctValues.size === 1 ? distinctValues.values().next().value : null;
    return {
        distinctValues,
        value,
        toString() {
            return value != null ? String(value) : '';
        },
    };
}
/**
 * AG Grid aggFunc that returns the column value only when all rows in the group
 * share the same value. Returns null when values differ (or when there are no values).
 *
 * params.values already respects suppressAggFilteredOnly, containing either:
 * - Raw cell values (string | number) for leaf children
 * - OnlyAggResult objects for sub-group children (with pre-computed distinct values)
 *
 * Bails out early as soon as two distinct values are found.
 */
const only = (params) => {
    const { values } = params;
    const distinctValues = new Set();
    for (let i = 0; i < values.length; i++) {
        const value = values[i];
        if (typeof value === 'number' || typeof value === 'string') {
            distinctValues.add(value);
        }
        else if (value != null && typeof value === 'object' && 'distinctValues' in value) {
            // sub-group: merge pre-computed distinct values (set has at most 2 elements)
            for (const v of value.distinctValues) {
                distinctValues.add(v);
            }
        }
        if (distinctValues.size > 1) {
            return createOnlyResult(distinctValues);
        }
    }
    return createOnlyResult(distinctValues);
};
exports.only = only;
