import { SelectionMode } from "./ts-types";

export function initOptions(options) {
    var _a, _b, _c, _d, _e, _f, _g;
    return {
        defaultRowHeight: null !== (_a = options.defaultRowHeight) && void 0 !== _a ? _a : 25,
        defaultColWidth: null !== (_b = options.defaultColWidth) && void 0 !== _b ? _b : 100,
        showRowHeader: null === (_c = options.showRowHeader) || void 0 === _c || _c,
        showColHeader: null === (_d = options.showColHeader) || void 0 === _d || _d,
        editable: null === (_e = options.editable) || void 0 === _e || _e,
        theme: null !== (_f = options.theme) && void 0 !== _f ? _f : "light",
        selectionMode: null !== (_g = options.selectionMode) && void 0 !== _g ? _g : SelectionMode.CELL,
        pixelRatio: window.devicePixelRatio || 1
    };
}

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

export 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;
}

export 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;
}

export 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;
}
//# sourceMappingURL=sheet-helper.js.map