"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 _DataExtensionStateBIReporter = require("./DataExtensionStateBIReporter");
class DeleteFieldModalState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "biReporter", void 0);
    (0, _defineProperty2.default)(this, "dataExtension", void 0);
    (0, _defineProperty2.default)(this, "modal", void 0);
    this.biReporter = new _DataExtensionStateBIReporter.DataExtensionStateBIReporter({
      reportBi: params.reportBi
    });
    this.modal = new _ConditionalModalState.ConditionalModalState({
      onConfirm: async () => {
        if (!this.modal.value) {
          return;
        }
        this.biReporter.reportDeleteFieldModalCtaClicked('Delete');
        await this.dataExtension.deleteField({
          ...this.modal.value,
          reportBi: this.biReporter.reportBi
        });

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