"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.NestedTableNodeStateOptimisticActions = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _once = _interopRequireDefault(require("lodash/once"));
class NestedTableNodeStateOptimisticActions {
  constructor(node) {
    (0, _defineProperty2.default)(this, "node", void 0);
    this.node = node;
  }
  _runAction(action, params) {
    const {
      node: {
        flatModeCollection,
        children
      }
    } = this;
    const submit = (0, _once.default)(params.submit);
    if (flatModeCollection != null && flatModeCollection._optimisticActions) {
      action(flatModeCollection._optimisticActions, {
        ...params,
        submit,
        successToast: undefined,
        errorToast: undefined
      });
    }
    if (children != null && children._optimisticActions) {
      action(children._optimisticActions, {
        ...params,
        submit
      });
    }
  }
  createOne(item, params) {
    this.createMany([item], params);
  }
  createMany(items, params) {
    this._runAction((a, p) => a.createMany(items, p), params);
  }
  updateAll(patchOrFn, params) {
    this._runAction((a, p) => a.updateAll(patchOrFn, p), params);
  }
  deleteMany(items, params) {
    this._runAction((a, p) => a.deleteMany(items, p), params);
  }
  deleteOne(item, params) {
    this.deleteMany([item], params);
  }
  deleteAll(params) {
    this._runAction((a, p) => a.deleteAll(p), params);
  }
  updateMany(items, params) {
    this._runAction((a, p) => a.updateMany(items, p), params);
  }
  updateOne(item, params) {
    this.updateMany([item], params);
  }
}
exports.NestedTableNodeStateOptimisticActions = NestedTableNodeStateOptimisticActions;
//# sourceMappingURL=NestedTableNodeStateOptimisticActions.js.map