import { composeFormulaFamilyStructuralSourceTransform, } from '../../formula/formula-family-store.js';
export function queueDeferredFormulaFamilyStructuralSourceTransforms(args) {
    if (args.runs === undefined) {
        return undefined;
    }
    let memberCount = 0;
    let transforms;
    for (let runIndex = 0; runIndex < args.runs.length; runIndex += 1) {
        const run = args.runs[runIndex];
        if (run.sheetId !== args.sheetId) {
            continue;
        }
        const representativeCellIndex = run.cellIndices[0];
        if (representativeCellIndex === undefined || !args.canDeferCellIndex(representativeCellIndex)) {
            return undefined;
        }
        memberCount += run.cellIndices.length;
        const existingTransform = args.existingTransforms?.get(runIndex);
        const nextTransform = existingTransform
            ? composeFormulaFamilyStructuralSourceTransform(existingTransform, args.transform)
            : args.transform;
        if (!nextTransform) {
            return undefined;
        }
        transforms ??= new Map(args.existingTransforms);
        transforms.set(runIndex, nextTransform);
    }
    if (transforms === undefined || memberCount !== args.ownedFormulaCount) {
        return undefined;
    }
    return { memberCount, transforms };
}
//# sourceMappingURL=formula-binding-deferred-family-transforms.js.map