import { CommonStore } from '@/stores/common';

export enum NODE_TYPE {
  /** 根节点（真正的根节点）,不存在于后端数据库 */
  ROOT = 'root',
  /** 项目 */
  PROJECT = 'project',
  /** 阶段 */
  PHASE = 'phase',
  /** 分类，不是某一个具体的nodeType，指用户数据字典配置的所有的 nodeType 的总称, 不存在于后端数据库 */
  CATEGORY = 'category',
  /** 任务 */
  TASK = 'task',
  /** 指标 */
  PERFORMANCE = 'performance',
  /** 混合类型，不是某一个具体的nodeType，合并多个 nodeType 的属性到一个 node 上时使用 */
  MIXED = 'mixed',
  /** 算例 */
  RUN = 'run',
  /** 工位 */
  WORKSPACE = 'workspace',
  /** 机台 */
  MACHINE = 'machine',
}
export enum LEVEL_TYPE {
  /** 非任务和指标 */
  NODE = 'node',
  /** 任务 */
  TASK = 'task',
  /** 指标 */
  PERFORMANCE = 'performance',
}
const commonStore = CommonStore();

export const UNDEFINED_TAG = 'tag10';

let noCategoryList = false;
let categoryList: any = [];

/** 所有的tag名称,及tag排列顺序 */
export const tagSortList = ['tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6', 'tag7', 'tag8', 'tag9', 'tag10'];

export const getTagKeyMap = () => {
  if (categoryList.length === 0 && !noCategoryList) {
    console.log('categoryListdata', commonStore.getDictData('TAG_TYPE_MAP_LIST'));
    categoryList = (commonStore.getDictData('TAG_TYPE_MAP_LIST')).A;
    console.log('categoryListdata', categoryList);
    // categoryList = data.A;
    if (categoryList.length === 0) {
      noCategoryList = true;
    }
  }
  // console.log('categoryList', categoryList);
  const map: any = new Map();
  categoryList.forEach((item: { value: string; label: string; }) => {
    map.set(item.value, item.label);
  });
  return map;
};

export interface TreeNode<T = any> {
  id?: number;
  uuid?: string;
  nodeType: string;
  nodeName?: string;
  children?: TreeNode<T>[]
  [key: string]: any
}

export interface DictItem {
  label: string;
  value: string | number
}

export const nodeTypeRelations: Record<string, string[]> = {
  [NODE_TYPE.ROOT]: [NODE_TYPE.CATEGORY],
  [NODE_TYPE.CATEGORY]: [NODE_TYPE.CATEGORY, NODE_TYPE.TASK],
  [NODE_TYPE.TASK]: [NODE_TYPE.PERFORMANCE],
  [NODE_TYPE.PERFORMANCE]: [],
};

export const poolNodePublicProps = ['id', 'pId', 'uuid', 'pUuid', 'nodeId', 'nodeName', 'englishName', 'nodeCode', 'nodeType', 'levelType', 'description'];
export const poolNodePropPickMap = {
  [NODE_TYPE.CATEGORY]: [...poolNodePublicProps],
  [NODE_TYPE.TASK]: [...poolNodePublicProps, 'days', 'flowTemplate', 'standard', 'analyseTarget', 'confidence', 'analyseSoftware', 'difficult', 'imageFileId', 'bCapacity', 'department', 'section', 'group'],
  [NODE_TYPE.PERFORMANCE]: [...poolNodePublicProps, 'taskId', 'taskName', 'unit', 'lowValue', 'highValue', 'performanceType', 'method'],
};
export const poolNodeExtraPropPickMap = {
  [NODE_TYPE.CATEGORY]: [],
  [NODE_TYPE.TASK]: [],
  [NODE_TYPE.PERFORMANCE]: [],
};

export const nodeTypeList: DictItem[] = [
  { label: '分类', value: NODE_TYPE.CATEGORY },
  { label: '工况', value: NODE_TYPE.TASK },
  { label: '指标', value: NODE_TYPE.PERFORMANCE },
];

