export function structuralScopeForTransform(transform) {
    switch (transform.kind) {
        case 'insert':
        case 'delete':
            return { start: transform.start };
        case 'move':
            if (transform.target < transform.start) {
                return { start: transform.target, end: transform.start + transform.count };
            }
            if (transform.target > transform.start) {
                return { start: transform.start, end: transform.target + transform.count };
            }
            return { start: transform.start, end: transform.start + transform.count };
        default: {
            const exhaustive = transform;
            return exhaustive;
        }
    }
}
export function buildStructuralTransaction(input) {
    const scope = structuralScopeForTransform(input.transform);
    const removedCellIndices = input.transform.kind === 'insert'
        ? []
        : input.remappedCells.filter((entry) => entry.toRow === undefined || entry.toCol === undefined).map((entry) => entry.cellIndex);
    return {
        sheetName: input.sheetName,
        sheetId: input.sheetId,
        transform: input.transform,
        scope,
        remappedCells: input.remappedCells,
        removedCellIndices,
        invalidationSpans: [
            {
                axis: input.transform.axis,
                start: scope.start,
                end: input.transform.kind === 'move'
                    ? (scope.end ?? input.transform.start + input.transform.count)
                    : input.transform.start + input.transform.count,
            },
        ],
    };
}
//# sourceMappingURL=structural-transaction.js.map