"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.DeleteFieldModalState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
var _ConditionalModalState = require("./ConditionalModalState");
var _FieldOperationsBIReporter = require("./FieldOperationsBIReporter");
class DeleteFieldModalState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "biReporter", void 0);
    (0, _defineProperty2.default)(this, "fieldManagement", void 0);
    (0, _defineProperty2.default)(this, "archive", void 0);
    (0, _defineProperty2.default)(this, "modal", void 0);
    this.biReporter = new _FieldOperationsBIReporter.FieldOperationsBIReporter({
      reportBi: params.reportBi
    });
    this.fieldManagement = params.fieldManagement;
    this.archive = params.archive;
    this.modal = new _ConditionalModalState.ConditionalModalState({
      onConfirm: async () => {
        if (!this.modal.value) {
          return;
        }
        this.biReporter.reportDeleteFieldModalCtaClicked('Delete');
        await this.fieldManagement.deleteField(this.modal.value.id, this.modal.value.origin);

        // Close archived panel if no items left
        if (this.archive.items.length === 0) {
          this.archive.closePanel();
        }
      },
      onClose: () => {
        this.biReporter.reportDeleteFieldModalCtaClicked('Cancel');
      }
    });
    (0, _mobx.makeAutoObservable)(this);
  }
}
exports.DeleteFieldModalState = DeleteFieldModalState;
//# sourceMappingURL=DeleteFieldModalState.js.map