"use strict";

function columnStringToIndex(colStr) {
    let col = 0;
    for (let i = 0; i < colStr.length; i++) col = 26 * col + (colStr.charCodeAt(i) - 64);
    return col - 1;
}

function columnIndexToString(colIndex) {
    let colStr = "", tempCol = colIndex + 1;
    do {
        tempCol -= 1, colStr = String.fromCharCode(65 + tempCol % 26) + colStr, tempCol = Math.floor(tempCol / 26);
    } while (tempCol > 0);
    return colStr;
}

function dataToRecords(data) {
    if (!data || !data.length) return [];
    const records = [], headerRow = data[0];
    for (let i = 1; i < data.length; i++) {
        const row = data[i], record = {};
        for (let j = 0; j < row.length; j++) {
            record[headerRow && j < headerRow.length ? headerRow[j] : j.toString()] = row[j];
        }
        records.push(record);
    }
    return records;
}

function recordsToData(records, columns) {
    if (!records || !records.length) return [];
    const data = [], headerRow = columns.map((col => col.title || col.field));
    data.push(headerRow);
    for (const record of records) {
        const row = columns.map((col => record[col.field]));
        data.push(row);
    }
    return data;
}

function excludeEditCellFromSelection(range, editRow, editCol) {
    const r = Object.assign({}, range), withinRow = r.startRow <= editRow && editRow <= r.endRow, withinCol = r.startCol <= editCol && editCol <= r.endCol;
    if (!withinRow || !withinCol) return r;
    const rowSpan = r.endRow - r.startRow, colSpan = r.endCol - r.startCol;
    return 0 === rowSpan && 0 === colSpan && r.startRow === editRow && r.startCol === editCol ? {
        startRow: -1,
        startCol: -1,
        endRow: -1,
        endCol: -1
    } : (rowSpan >= colSpan ? editRow === r.startRow && r.startRow < r.endRow ? r.startRow += 1 : editRow === r.endRow && r.startRow < r.endRow ? r.endRow -= 1 : r.startRow < r.endRow && (r.startRow += 1) : editCol === r.startCol && r.startCol < r.endCol ? r.startCol += 1 : editCol === r.endCol && r.startCol < r.endCol ? r.endCol -= 1 : r.startCol < r.endCol && (r.startCol += 1), 
    r);
}

function pluginIsChanged(prevPlugins, newPlugins) {
    return !(!prevPlugins && !newPlugins) && (!(prevPlugins || !newPlugins) || (!(!prevPlugins || newPlugins) || prevPlugins.some(((prevPlugin, index) => {
        const newPlugin = newPlugins[index];
        return newPlugin.module !== prevPlugin.module || pluginOptionsIsChanged(newPlugin.moduleOptions, prevPlugin.moduleOptions);
    }))));
}

function pluginOptionsIsChanged(prevPluginOptions, newPluginOptions) {
    return !(!prevPluginOptions && !newPluginOptions) && (!(prevPluginOptions || !newPluginOptions) || (!(!prevPluginOptions || newPluginOptions) || JSON.stringify(prevPluginOptions) !== JSON.stringify(newPluginOptions)));
}

//# sourceMappingURL=sheet-helper.js.map
Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.pluginIsChanged = exports.excludeEditCellFromSelection = exports.recordsToData = exports.dataToRecords = exports.columnIndexToString = exports.columnStringToIndex = void 0, 
exports.columnStringToIndex = columnStringToIndex, exports.columnIndexToString = columnIndexToString, 
exports.dataToRecords = dataToRecords, exports.recordsToData = recordsToData, exports.excludeEditCellFromSelection = excludeEditCellFromSelection, 
exports.pluginIsChanged = pluginIsChanged;