import once from 'lodash/once';
export class NestedTableNodeStateOptimisticActions {
    constructor(node) {
        this.node = node;
    }
    _runAction(action, params) {
        const { node: { flatModeCollection, children }, } = this;
        const submit = once(params.submit);
        if (flatModeCollection?._optimisticActions) {
            action(flatModeCollection._optimisticActions, {
                ...params,
                submit,
                successToast: undefined,
                errorToast: undefined,
            });
        }
        if (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);
    }
}
//# sourceMappingURL=NestedTableNodeStateOptimisticActions.js.map