/* eslint-disable no-nested-ternary */
import { CUSTOM_PREVIEW_STATUS_MAP } from '../config';


export function judgePreview(resp: any) {
  const hasCustomSche = judgeCustomShe(resp);
  if (!resp.is_admin) return CUSTOM_PREVIEW_STATUS_MAP.PREVIEW;

  return resp.is_preview == 1
    ? hasCustomSche
      ? CUSTOM_PREVIEW_STATUS_MAP.PREVIEW_CUSTOM
      : CUSTOM_PREVIEW_STATUS_MAP.PREVIEW
    : 0;
}


function judgeCustomShe(resp: any = {}) {
  const NULL_TEAM_ID_LIST = ['', '0', undefined, 'PREVIEW', 'PREVIEW_EMPTY'];
  const res = (resp.tree_round_list || [])
    .find((nodeInfo: any) => (nodeInfo?.node_list || [])
      .find((node: any) => (!NULL_TEAM_ID_LIST.includes(node?.sch_score?.teama_id)
      || !NULL_TEAM_ID_LIST.includes(node?.sch_score?.teamb_id))));
  return !!res;
}
