import { formatAddress, parseCellAddress } from '@bilig/formula';
import { areCellValuesEqual, emptyValue } from '../../engine-value-utils.js';
export function capturePivotOutputValues(input) {
    const values = new Map();
    const owner = parseCellAddress(input.pivot.address, input.pivot.sheetName);
    for (let rowOffset = 0; rowOffset < input.pivot.rows; rowOffset += 1) {
        for (let colOffset = 0; colOffset < input.pivot.cols; colOffset += 1) {
            const cellIndex = input.workbook.getCellIndex(input.pivot.sheetName, formatAddress(owner.row + rowOffset, owner.col + colOffset));
            if (cellIndex !== undefined) {
                values.set(cellIndex, input.workbook.cellStore.getValue(cellIndex, (id) => input.strings.get(id)));
            }
        }
    }
    return values;
}
export function notePivotValueChanges(input) {
    for (let index = 0; index < input.changed.length; index += 1) {
        const cellIndex = input.changed[index];
        const beforeValue = input.before.get(cellIndex) ?? emptyValue();
        const afterValue = input.workbook.cellStore.getValue(cellIndex, (id) => input.strings.get(id));
        if (!areCellValuesEqual(beforeValue, afterValue)) {
            input.collector.note(cellIndex);
        }
    }
}
//# sourceMappingURL=recalc-pivot-value-changes.js.map