"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.enhanceCellDataWithFormula = exports.CustomFormulaAdapter = exports.createFormulaAdapter = exports.DefaultFormulaAdapter = void 0;

class DefaultFormulaAdapter {
    constructor(table) {
        this.table = table;
    }
    isFormulaCell(col, row) {
        const cellValue = this.table.getCellValue(col, row);
        return "string" == typeof cellValue && cellValue.startsWith("=");
    }
    getCellFormula(col, row) {
        const cellValue = this.table.getCellValue(col, row);
        if ("string" == typeof cellValue && cellValue.startsWith("=")) return cellValue;
    }
    setCellFormula(col, row, formula) {
        this.table.changeCellValue(col, row, formula);
    }
    getCalculatedValue(col, row) {
        return this.table.getCellValue(col, row);
    }
    refreshFormulas() {}
    hasFormulaEngine() {
        return !1;
    }
}

function createFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula) {
    return customIsFormulaCell || customGetCellFormula || customSetCellFormula ? new CustomFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula) : new DefaultFormulaAdapter(table);
}

exports.DefaultFormulaAdapter = DefaultFormulaAdapter, exports.createFormulaAdapter = createFormulaAdapter;

class CustomFormulaAdapter {
    constructor(table, isFormulaCellFn, getCellFormulaFn, setCellFormulaFn) {
        this.table = table, this.isFormulaCellFn = isFormulaCellFn, this.getCellFormulaFn = getCellFormulaFn, 
        this.setCellFormulaFn = setCellFormulaFn;
    }
    isFormulaCell(col, row) {
        if (this.isFormulaCellFn) {
            const cellData = this.table.getCellValue(col, row);
            return this.isFormulaCellFn(col, row, cellData, this.table);
        }
        const cellValue = this.table.getCellValue(col, row);
        return "string" == typeof cellValue && cellValue.startsWith("=");
    }
    getCellFormula(col, row) {
        if (this.getCellFormulaFn) {
            const cellData = this.table.getCellValue(col, row);
            return this.getCellFormulaFn(col, row, cellData, this.table);
        }
        const cellValue = this.table.getCellValue(col, row);
        if ("string" == typeof cellValue && cellValue.startsWith("=")) return cellValue;
    }
    setCellFormula(col, row, formula) {
        this.setCellFormulaFn ? this.setCellFormulaFn(col, row, formula, this.table) : this.table.changeCellValue(col, row, formula);
    }
    getCalculatedValue(col, row) {
        return this.table.getCellValue(col, row);
    }
    refreshFormulas() {}
    hasFormulaEngine() {
        return !1;
    }
}

function enhanceCellDataWithFormula(cellData, col, row, formulaAdapter) {
    const enhanced = Object.assign({}, cellData);
    return formulaAdapter.isFormulaCell(col, row) && (enhanced.isFormula = !0, enhanced.formula = formulaAdapter.getCellFormula(col, row), 
    enhanced.calculatedValue = formulaAdapter.getCalculatedValue(col, row)), enhanced;
}

exports.CustomFormulaAdapter = CustomFormulaAdapter, exports.enhanceCellDataWithFormula = enhanceCellDataWithFormula;
//# sourceMappingURL=formula-integration.js.map