"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.DataExtensionStateBIReporter = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _util = require("../util");
var _v = require("@wix/bex-utils/@wix/bi-logger-os-data/v2");
class DataExtensionStateBIReporter {
  constructor(params) {
    (0, _defineProperty2.default)(this, "reportBi", void 0);
    (0, _defineProperty2.default)(this, "reportArchiveFieldModalCtaClicked", ctaName => {
      this.reportBi((0, _util.withoutDefaults)(_v.cairoModalCtaClicked)({
        ctaName,
        modalName: 'Archive custom field'
      }));
    });
    (0, _defineProperty2.default)(this, "reportDeleteFieldModalCtaClicked", ctaName => {
      this.reportBi((0, _util.withoutDefaults)(_v.cairoModalCtaClicked)({
        ctaName,
        modalName: 'Delete custom field'
      }));
    });
    (0, _defineProperty2.default)(this, "reportArchiveFieldFailed", ({
      origin,
      formValues
    }) => {
      if (!formValues) {
        return;
      }
      this.reportBi((0, _util.withoutDefaults)(_v.cairoDataExtensionUnsuccessfulUpdateInServer)({
        actionName: 'Archive',
        errorType: 'Technical issue',
        origin,
        permissions: this.getBiPermissions(formValues),
        fieldType: formValues.type,
        fieldName: formValues.name,
        key: formValues.key
      }));
    });
    (0, _defineProperty2.default)(this, "reportArchiveTryAgain", () => {
      this.reportBi((0, _util.withoutDefaults)(_v.cairoTryAgainClicked)({
        actionName: 'Archive custom field',
        loaction: 'toast'
      }));
    });
    (0, _defineProperty2.default)(this, "reportRestoreFieldFailed", ({
      origin,
      formValues
    }) => {
      if (!formValues) {
        return;
      }
      this.reportBi((0, _util.withoutDefaults)(_v.cairoDataExtensionUnsuccessfulUpdateInServer)({
        actionName: 'Restore',
        errorType: 'Technical issue',
        origin,
        permissions: this.getBiPermissions(formValues),
        fieldType: formValues.type,
        fieldName: formValues.name,
        key: formValues.key
      }));
    });
    (0, _defineProperty2.default)(this, "reportRestoreTryAgain", () => {
      this.reportBi((0, _util.withoutDefaults)(_v.cairoTryAgainClicked)({
        actionName: 'Restore custom field',
        loaction: 'toast'
      }));
    });
    const {
      reportBi
    } = params;
    this.reportBi = reportBi;
  }
  getBiPermissions(formValues) {
    const {
      readApps,
      readUsers,
      writeApps,
      writeUsers
    } = formValues;
    const apps = [];
    const users = [];
    if (readApps) {
      apps.push('Read');
    }
    if (writeApps) {
      apps.push('Write');
    }
    if (readUsers) {
      users.push('Read');
    }
    if (writeUsers) {
      users.push('Write');
    }
    return JSON.stringify({
      'Installed apps': apps.length !== 0 ? apps.join(' and ') : null,
      'Site visitors': users.length !== 0 ? users.join(' and ') : null
    });
  }
}
exports.DataExtensionStateBIReporter = DataExtensionStateBIReporter;
//# sourceMappingURL=DataExtensionStateBIReporter.js.map