import { formulaColumnCountKey } from './formula-binding-dependency-helpers.js';
function decrementMapCount(map, key) {
    const nextCount = (map.get(key) ?? 1) - 1;
    if (nextCount <= 0) {
        map.delete(key);
        return;
    }
    map.set(key, nextCount);
}
export function createFormulaBindingMemberCounts() {
    const columnCounts = new Map();
    const sheetCounts = new Map();
    return {
        clear() {
            columnCounts.clear();
            sheetCounts.clear();
        },
        increment(sheetId, col) {
            sheetCounts.set(sheetId, (sheetCounts.get(sheetId) ?? 0) + 1);
            if (col === undefined) {
                return;
            }
            const columnKey = formulaColumnCountKey(sheetId, col);
            columnCounts.set(columnKey, (columnCounts.get(columnKey) ?? 0) + 1);
        },
        decrement(sheetId, col) {
            decrementMapCount(sheetCounts, sheetId);
            if (col === undefined) {
                return;
            }
            decrementMapCount(columnCounts, formulaColumnCountKey(sheetId, col));
        },
        countSheetMembers(sheetId) {
            return sheetCounts.get(sheetId) ?? 0;
        },
        hasColumnMembers(sheetId, col) {
            return (columnCounts.get(formulaColumnCountKey(sheetId, col)) ?? 0) !== 0;
        },
    };
}
//# sourceMappingURL=formula-binding-member-counts.js.map