import { cloneDeep } from 'lodash-es';
import { useDict } from './useDict';
import { getTagKeyMap } from './enum/node';
import { TASK_CALCULATE_STATUS, TASK_PROCESS_STATUS } from './enum/task';

export const disposeSimType = (demandType: string, simType: string) => {
  if (demandType && simType) {
    const dict: any = useDict(demandType);
    if (dict[demandType]) {
      if (dict[demandType].value.O[simType]) {
        return dict[demandType].value.O[simType];
      }
    }
  }
  return simType;
};

/**
 *
 * @param memberList
 * @returns 用户ids，逗号隔开的id字符串
 */
export const getMemberListIds = (memberList: any[]) => {
  const list = cloneDeep(memberList);
  if (Array.isArray(list)) {
    return list
      .map((item: any) => {
        return item.userId;
      })
      .join(',');
  }
  return '';
};

export const getTagMapList = () => {
  const tagMap = getTagKeyMap();
  const tagMapList: { key: string; value: string }[] = [];
  tagMap.forEach((value: string, key: string) => {
    tagMapList.push({
      key: key,
      value: value,
    });
  });
  return tagMapList;
};

export const getTaskExeStyleClass = (status: string) => {
  switch (status) {
    case TASK_PROCESS_STATUS.COMPLETED:
      return 'dot dot-success';
    case TASK_PROCESS_STATUS.IN_PROGRESS:
      return 'dot dot-in-precess';
    case TASK_PROCESS_STATUS.NO_STARTED:
      return 'dot dot-default';
    case TASK_PROCESS_STATUS.PAUSED:
      return 'dot dot-approving';
    default:
      return 'dot dot-default';
  }
};

export const getTaskAchieveStyleClass = (status: number) => {
  const statusString = String(status);
  switch (statusString) {
    case TASK_CALCULATE_STATUS.QUALIFIED:
      return 'dot dot-qualified';
    case TASK_CALCULATE_STATUS.UNQUALIFIED:
      return 'dot dot-unqualified';
    case TASK_CALCULATE_STATUS.NO_CALCULATE:
      return 'dot dot-no-calculate';
    default:
      return 'dot dot-no-calculate';
  }
};
