import { uuid } from "../../../_utils/utils";
import { groupCategoryType, groupClassType, groupModeType } from "../type";
import { t } from "../../../../src/locale";
import { SchemaService } from "../../../_utils/schemaService";
import { EntryGroupIndexCallbackCodeList } from "@cverse/core-lib-vue-beta";
import { ComponentName } from "../../../_utils/treeDataRelationFn/type";
import { getValueByLang } from "../../../../src/utils/comfn/util";
import { EngineRuleState } from "../../../../src/utils/type";
var schemaService = new SchemaService();
export function createNewGroupItem() {
  return {
    groupId: "g_" + uuid(),
    groupName: '',
    groupCategory: groupCategoryType["default"],
    groupType: groupClassType.component,
    groupMode: groupModeType.single,
    groupList: []
  };
}
export function createNewGroupListItem(index) {
  return {
    code: '',
    groupIndex: index,
    selected: false,
    stateList: []
  };
}
export function createNewStateListItem(config) {
  var newName = config.name ? config.name : 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 : EngineRuleState.loading,
    code: '',
    isDelete: newIsDelete,
    selected: false,
    isIndexDisable: newIsIndexDisable
  };
}

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

/**
 * 获取按钮和图片等可以被选中的数据
 */
export function getBaseDataSourceBySchema() {
  var result = [];
  var buttonList = getButtonDataSourceBySchema();
  var imgList = getImageDataSourceBySchema();
  result = [].concat(buttonList, imgList);
  return result;
}
function getButtonDataSourceBySchema() {
  var result = schemaService.getBaseDataByType(ComponentName.Button);
  return result;
}
function getImageDataSourceBySchema() {
  var result = schemaService.getBaseDataByType(ComponentName.Image);
  return result;
}
export function getDefaultIndexOptions() {
  var result = [];
  var data = EntryGroupIndexCallbackCodeList;
  if (data !== null && data !== void 0 && data.length) {
    result = data.map(function (item) {
      return {
        label: getValueByLang(item.label) + "(" + item.value + ")",
        value: item.value,
        stateList: item.stateList.map(function (stateItem) {
          return {
            label: getValueByLang(stateItem.label) + "(" + stateItem.value + ")",
            value: stateItem.value
          };
        })
      };
    });
  }
  return result;
}
export 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;
}