"use strict";

exports.__esModule = true;
exports.createNewGroupItem = createNewGroupItem;
exports.createNewGroupListItem = createNewGroupListItem;
exports.createNewStateListItem = createNewStateListItem;
exports.getBaseDataSourceBySchema = getBaseDataSourceBySchema;
exports.getColDataSourceBySchema = getColDataSourceBySchema;
exports.getDefaultIndexOptions = getDefaultIndexOptions;
exports.getStateListByGroupIndex = getStateListByGroupIndex;
var _utils = require("../../../_utils/utils");
var _type = require("../type");
var _locale = require("../../../../src/locale");
var _schemaService = require("../../../_utils/schemaService");
var _coreLibVueBeta = require("@cverse/core-lib-vue-beta");
var _type2 = require("../../../_utils/treeDataRelationFn/type");
var _util = require("../../../../src/utils/comfn/util");
var _type3 = require("../../../../src/utils/type");
var schemaService = new _schemaService.SchemaService();
function createNewGroupItem() {
  return {
    groupId: "g_" + (0, _utils.uuid)(),
    groupName: '',
    groupCategory: _type.groupCategoryType["default"],
    groupType: _type.groupClassType.component,
    groupMode: _type.groupModeType.single,
    groupList: []
  };
}
function createNewGroupListItem(index) {
  return {
    code: '',
    groupIndex: index,
    selected: false,
    stateList: []
  };
}
function createNewStateListItem(config) {
  var newName = config.name ? config.name : (0, _locale.t)('page.stateCreateName');
  var newIsDelete = config.isDelete !== undefined ? config.isDelete : true;
  var newIsIndexDisable = config.isIndexDisable !== undefined ? config.isIndexDisable : false;
  return {
    name: newName,
    state: config.state !== undefined ? config.state : _type3.EngineRuleState.loading,
    code: '',
    isDelete: newIsDelete,
    selected: false,
    isIndexDisable: newIsIndexDisable
  };
}

/**
 * 获取所有的槽位数据
 */
function getColDataSourceBySchema() {
  var result = schemaService.getColDataSourceList();
  return result;
}

/**
 * 获取按钮和图片等可以被选中的数据
 */
function getBaseDataSourceBySchema() {
  var result = [];
  var buttonList = getButtonDataSourceBySchema();
  var imgList = getImageDataSourceBySchema();
  result = [].concat(buttonList, imgList);
  return result;
}
function getButtonDataSourceBySchema() {
  var result = schemaService.getBaseDataByType(_type2.ComponentName.Button);
  return result;
}
function getImageDataSourceBySchema() {
  var result = schemaService.getBaseDataByType(_type2.ComponentName.Image);
  return result;
}
function getDefaultIndexOptions() {
  var result = [];
  var data = _coreLibVueBeta.EntryGroupIndexCallbackCodeList;
  if (data !== null && data !== void 0 && data.length) {
    result = data.map(function (item) {
      return {
        label: (0, _util.getValueByLang)(item.label) + "(" + item.value + ")",
        value: item.value,
        stateList: item.stateList.map(function (stateItem) {
          return {
            label: (0, _util.getValueByLang)(stateItem.label) + "(" + stateItem.value + ")",
            value: stateItem.value
          };
        })
      };
    });
  }
  return result;
}
function getStateListByGroupIndex(groupIndex) {
  var result = [];
  var list = getDefaultIndexOptions();
  var groupItem = list.find(function (item) {
    return item.value === groupIndex;
  });
  if (groupItem && groupItem.stateList) {
    groupItem.stateList.forEach(function (item) {
      var obj = createNewStateListItem({
        name: item.label,
        state: item.value,
        isDelete: false,
        isIndexDisable: true
      });
      result.push(obj);
    });
  }
  return result;
}