"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const columns_1 = require("./columns");
function mapEditable({ insertable, readonly, myData, columns, }) {
    return insertable && !readonly
        ? {
            isEditHidden: () => true,
            onRowUpdate: async (newData, oldData) => {
                var _a;
                const dataUpdate = [].concat(myData);
                const index = oldData.tableData.id;
                dataUpdate[index] = newData;
                const type = (_a = insertable === null || insertable === void 0 ? void 0 : insertable.onUpdate) === null || _a === void 0 ? void 0 : _a.call(insertable, dataUpdate);
                if (type instanceof Promise) {
                    await type;
                }
                // 还原共享数据
                columns[columns_1.SHARED_DATA_KEY] = null;
            },
            onRowUpdateCancelled: () => {
                var _a;
                (_a = insertable === null || insertable === void 0 ? void 0 : insertable.onUpdate) === null || _a === void 0 ? void 0 : _a.call(insertable, myData.filter(i => !i['tableData'].isNew));
                // 还原共享数据
                columns[columns_1.SHARED_DATA_KEY] = null;
            },
        }
        : {};
}
exports.default = mapEditable;
