"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.FormulaPasteProcessor = void 0;

const formula_reference_adjustor_1 = require("./formula-reference-adjustor");

class FormulaPasteProcessor {
    static adjustFormulaForPaste(formula, context) {
        if (!formula_reference_adjustor_1.FormulaReferenceAdjustor.isFormula(formula)) return formula;
        const colOffset = context.targetCell.col - context.sourceCell.col, rowOffset = context.targetCell.row - context.sourceCell.row;
        return formula_reference_adjustor_1.FormulaReferenceAdjustor.adjustFormulaReferences(formula, colOffset, rowOffset);
    }
    static adjustFormulasForPaste(formulas, context) {
        const colOffset = context.targetRange.startCol - context.sourceRange.startCol, rowOffset = context.targetRange.startRow - context.sourceRange.startRow;
        return this.adjustFormulasForPasteWithOffset(formulas, colOffset, rowOffset);
    }
    static adjustFormulasForPasteWithOffset(formulas, colOffset, rowOffset) {
        const result = [];
        for (let row = 0; row < formulas.length; row++) {
            const newRow = [];
            for (let col = 0; col < formulas[row].length; col++) {
                const formula = formulas[row][col];
                if (formula_reference_adjustor_1.FormulaReferenceAdjustor.isFormula(formula)) {
                    const adjustedFormula = formula_reference_adjustor_1.FormulaReferenceAdjustor.adjustFormulaReferences(formula, colOffset, rowOffset);
                    newRow.push(adjustedFormula);
                } else newRow.push(formula);
            }
            result.push(newRow);
        }
        return result;
    }
    static needsFormulaAdjustment(value) {
        return formula_reference_adjustor_1.FormulaReferenceAdjustor.isFormula(value);
    }
    static getFormulaReferences(formula) {
        return formula_reference_adjustor_1.FormulaReferenceAdjustor.extractReferences(formula);
    }
    static validateFormulaReferences(formula, maxCol, maxRow) {
        const references = formula_reference_adjustor_1.FormulaReferenceAdjustor.extractReferences(formula);
        for (const ref of references) if (ref.col < 0 || ref.col > maxCol || ref.row < 0 || ref.row > maxRow) return !1;
        return !0;
    }
    static createPasteContext(sourceStartCol, sourceStartRow, targetStartCol, targetStartRow, sourceCols, sourceRows, targetCols, targetRows) {
        return {
            sourceRange: {
                startCol: sourceStartCol,
                startRow: sourceStartRow,
                endCol: sourceStartCol + sourceCols - 1,
                endRow: sourceStartRow + sourceRows - 1
            },
            targetRange: {
                startCol: targetStartCol,
                startRow: targetStartRow,
                endCol: targetStartCol + targetCols - 1,
                endRow: targetStartRow + targetRows - 1
            },
            sourceCell: {
                col: sourceStartCol,
                row: sourceStartRow
            },
            targetCell: {
                col: targetStartCol,
                row: targetStartRow
            }
        };
    }
}

exports.FormulaPasteProcessor = FormulaPasteProcessor;
//# sourceMappingURL=formula-paste-processor.js.map