"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ItemActionsState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
var _bexCore = require("@wix/bex-core");
class ItemActionsState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "keyedItem", void 0);
    (0, _defineProperty2.default)(this, "fade", void 0);
    (0, _defineProperty2.default)(this, "collection", void 0);
    (0, _defineProperty2.default)(this, "confirmModal", new _bexCore.ConditionalModalState());
    (0, _defineProperty2.default)(this, "actionCellAPI", void 0);
    this.fade = params.fade;
    this.keyedItem = params.keyedItem;
    this.collection = params.collection;
    (0, _mobx.makeObservable)(this, {
      keyedItem: _mobx.observable.ref,
      fade: _mobx.observable.ref,
      onFadeStart: _mobx.action.bound,
      onFadeDone: _mobx.action.bound,
      setItemIfChanged: _mobx.action,
      openConfirmModal: _mobx.action.bound,
      openConfirmDeleteModal: _mobx.action.bound
    });
    this.actionCellAPI = {
      openConfirmModal: this.openConfirmModal,
      openConfirmDeleteModal: this.openConfirmDeleteModal,
      collection: this.collection,
      keyedItem: this.keyedItem
    };
  }
  openConfirmModal(props) {
    const {
      translate: t
    } = this.collection;
    this.confirmModal.open({
      title: t('cairo.confirmModal.title'),
      primaryButtonText: t('cairo.confirm.button'),
      secondaryButtonText: t('cairo.cancel.button'),
      ...props
    });
  }
  openConfirmDeleteModal(props) {
    const {
      translate: t
    } = this.collection;
    this.openConfirmModal({
      theme: 'destructive',
      title: t('cairo.deleteModal.title'),
      content: t('cairo.deleteModal.body'),
      ...props
    });
  }
  onFadeStart() {
    if (this.fade === 'exit') {
      this.fade = 'exiting';
    }
  }
  onFadeDone() {
    const {
      fade
    } = this;
    if (fade === 'exiting') {
      this.fade = 'idle';
    }
  }
  setItemIfChanged(keyedItem) {
    if (this.keyedItem !== keyedItem) {
      this.keyedItem = keyedItem;
    }
  }
}
exports.ItemActionsState = ItemActionsState;
//# sourceMappingURL=ItemActionsState.js.map