"use strict";

exports.__esModule = true;
exports.AlterStateService = void 0;
var _utils = require("../../../_utils/utils");
var _formKeyType = require("../../../_utils/formKeyType");
var _logicRenderService = require("../../../_utils/logicRenderService");
var _type = require("../../../_utils/conditionRenderService/type");
var _lodash = require("lodash");
var AlterStateService = exports.AlterStateService = /*#__PURE__*/function () {
  function AlterStateService() {
    this.logicRenderService = void 0;
    this.logicRenderService = new _logicRenderService.LogicRenderService();
  }
  var _proto = AlterStateService.prototype;
  _proto.addRowData = function addRowData(data) {
    data.push(this.createRowData());
    return [].concat(data);
  };
  _proto.copyRowData = function copyRowData(data, index) {
    var copyData = (0, _lodash.cloneDeep)(data[index]);
    copyData.id = (0, _utils.uuid)();
    data.splice(index + 1, 0, copyData);
    return [].concat(data);
  };
  _proto.removeRowData = function removeRowData(data, id) {
    return data.filter(function (item) {
      return item.id !== id;
    });
  };
  _proto.resetRowData = function resetRowData(data, id) {
    var newData = this.createRowData();
    var newResult = data.map(function (item) {
      if (item.id === id) {
        item = newData;
      }
      return item;
    });
    return newResult;
  };
  _proto.alterRowData = function alterRowData(config) {
    var oldData = config.oldData,
      id = config.id,
      logic = config.logic,
      value = config.value;
    return oldData.map(function (item) {
      if (item.id === id) {
        if (logic) {
          item.alterLogic = logic;
        }
        if (value) {
          item.alterValue = value;
        }
      }
      return item;
    });
  };
  _proto.getCopyAlterStateList = function getCopyAlterStateList(list) {
    var _this = this;
    var result = (0, _lodash.cloneDeep)(list);
    return result.map(function (item) {
      item.id = (0, _utils.uuid)();
      item.alterLogic = _this.handleCopyAlterLogic(item.alterLogic);
      return item;
    });
  };
  _proto.handleCopyAlterLogic = function handleCopyAlterLogic(logic) {
    var result = logic;
    result.data = this.logicRenderService.conditionRenderService.getCopyConditionData(result.data);
    return result;
  };
  _proto.createRowData = function createRowData() {
    return {
      id: (0, _utils.uuid)(),
      alterValue: {
        formKey: _formKeyType.DataSourceType.currentPageType,
        data: '',
        treeData: []
      },
      alterLogic: {
        data: this.logicRenderService.createConditionData(_type.ConditionType.computed),
        resultData: this.logicRenderService.createResultData()
      }
    };
  };
  return AlterStateService;
}();