export function cloneDeep(input, cache = new WeakMap) {
    if (null == input) return input;
    const t = typeof input;
    if ("function" === t || "object" !== t) return input;
    const obj = input;
    if (obj instanceof Date) return new Date(obj.getTime());
    if (obj instanceof RegExp) return new RegExp(obj);
    if (cache.has(obj)) return cache.get(obj);
    if (Array.isArray(obj)) {
        const arr = [];
        cache.set(obj, arr);
        for (let i = 0; i < obj.length; i++) arr[i] = cloneDeep(obj[i], cache);
        return arr;
    }
    const out = {};
    return cache.set(obj, out), Object.keys(obj).forEach((key => {
        out[key] = cloneDeep(obj[key], cache);
    })), out;
}

export function captureSnapshot(table, state, options) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j;
    const tableOptions = table.options || {}, columns = tableOptions.columns;
    Array.isArray(columns) ? state.prevColumnsSnapshot = columns.map((c => cloneDeep(c))) : state.prevColumnsSnapshot = null;
    const merge = tableOptions.customMergeCell;
    Array.isArray(merge) ? state.prevMergeSnapshot = merge.map((m => Object.assign(Object.assign({}, m), {
        range: {
            start: Object.assign({}, m.range.start),
            end: Object.assign({}, m.range.end)
        }
    }))) : state.prevMergeSnapshot = merge;
    const records = table.records || [];
    Array.isArray(records) ? state.prevRecordsSnapshot = records.map((r => cloneRecord(r))) : state.prevRecordsSnapshot = null;
    try {
        const resizedRowIndexs = Array.from(null !== (_d = null === (_c = null === (_b = null === (_a = table.internalProps) || void 0 === _a ? void 0 : _a._heightResizedRowMap) || void 0 === _b ? void 0 : _b.keys) || void 0 === _c ? void 0 : _c.call(_b)) && void 0 !== _d ? _d : []);
        if (resizedRowIndexs.length && "function" == typeof table.getRowHeight) {
            const map = {};
            resizedRowIndexs.forEach((rowIndex => {
                if ("number" != typeof rowIndex) return;
                const h = table.getRowHeight(rowIndex);
                "number" == typeof h && (map[rowIndex] = h);
            })), state.prevResizedRowHeightsSnapshot = map;
        } else state.prevResizedRowHeightsSnapshot = null;
    } catch (_k) {
        state.prevResizedRowHeightsSnapshot = null;
    }
    try {
        const resizedColIndexs = Array.from(null !== (_h = null === (_g = null === (_f = null === (_e = table.internalProps) || void 0 === _e ? void 0 : _e._widthResizedColMap) || void 0 === _f ? void 0 : _f.keys) || void 0 === _g ? void 0 : _g.call(_f)) && void 0 !== _h ? _h : []);
        if (resizedColIndexs.length && "function" == typeof table.getColWidth) {
            const map = {};
            resizedColIndexs.forEach((colIndex => {
                if ("number" != typeof colIndex) return;
                const w = table.getColWidth(colIndex);
                "number" == typeof w && (map[colIndex] = w);
            })), state.prevResizedColWidthsSnapshot = map;
        } else state.prevResizedColWidthsSnapshot = null;
    } catch (_l) {
        state.prevResizedColWidthsSnapshot = null;
    }
    if ((null === (_j = null == options ? void 0 : options.formulaManager) || void 0 === _j ? void 0 : _j.exportFormulas) && options.sheetKey) try {
        const formulas = options.formulaManager.exportFormulas(options.sheetKey);
        state.prevFormulasSnapshot = formulas ? Object.assign({}, formulas) : null;
    } catch (_m) {
        state.prevFormulasSnapshot = null;
    } else state.prevFormulasSnapshot = null;
}

export function cloneRecord(record) {
    return Array.isArray(record) ? record.slice() : record && "object" == typeof record ? Object.assign({}, record) : record;
}
//# sourceMappingURL=snapshot.js.map
