import _extends from "@babel/runtime/helpers/extends";
import { IPublicEnumTransformStage } from '@clc/lowcode-types';
import { project } from '@alilc/lowcode-engine';
import { isArray } from 'lodash';
import { ComponentName, TreeType } from "./treeDataRelationFn/type";
import { t } from "../../src/locale/index";
import { getLocationParamsByName, uuid } from "./utils";
import { refreshType } from "./formKeyType";
import { groupCategoryType } from "../_setters/cGroupManage-setter/type";
import { StorageDataBType, StorageLocalType } from "../_setters/cBehavior-setter/type";
import { dataSource } from "../../src/utils/dataSource";
import { isEffectiveEventFlow } from "../../src/utils/comfn/util";
import { FlowEventService } from "../_setters/cFlowEvent-setter/page/service";
import { LowCodeWebGidKey } from "../../src/utils/type";
/**
 * 提供一个schemaService的类
 * 用于查询各种schema里面的内容
 */
export var SchemaService = /*#__PURE__*/function () {
  function SchemaService() {}
  var _proto = SchemaService.prototype;
  _proto.getWebGidBySchemaProps = function getWebGidBySchemaProps() {
    var _componentsTree$props;
    var result = LowCodeWebGidKey.localhost;
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && (_componentsTree$props = componentsTree.props) !== null && _componentsTree$props !== void 0 && _componentsTree$props.webGid) {
      var _componentsTree$props2;
      result = (_componentsTree$props2 = componentsTree.props) === null || _componentsTree$props2 === void 0 ? void 0 : _componentsTree$props2.webGid;
    } else {
      // 尝试从地址栏获取
      result = getLocationParamsByName("webGid") || LowCodeWebGidKey.localhost;
    }
    return result;
  }
  /**
   * 获取弹框信息
   * @returns
   */;
  _proto.getModalList = function getModalList() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getModalBySchemaChildren(children);
    }
    return result;
  }

  /**
   * 这里schema配置有点特殊，编辑态会使用(window as any).top?.AliLowCodeEngine
   * 预览态 (window as any).PageSchema
   * @returns
   */;
  _proto.getDictionaryList = function getDictionaryList(webGid) {
    var result = [];
    if (webGid) {
      var _schema$dictionary;
      var schema = this.getPageSchemaByWebGid(webGid);
      if (schema !== null && schema !== void 0 && (_schema$dictionary = schema.dictionary) !== null && _schema$dictionary !== void 0 && _schema$dictionary.list) {
        result = schema.dictionary.list;
      } else {
        var preViewLock = sessionStorage.getItem('preViewLock');
        if (preViewLock === 'open') {
          var _themePreview$compone, _themePreview$compone2;
          var themePreview = JSON.parse(sessionStorage.getItem('themePreview') || '');
          return ((_themePreview$compone = themePreview.componentsTree) === null || _themePreview$compone === void 0 ? void 0 : (_themePreview$compone2 = _themePreview$compone[0].dictionary) === null || _themePreview$compone2 === void 0 ? void 0 : _themePreview$compone2.list) || [];
        }
        result = this.getDictionaryByWindow();
      }
    } else {
      result = this.getDictionaryByWindow();
    }
    return result;
  };
  _proto.getPageSchemaByWebGid = function getPageSchemaByWebGid(webGid) {
    var pageSchema;
    var webGidObj = dataSource.getPageThisStateByWebGid(webGid);
    if (webGidObj && webGidObj.getPageThis) {
      var page = webGidObj.getPageThis();
      pageSchema = page.props.schema;
    }
    return pageSchema;
  }

  /**
   * 获取到全局数据源配置
   * @returns
   */;
  _proto.getDataSourceList = function getDataSourceList(webGid) {
    var result = [];
    if (webGid) {
      var _schema$dataSource;
      var schema = this.getPageSchemaByWebGid(webGid);
      if (schema !== null && schema !== void 0 && (_schema$dataSource = schema.dataSource) !== null && _schema$dataSource !== void 0 && _schema$dataSource.list) {
        result = schema.dataSource.list;
      } else {
        result = this.getDataSourceByWindow();
      }
    } else {
      result = this.getDataSourceByWindow();
    }
    return result;
  }
  /**
   * 获取全局自定义变量
   */;
  _proto.getCustomStateList = function getCustomStateList(webGid) {
    var result = {};
    if (webGid) {
      var _schema$state, _schema$state$customS;
      var schema = this.getPageSchemaByWebGid(webGid);
      if (schema !== null && schema !== void 0 && (_schema$state = schema.state) !== null && _schema$state !== void 0 && (_schema$state$customS = _schema$state.customState) !== null && _schema$state$customS !== void 0 && _schema$state$customS.value) {
        result = JSON.parse(schema.state.customState.value);
      } else {
        result = this.getCustomStateByWindow();
      }
    } else {
      result = this.getCustomStateByWindow();
    }
    return result;
  }

  /**
   * 获取指定的事件流
   * @param webGid
   * @param key
   * @returns
   */;
  _proto.getFlowEventConfigByGidAndKey = function getFlowEventConfigByGidAndKey(webGid, key) {
    var result;
    var schema = this.getPageSchemaByWebGid(webGid);
    if (schema !== null && schema !== void 0 && schema.children) {
      result = this.getFlowEventConfigByGidAndKeyMain(schema.children, key);
    }
    return result;
  };
  _proto.getDataSourceByWindow = function getDataSourceByWindow() {
    var result = [];
    try {
      var _top;
      if ((_top = window.top) !== null && _top !== void 0 && _top.AliLowCodeEngine) {
        var _componentsTree$dataS;
        var _project = window.top.AliLowCodeEngine.project;
        var schema = _project.exportSchema();
        var componentsTree = schema.componentsTree[0];
        if (componentsTree !== null && componentsTree !== void 0 && (_componentsTree$dataS = componentsTree.dataSource) !== null && _componentsTree$dataS !== void 0 && _componentsTree$dataS.list) {
          result = componentsTree.dataSource.list;
        }
      }
    } catch (error) {
      console.error(error);
    }
    return result;
  };
  _proto.getCustomStateByWindow = function getCustomStateByWindow() {
    var result = {};
    try {
      var _top2;
      if ((_top2 = window.top) !== null && _top2 !== void 0 && _top2.AliLowCodeEngine) {
        var _componentsTree$state, _componentsTree$state2;
        var _project2 = window.top.AliLowCodeEngine.project;
        var schema = _project2.exportSchema();
        var componentsTree = schema.componentsTree[0];
        var customState = componentsTree === null || componentsTree === void 0 ? void 0 : (_componentsTree$state = componentsTree.state) === null || _componentsTree$state === void 0 ? void 0 : (_componentsTree$state2 = _componentsTree$state.customState) === null || _componentsTree$state2 === void 0 ? void 0 : _componentsTree$state2.value;
        if (customState) {
          result = JSON.parse(customState);
        }
      }
    } catch (error) {
      console.error(error);
    }
    return result;
  };
  _proto.getDictionaryByWindow = function getDictionaryByWindow() {
    var result = [];
    try {
      var _top3;
      if ((_top3 = window.top) !== null && _top3 !== void 0 && _top3.AliLowCodeEngine) {
        var _componentsTree$dicti;
        var _project3 = window.top.AliLowCodeEngine.project;
        var schema = _project3.exportSchema();
        var componentsTree = schema.componentsTree[0];
        if (componentsTree !== null && componentsTree !== void 0 && (_componentsTree$dicti = componentsTree.dictionary) !== null && _componentsTree$dicti !== void 0 && _componentsTree$dicti.list) {
          result = componentsTree.dictionary.list;
        }
      }
    } catch (error) {
      console.error(error);
    }
    return result;
  }

  /**
   * 得到刷新列表
   * @returns
   */;
  _proto.getRefreshList = function getRefreshList() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getRefreshBySchemaChildren(children);
      var addShiftListData = [{
        label: t('setter.refreshLabel'),
        value: refreshType.refreshPage
      }, {
        label: t('setter.refreshBaseInfo'),
        value: refreshType.refreshBaseInfo
      }];
      result = [].concat(addShiftListData, result);
    }
    return result;
  }

  /**
   * 处理循环组件唯一标识,排除自己
   * 这里可能存在后补 ComponentName.CarouselBox 问题
   * @param dragNode
   * @param currentNode
   */;
  _proto.handleLoopBoxComponent = function handleLoopBoxComponent(dragNode, currentNode) {
    if (dragNode.componentName === 'Slot' && dragNode.parent.componentName === ComponentName.LoopBox) {
      var oldKey = currentNode.getPropValue('componentKey');
      var id = currentNode.id;
      var isRes = this.checkComponentKey(oldKey, id);
      if (isRes) {
        currentNode.setPropValue('componentKey', "loopRef_" + uuid());
      }
    }
  }

  /**
   * 检测组件标识是否重复
   * 带补充，这里暂时只支持loopBox循环组件
   * @param value
   */;
  _proto.checkComponentKey = function checkComponentKey(value, id) {
    var result = false;
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getPropsKeyInSchema(children, 'componentKey', value, id);
    }
    return result;
  }

  /**
   * 获取所有的槽位
   * @returns
   */;
  _proto.getColDataSourceList = function getColDataSourceList() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getColDataSourceBySchema(children, ComponentName.Col);
    }
    return result;
  }

  /**
   * 获取按钮或图片的下拉选择数据
   * @param name
   */;
  _proto.getBaseDataByType = function getBaseDataByType(name) {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getColDataSourceBySchema(children, name);
    }
    return result;
  }

  /**
   * 获取页面组管理信息
   */;
  _proto.getPageGroupListData = function getPageGroupListData(category) {
    var _componentsTree$props3;
    if (category === void 0) {
      category = groupCategoryType["default"];
    }
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree.componentName === ComponentName.Page && (_componentsTree$props3 = componentsTree.props) !== null && _componentsTree$props3 !== void 0 && _componentsTree$props3.groupManager) {
      var _componentsTree$props4;
      var list = (_componentsTree$props4 = componentsTree.props) === null || _componentsTree$props4 === void 0 ? void 0 : _componentsTree$props4.groupManager;
      if (list && list.length) {
        list.forEach(function (item) {
          result.push(_extends({}, item, {
            label: item.groupName,
            value: item.groupId
          }));
        });
      }
    }
    if (category === groupCategoryType.allPurpose) {
      result = result.filter(function (item) {
        return item.groupCategory === groupCategoryType.allPurpose;
      });
    }
    return result;
  };
  _proto.getVideoListData = function getVideoListData() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getVideoListMain(children);
    }
    return result;
  }
  /**
   * 获取转盘组件
   * @returns
   */;
  _proto.getRotateWheelListData = function getRotateWheelListData() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getRotateWheelListMain(children);
    }
    return result;
  }

  /**
   * 获取动画组件 目前支持图片 按钮
   * @returns
   */;
  _proto.getAnimationListData = function getAnimationListData() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getAnimationListMain(children);
    }
    return result;
  }

  /**
   * 获取轮播图组件
   * @returns
   */;
  _proto.getCarouselListData = function getCarouselListData() {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = this.getCarouselListMain(children);
    }
    return result;
  }

  /**
   * 获取page.props.customStateStorageList
   * 和所有子组件的事件流涉及到本地存储的模块
   * 追加一个人机校验的本地存储
   * @returns
   */;
  _proto.getStorageDataRelation = function getStorageDataRelation() {
    var _componentsTree$props6, _componentsTree$props7, _componentsTree$props8;
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var _componentsTree$props5;
      var children = componentsTree.children;
      result = result.concat(this.getStorageKeyByPropsFlowEventConfig(componentsTree === null || componentsTree === void 0 ? void 0 : (_componentsTree$props5 = componentsTree.props) === null || _componentsTree$props5 === void 0 ? void 0 : _componentsTree$props5.flowEventConfig));
      result = result.concat(this.getStorageDataRelationMain(children));
    }

    // 追加page.props.idMap.customStateStorageList里面的数据
    if ((_componentsTree$props6 = componentsTree.props) !== null && _componentsTree$props6 !== void 0 && (_componentsTree$props7 = _componentsTree$props6.idMap) !== null && _componentsTree$props7 !== void 0 && _componentsTree$props7.customStateStorageList && isArray((_componentsTree$props8 = componentsTree.props) === null || _componentsTree$props8 === void 0 ? void 0 : _componentsTree$props8.idMap.customStateStorageList)) {
      componentsTree.props.idMap.customStateStorageList.forEach(function (item) {
        result.push({
          label: item.key + "_custom",
          key: item.key,
          type: TreeType.storageDataItem
        });
      });
    }
    result.push({
      label: 'googleCaptcha',
      key: StorageLocalType.GoogleCaptcha,
      type: TreeType.storageDataItem
    });
    return result;
  };
  _proto.getFlowEventOptionsBySchema = function getFlowEventOptionsBySchema(componentKey) {
    var result = [];
    var componentsTree = this.getComponentsTreeBySchema();
    if (componentsTree && componentsTree.children && isArray(componentsTree.children)) {
      var children = componentsTree.children;
      result = result.concat(this.getFlowEventOptionsBySchemaMain(children, componentKey));
    }
    return result;
  };
  _proto.getColDataSourceBySchema = function getColDataSourceBySchema(children, name) {
    var _this = this;
    var result = [];
    if (children && children.length) {
      children.forEach(function (item) {
        var _item$children;
        if (item.componentName === name) {
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || 'error_key'
          });
        }
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot;
            slotData = isArray((_item$props$loopSlot = item.props.loopSlot) === null || _item$props$loopSlot === void 0 ? void 0 : _item$props$loopSlot.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS;
            slotData = isArray((_item$props$carouselS = item.props.carouselSlot) === null || _item$props$carouselS === void 0 ? void 0 : _item$props$carouselS.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this.getColDataSourceBySchema(slotDataChildren, name));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items;
          var list = [];
          if ((_item$props$items = item.props.items) !== null && _item$props$items !== void 0 && _item$props$items.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children, _itemOne$children$val;
              list = list.concat(((_itemOne$children = itemOne.children) === null || _itemOne$children === void 0 ? void 0 : (_itemOne$children$val = _itemOne$children.value) === null || _itemOne$children$val === void 0 ? void 0 : _itemOne$children$val.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this.getColDataSourceBySchema(list, name));
          }
        }
        if ((_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length) {
          result = result.concat(_this.getColDataSourceBySchema(item.children, name));
        }
      });
    }
    return result;
  };
  _proto.getVideoListMain = function getVideoListMain(children) {
    var _this2 = this;
    var result = [];
    if (children && children.length) {
      children.forEach(function (item) {
        var _item$children2;
        if (item.componentName === ComponentName.ToolVideo) {
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || 'error_key',
            groupList: _this2.getVideoGroupList(item.props.stepsVideo)
          });
        }
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot2;
            slotData = isArray((_item$props$loopSlot2 = item.props.loopSlot) === null || _item$props$loopSlot2 === void 0 ? void 0 : _item$props$loopSlot2.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS2;
            slotData = isArray((_item$props$carouselS2 = item.props.carouselSlot) === null || _item$props$carouselS2 === void 0 ? void 0 : _item$props$carouselS2.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this2.getVideoListMain(slotDataChildren));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items2;
          var list = [];
          if ((_item$props$items2 = item.props.items) !== null && _item$props$items2 !== void 0 && _item$props$items2.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children2, _itemOne$children2$va;
              list = list.concat(((_itemOne$children2 = itemOne.children) === null || _itemOne$children2 === void 0 ? void 0 : (_itemOne$children2$va = _itemOne$children2.value) === null || _itemOne$children2$va === void 0 ? void 0 : _itemOne$children2$va.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this2.getVideoListMain(list));
          }
        }
        if ((_item$children2 = item.children) !== null && _item$children2 !== void 0 && _item$children2.length) {
          result = result.concat(_this2.getVideoListMain(item.children));
        }
      });
    }
    return result;
  }

  /**
   * 获取转盘组件
   * @param children
   * @returns
   */;
  _proto.getRotateWheelListMain = function getRotateWheelListMain(children) {
    var _this3 = this;
    var result = [];
    if (children && children.length) {
      children.forEach(function (item) {
        var _item$children3;
        if (item.componentName === ComponentName.RotateWheel) {
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || 'error_key',
            groupList: _this3.getVideoGroupList(item.props.stepsVideo)
          });
        }
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot3;
            slotData = isArray((_item$props$loopSlot3 = item.props.loopSlot) === null || _item$props$loopSlot3 === void 0 ? void 0 : _item$props$loopSlot3.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS3;
            slotData = isArray((_item$props$carouselS3 = item.props.carouselSlot) === null || _item$props$carouselS3 === void 0 ? void 0 : _item$props$carouselS3.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this3.getRotateWheelListMain(slotDataChildren));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items3;
          var list = [];
          if ((_item$props$items3 = item.props.items) !== null && _item$props$items3 !== void 0 && _item$props$items3.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children3, _itemOne$children3$va;
              list = list.concat(((_itemOne$children3 = itemOne.children) === null || _itemOne$children3 === void 0 ? void 0 : (_itemOne$children3$va = _itemOne$children3.value) === null || _itemOne$children3$va === void 0 ? void 0 : _itemOne$children3$va.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this3.getRotateWheelListMain(list));
          }
        }
        if ((_item$children3 = item.children) !== null && _item$children3 !== void 0 && _item$children3.length) {
          result = result.concat(_this3.getRotateWheelListMain(item.children));
        }
      });
    }
    return result;
  }

  /**
   * 获取动画组件 目前支持图片 按钮
   * @param children
   * @returns
   */;
  _proto.getAnimationListMain = function getAnimationListMain(children) {
    var _this4 = this;
    var result = [];
    if (children && children.length) {
      children.forEach(function (item) {
        var _item$children4;
        if (item.componentName === ComponentName.Image || item.componentName === ComponentName.Button || item.componentName === ComponentName.Col) {
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || 'error_key'
          });
        }
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot4;
            slotData = isArray((_item$props$loopSlot4 = item.props.loopSlot) === null || _item$props$loopSlot4 === void 0 ? void 0 : _item$props$loopSlot4.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS4;
            slotData = isArray((_item$props$carouselS4 = item.props.carouselSlot) === null || _item$props$carouselS4 === void 0 ? void 0 : _item$props$carouselS4.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this4.getAnimationListMain(slotDataChildren));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items4;
          var list = [];
          if ((_item$props$items4 = item.props.items) !== null && _item$props$items4 !== void 0 && _item$props$items4.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children4, _itemOne$children4$va;
              list = list.concat(((_itemOne$children4 = itemOne.children) === null || _itemOne$children4 === void 0 ? void 0 : (_itemOne$children4$va = _itemOne$children4.value) === null || _itemOne$children4$va === void 0 ? void 0 : _itemOne$children4$va.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this4.getAnimationListMain(list));
          }
        }
        if ((_item$children4 = item.children) !== null && _item$children4 !== void 0 && _item$children4.length) {
          result = result.concat(_this4.getAnimationListMain(item.children));
        }
      });
    }
    return result;
  };
  _proto.getCarouselListMain = function getCarouselListMain(children) {
    var _this5 = this;
    var result = [];
    if (children && children.length) {
      children.forEach(function (item) {
        var _item$children5;
        if (item.componentName === ComponentName.CarouselBox) {
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || 'error_key',
            groupList: _this5.getVideoGroupList(item.props.stepsVideo)
          });
        }
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot5;
            slotData = isArray((_item$props$loopSlot5 = item.props.loopSlot) === null || _item$props$loopSlot5 === void 0 ? void 0 : _item$props$loopSlot5.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS5;
            slotData = isArray((_item$props$carouselS5 = item.props.carouselSlot) === null || _item$props$carouselS5 === void 0 ? void 0 : _item$props$carouselS5.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this5.getCarouselListMain(slotDataChildren));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items5;
          var list = [];
          if ((_item$props$items5 = item.props.items) !== null && _item$props$items5 !== void 0 && _item$props$items5.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children5, _itemOne$children5$va;
              list = list.concat(((_itemOne$children5 = itemOne.children) === null || _itemOne$children5 === void 0 ? void 0 : (_itemOne$children5$va = _itemOne$children5.value) === null || _itemOne$children5$va === void 0 ? void 0 : _itemOne$children5$va.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this5.getCarouselListMain(list));
          }
        }
        if ((_item$children5 = item.children) !== null && _item$children5 !== void 0 && _item$children5.length) {
          result = result.concat(_this5.getCarouselListMain(item.children));
        }
      });
    }
    return result;
  };
  _proto.getStorageDataRelationMain = function getStorageDataRelationMain(children) {
    var _this6 = this;
    var result = [];
    if (children !== null && children !== void 0 && children.length) {
      children.forEach(function (item) {
        var _item$children6;
        result = result.concat(_this6.getStorageKeyByPropsFlowEventConfig(item.props.flowEventConfig));
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot6;
            slotData = isArray((_item$props$loopSlot6 = item.props.loopSlot) === null || _item$props$loopSlot6 === void 0 ? void 0 : _item$props$loopSlot6.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS6;
            slotData = isArray((_item$props$carouselS6 = item.props.carouselSlot) === null || _item$props$carouselS6 === void 0 ? void 0 : _item$props$carouselS6.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this6.getStorageDataRelationMain(slotDataChildren));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items6;
          var list = [];
          if ((_item$props$items6 = item.props.items) !== null && _item$props$items6 !== void 0 && _item$props$items6.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children6, _itemOne$children6$va;
              list = list.concat(((_itemOne$children6 = itemOne.children) === null || _itemOne$children6 === void 0 ? void 0 : (_itemOne$children6$va = _itemOne$children6.value) === null || _itemOne$children6$va === void 0 ? void 0 : _itemOne$children6$va.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this6.getStorageDataRelationMain(list));
          }
        }
        if ((_item$children6 = item.children) !== null && _item$children6 !== void 0 && _item$children6.length) {
          result = result.concat(_this6.getStorageDataRelationMain(item.children));
        }
      });
    }
    return result;
  };
  _proto.getFlowEventOptionsBySchemaMain = function getFlowEventOptionsBySchemaMain(children, componentKey) {
    var _this7 = this;
    var result = [];
    if (children !== null && children !== void 0 && children.length) {
      children.forEach(function (item) {
        var _item$children7;
        if (item.componentName === ComponentName.Button && item.props.componentKey !== componentKey && item.props.flowEventConfig && isEffectiveEventFlow(item.props.flowEventConfig)) {
          result.push({
            label: item.props.componentName,
            value: item.props.componentKey
          });
        }
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var slotData = [];
          if (item.componentName === ComponentName.LoopBox) {
            var _item$props$loopSlot7;
            slotData = isArray((_item$props$loopSlot7 = item.props.loopSlot) === null || _item$props$loopSlot7 === void 0 ? void 0 : _item$props$loopSlot7.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
          } else {
            var _item$props$carouselS7;
            slotData = isArray((_item$props$carouselS7 = item.props.carouselSlot) === null || _item$props$carouselS7 === void 0 ? void 0 : _item$props$carouselS7.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
          }
          var slotDataChildren = [];
          if (slotData.length) {
            slotData.forEach(function (item) {
              if (item.children) {
                slotDataChildren = slotDataChildren.concat(item.children);
              }
            });
          }
          if (slotDataChildren.length) {
            result = result.concat(_this7.getFlowEventOptionsBySchemaMain(slotDataChildren, componentKey));
          }
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items7;
          var list = [];
          if ((_item$props$items7 = item.props.items) !== null && _item$props$items7 !== void 0 && _item$props$items7.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children7, _itemOne$children7$va;
              list = list.concat(((_itemOne$children7 = itemOne.children) === null || _itemOne$children7 === void 0 ? void 0 : (_itemOne$children7$va = _itemOne$children7.value) === null || _itemOne$children7$va === void 0 ? void 0 : _itemOne$children7$va.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this7.getFlowEventOptionsBySchemaMain(list, componentKey));
          }
        }
        if ((_item$children7 = item.children) !== null && _item$children7 !== void 0 && _item$children7.length) {
          result = result.concat(_this7.getFlowEventOptionsBySchemaMain(item.children, componentKey));
        }
      });
    }
    return result;
  };
  _proto.getFlowEventConfigByGidAndKeyMain = function getFlowEventConfigByGidAndKeyMain(children, key) {
    var _this8 = this;
    var result;
    if (children && children.length) {
      var _loop = function _loop() {
          var _item$children8;
          var item = children[i];
          if (item.componentName === ComponentName.Button && item.props.componentKey === key) {
            result = item.props.flowEventConfig;
            return 0; // break
          }
          if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
            var slotData = [];
            if (item.componentName === ComponentName.LoopBox) {
              var _item$props$loopSlot8;
              slotData = isArray((_item$props$loopSlot8 = item.props.loopSlot) === null || _item$props$loopSlot8 === void 0 ? void 0 : _item$props$loopSlot8.value) ? item.props.loopSlot.value : [item.props.loopSlot.value];
            } else {
              var _item$props$carouselS8;
              slotData = isArray((_item$props$carouselS8 = item.props.carouselSlot) === null || _item$props$carouselS8 === void 0 ? void 0 : _item$props$carouselS8.value) ? item.props.carouselSlot.value : [item.props.carouselSlot.value];
            }
            var slotDataChildren = [];
            if (slotData.length) {
              slotData.forEach(function (item) {
                if (item.children) {
                  slotDataChildren = slotDataChildren.concat(item.children);
                }
              });
            }
            if (slotDataChildren.length) {
              var res = _this8.getFlowEventConfigByGidAndKeyMain(slotDataChildren, key);
              if (res) {
                result = res;
                return 0; // break
              }
            }
          }
          if (item.componentName === ComponentName.Tabs) {
            var _item$props$items8;
            var list = [];
            if ((_item$props$items8 = item.props.items) !== null && _item$props$items8 !== void 0 && _item$props$items8.length) {
              item.props.items.forEach(function (itemOne) {
                var _itemOne$children8, _itemOne$children8$va;
                list = list.concat(((_itemOne$children8 = itemOne.children) === null || _itemOne$children8 === void 0 ? void 0 : (_itemOne$children8$va = _itemOne$children8.value) === null || _itemOne$children8$va === void 0 ? void 0 : _itemOne$children8$va.children) || []);
              });
            }
            if (list.length) {
              var _res = _this8.getFlowEventConfigByGidAndKeyMain(list, key);
              if (_res) {
                result = _res;
                return 0; // break
              }
            }
          }
          if ((_item$children8 = item.children) !== null && _item$children8 !== void 0 && _item$children8.length) {
            var _res2 = _this8.getFlowEventConfigByGidAndKeyMain(item.children, key);
            if (_res2) {
              result = _res2;
              return 0; // break
            }
          }
        },
        _ret;
      for (var i = 0; i < children.length; i++) {
        _ret = _loop();
        if (_ret === 0) break;
      }
    }
    return result;
  }

  /**
   * 从所有的事件流里面获取关于配置存储的key配置
   * @param flowEventConfig
   * @returns
   */;
  _proto.getStorageKeyByPropsFlowEventConfig = function getStorageKeyByPropsFlowEventConfig(flowNode) {
    var result = [];
    if (flowNode && isEffectiveEventFlow(flowNode)) {
      var flowEventConfig = new FlowEventService();
      var listData = flowEventConfig.getSaveDataBehaviorByAction(flowNode);
      if (listData.length) {
        listData.forEach(function (item) {
          var obj = {
            label: '',
            key: '',
            type: TreeType.storageDataItem
          };
          var key;
          if (item.type === StorageDataBType.Local) {
            // 由于编辑态不具备直接获取数据，并且前期key暂时都是固定值，可以这样获取
            key = item.localConfig.key.data;
          } else if (item.type === StorageDataBType.OnLine) {
            key = item.onLineConfig.key.data;
          }
          if (key) {
            obj.key = key;
            obj.label = key + "_flow";
            result.push(obj);
          }
        });
      }
    }
    return result;
  };
  _proto.getVideoGroupList = function getVideoGroupList(videoList) {
    var result = [];
    if (videoList !== null && videoList !== void 0 && videoList.length) {
      videoList.forEach(function (item) {
        result.push({
          label: item.groupName,
          value: item.groupId
        });
      });
    }
    return result;
  };
  _proto.getPropsKeyInSchema = function getPropsKeyInSchema(children, propsKey, value, id) {
    var _this9 = this;
    var result = false;
    if (children && children.length) {
      var _loop2 = function _loop2() {
          var _item$children9;
          var item = children[i];
          // 存在循环嵌套循环
          if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
            var _item$props$loopSlot9, _item$props$loopSlot10, _item$props$loopSlot11, _item$props$carouselS9, _item$props$carouselS10, _item$props$carouselS11;
            if (item.id !== id && item.props[propsKey] === value) {
              result = true;
              return 0; // break
            }
            if (item.componentName === ComponentName.LoopBox && (_item$props$loopSlot9 = item.props.loopSlot) !== null && _item$props$loopSlot9 !== void 0 && (_item$props$loopSlot10 = _item$props$loopSlot9.value) !== null && _item$props$loopSlot10 !== void 0 && (_item$props$loopSlot11 = _item$props$loopSlot10.children) !== null && _item$props$loopSlot11 !== void 0 && _item$props$loopSlot11.length) {
              result = _this9.getPropsKeyInSchema(item.props.loopSlot.value.children, propsKey, value, id);
            } else if (item.componentName === ComponentName.CarouselBox && (_item$props$carouselS9 = item.props.carouselSlot) !== null && _item$props$carouselS9 !== void 0 && (_item$props$carouselS10 = _item$props$carouselS9.value) !== null && _item$props$carouselS10 !== void 0 && (_item$props$carouselS11 = _item$props$carouselS10.children) !== null && _item$props$carouselS11 !== void 0 && _item$props$carouselS11.length) {
              result = _this9.getPropsKeyInSchema(item.props.carouselSlot.value.children, propsKey, value, id);
            }
            if (result) {
              return 0; // break
            }
          }
          // tab的情况下需要特殊处理
          if (item.componentName === ComponentName.Tabs) {
            var _item$props$items9;
            var list = [];
            if ((_item$props$items9 = item.props.items) !== null && _item$props$items9 !== void 0 && _item$props$items9.length) {
              item.props.items.forEach(function (itemOne) {
                var _itemOne$children9, _itemOne$children9$va;
                list = list.concat(((_itemOne$children9 = itemOne.children) === null || _itemOne$children9 === void 0 ? void 0 : (_itemOne$children9$va = _itemOne$children9.value) === null || _itemOne$children9$va === void 0 ? void 0 : _itemOne$children9$va.children) || []);
              });
            }
            if (list.length) {
              result = _this9.getPropsKeyInSchema(list, propsKey, value, id);
              if (result) {
                return 0; // break
              }
            }
          }
          if ((_item$children9 = item.children) !== null && _item$children9 !== void 0 && _item$children9.length) {
            result = _this9.getPropsKeyInSchema(item.children, propsKey, value, id);
            if (result) {
              return 0; // break
            }
          }
        },
        _ret2;
      for (var i = 0; i < children.length; i++) {
        _ret2 = _loop2();
        if (_ret2 === 0) break;
      }
    }
    return result;
  }

  /**
   * 由于所有的弹框只会在第一岑级别，故不需要递归查找
   * @param children
   */;
  _proto.getModalBySchemaChildren = function getModalBySchemaChildren(children) {
    var _keyObj,
      _this10 = this;
    var componentNameMap = {};
    var modalList = [ComponentName.Modal, ComponentName.Drawer, ComponentName.ModalDefault];
    children.forEach(function (item) {
      if (modalList.includes(item.componentName)) {
        if (componentNameMap[item.componentName]) {
          componentNameMap[item.componentName].push(item);
        } else {
          componentNameMap[item.componentName] = [item];
        }
      }
    });
    var result = [];
    var keyObj = (_keyObj = {}, _keyObj[ComponentName.Modal] = t('setter.Modal'), _keyObj[ComponentName.Drawer] = t('setter.Drawer'), _keyObj[ComponentName.ModalDefault] = t('setter.ModalDefault'), _keyObj);
    Object.keys(componentNameMap).forEach(function (key) {
      var _componentNameMap$key;
      var obj = {
        value: ComponentName.Modal + "_" + _this10.getParentKeyByChildren(componentNameMap[key]),
        label: keyObj[key] || '未定义',
        componentName: key,
        children: _this10.getModalChildren(componentNameMap[key])
      };
      if ((_componentNameMap$key = componentNameMap[key].props) !== null && _componentNameMap$key !== void 0 && _componentNameMap$key.apiParams) {
        obj.apiParams = componentNameMap[key].props.apiParams;
      }
      result.push(obj);
    });
    return result;
  }

  /**
   * 得到所有可以被刷新的key和value
   * 目前暂时只针对
   * 循环组件
   * 配置了事件流的Col
   * @param children
   */;
  _proto.getRefreshBySchemaChildren = function getRefreshBySchemaChildren(children) {
    var _this11 = this;
    var result = [];
    if (children && children.length) {
      children.forEach(function (item) {
        var _item$children10;
        // 存在循环嵌套循环
        if (item.componentName === ComponentName.LoopBox || item.componentName === ComponentName.CarouselBox) {
          var _item$props$loopSlot12, _item$props$loopSlot13, _item$props$carouselS12, _item$props$carouselS13;
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || uuid()
          });
          if (item.componentName === ComponentName.LoopBox && (_item$props$loopSlot12 = item.props.loopSlot) !== null && _item$props$loopSlot12 !== void 0 && (_item$props$loopSlot13 = _item$props$loopSlot12.value) !== null && _item$props$loopSlot13 !== void 0 && _item$props$loopSlot13.length) {
            result = result.concat(_this11.getRefreshBySchemaChildren(item.props.loopSlot.value));
          } else if (item.componentName === ComponentName.CarouselBox && (_item$props$carouselS12 = item.props.carouselSlot) !== null && _item$props$carouselS12 !== void 0 && (_item$props$carouselS13 = _item$props$carouselS12.value) !== null && _item$props$carouselS13 !== void 0 && _item$props$carouselS13.length) {
            result = result.concat(_this11.getRefreshBySchemaChildren(item.props.carouselSlot.value));
          }
        }
        if (item.componentName === ComponentName.Col && isEffectiveEventFlow(item.props.flowEventConfig)) {
          result.push({
            label: item.props.componentName || 'Title is blank',
            value: item.props.componentKey || 'error_key'
          });
        }

        // tab的情况下需要特殊处理
        if (item.componentName === ComponentName.Tabs) {
          var _item$props$items10;
          var list = [];
          if ((_item$props$items10 = item.props.items) !== null && _item$props$items10 !== void 0 && _item$props$items10.length) {
            item.props.items.forEach(function (itemOne) {
              var _itemOne$children10, _itemOne$children10$v;
              list = list.concat(((_itemOne$children10 = itemOne.children) === null || _itemOne$children10 === void 0 ? void 0 : (_itemOne$children10$v = _itemOne$children10.value) === null || _itemOne$children10$v === void 0 ? void 0 : _itemOne$children10$v.children) || []);
            });
          }
          if (list.length) {
            result = result.concat(_this11.getRefreshBySchemaChildren(list));
          }
        }
        if ((_item$children10 = item.children) !== null && _item$children10 !== void 0 && _item$children10.length) {
          result = result.concat(_this11.getRefreshBySchemaChildren(item.children));
        }
      });
    }
    return result;
  };
  _proto.getModalChildren = function getModalChildren(list) {
    return list.map(function (item) {
      var _item$props;
      var name = item.props.name ? item.props.name : '未命名';
      var newLabel = item.props.componentName ? item.props.componentName : item.props.title + "(" + name + ")";
      var obj = {
        value: name,
        label: newLabel,
        componentName: item.componentName,
        children: []
      };
      if ((_item$props = item.props) !== null && _item$props !== void 0 && _item$props.apiParams) {
        obj.apiParams = item.props.apiParams;
      }
      return obj;
    }) || [];
  };
  _proto.getParentKeyByChildren = function getParentKeyByChildren(list) {
    return list.map(function (item) {
      return item.id;
    }).join('');
  };
  _proto.getComponentsTreeBySchema = function getComponentsTreeBySchema() {
    var schema = project.exportSchema(IPublicEnumTransformStage.Save);
    return schema.componentsTree[0];
  };
  return SchemaService;
}();