
import { SCHEDULE_TYPE_MAP, SPECIAL_TEAM_STATE_MAP } from '../config';

export function parseTreeRoundList(treeRoundList: Array<any> = []) {
  treeRoundList.forEach((item) => {
    item?.node_list?.forEach((node: any) => {
      const schScore = node.sch_score || {};
      const schDanTao = node.sch_dantao || {};
      const { teama_id: teamAId, teamb_id: teamBId } = schScore;
      const { both_team_set: bothTeamSet = 0  } = schDanTao;

      if (!teamAId || !teamBId) {
        if (bothTeamSet < 3) {
          node.state = SPECIAL_TEAM_STATE_MAP.DAI_DING.state;
          node.specState = SPECIAL_TEAM_STATE_MAP.DAI_DING.specState;
        } else {
          node.state = SPECIAL_TEAM_STATE_MAP.LUN_KONG.state;
          node.specState = SPECIAL_TEAM_STATE_MAP.LUN_KONG.specState;
        }
      }
    });
  });
  return treeRoundList;
}


// 处理轮次
export function handleRoundList(resp: any) {
  const {
    curScheType,
    tree_round_list: treeRoundList = [],
  } = resp;
  if ((curScheType === SCHEDULE_TYPE_MAP.DOUBLE_FAIL || curScheType === SCHEDULE_TYPE_MAP.KNOCK_OUT)
    && treeRoundList.length
  ) {
    const res = treeRoundList.map((item: any) => {
      const roundInfo = item.round_info || {};
      return {
        ...roundInfo,
        rawRoundName: roundInfo.round_name,
      };
    });
    return res;
  }
  const roundList = (resp.round_list || []).map((item: any, index: number) => ({
    uniqueKey: `${index}-roundItem`,
    ...item,
  }));
  return roundList;
}
