import { formatAddress } from '@bilig/formula';
export function cloneCellMutationAt(mutation) {
    switch (mutation.kind) {
        case 'setCellValue':
            return {
                kind: 'setCellValue',
                row: mutation.row,
                col: mutation.col,
                value: mutation.value,
            };
        case 'setCellFormula':
            return {
                kind: 'setCellFormula',
                row: mutation.row,
                col: mutation.col,
                formula: mutation.formula,
            };
        case 'clearCell':
            return {
                kind: 'clearCell',
                row: mutation.row,
                col: mutation.col,
            };
    }
}
export function cloneCellMutationRef(ref) {
    return {
        sheetId: ref.sheetId,
        mutation: cloneCellMutationAt(ref.mutation),
        ...(ref.cellIndex !== undefined ? { cellIndex: ref.cellIndex } : {}),
    };
}
export function cellMutationRefToEngineOp(workbook, ref) {
    const sheet = workbook.getSheetById(ref.sheetId);
    if (!sheet) {
        throw new Error(`Unknown sheet id: ${ref.sheetId}`);
    }
    const address = formatAddress(ref.mutation.row, ref.mutation.col);
    switch (ref.mutation.kind) {
        case 'setCellValue':
            return {
                kind: 'setCellValue',
                sheetName: sheet.name,
                address,
                value: ref.mutation.value,
            };
        case 'setCellFormula':
            return {
                kind: 'setCellFormula',
                sheetName: sheet.name,
                address,
                formula: ref.mutation.formula,
            };
        case 'clearCell':
            return {
                kind: 'clearCell',
                sheetName: sheet.name,
                address,
            };
    }
}
export function countPotentialNewCellsForMutationRefs(refs) {
    let count = 0;
    for (let index = 0; index < refs.length; index += 1) {
        if (refs[index]?.mutation.kind !== 'clearCell') {
            count += 1;
        }
    }
    return count;
}
//# sourceMappingURL=cell-mutations-at.js.map