import dayjs from 'dayjs';

/**
 * 流程节点
 */
// 待交办
export const PROCESS_START = "01";
// 交办
export const PROCESS_ASSIGNED = "02";
// 办结
export const PROCESS_END = "03";
// 驳回申请
export const PROCESS_APPLY_REJECT = "0201";
// 延期申请
export const PROCESS_APPLY_DELAY = "0202";
// 单位审核
export const PROCESS_APPLY_VERIFY = "0203";
// 办结申请
export const PROCESS_APPLY_END = "0204";

/**
 * 审核结果
 */
// 未审核
export const APPLY_READY = "ready";
// 审核通过
export const APPLY_PASS = "pass";
// 审核驳回
export const APPLY_REJECT = "reject";


export function getIssueStatus (taIssue) {

  const isExpired = dayjs(taIssue.expireDate).format('YYYY-MM-DD') < dayjs().format('YYYY-MM-DD');

  if (taIssue.processStatus === APPLY_REJECT) {
    return {
      value: 4,
      label: '已打回',
    };
  } else if (taIssue.processNode === PROCESS_START) {

    if (isExpired) {
      return {
        value: 3,
        label: '已逾期',
      };
    }

    return {
      value: 0,
      label: '待交办',
    }
  } else if (taIssue.processNode === PROCESS_END) {
    if (dayjs(taIssue.expireDate).format('YYYY-MM-DD') < dayjs(taIssue.endDate).format('YYYY-MM-DD')) {
      return {
        value: 5,
        label: '逾期办结',
      };
    }

    return {
      value: 2,
      label: '已办结',
    };
  } else if (taIssue.processNode.indexOf(PROCESS_ASSIGNED) === 0) {
    if (taIssue.processStatus === APPLY_READY) {
      if (taIssue.processNode === PROCESS_APPLY_REJECT) {
        return {
          value: 1,
          label: '驳回申请',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_DELAY) {
        return {
          value: 1,
          label: '延期申请',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_VERIFY) {
        return {
          value: 1,
          label: '审核申请',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_END) {
        return {
          value: 1,
          label: '消单申请',
        };
      } else {
        // return {
        //   value: 1,
        //   label: '待处理',
        // };
      }
    } else if (taIssue.processStatus === APPLY_PASS) {
      if (taIssue.processNode === PROCESS_APPLY_REJECT) {
        return {
          value: 1,
          label: '驳回申请通过',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_DELAY) {
        return {
          value: 1,
          label: '延期申请通过',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_VERIFY) {
        return {
          value: 1,
          label: '审核申请通过',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_END) {
        return {
          value: 1,
          label: '消单申请通过',
        };
      }
    } else {
      if (taIssue.processNode === PROCESS_APPLY_REJECT) {
        return {
          value: 1,
          label: '驳回申请驳回',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_DELAY) {
        return {
          value: 1,
          label: '延期申请驳回',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_VERIFY) {
        return {
          value: 1,
          label: '审核申请驳回',
        };
      } else if (taIssue.processNode === PROCESS_APPLY_END) {
        return {
          value: 1,
          label: '消单申请驳回',
        };
      }
    }

    if (isExpired) {
      return {
        value: 3,
        label: '已逾期',
      };
    }

    return {
      value: 1,
      label: '已交办',
    };
  }

  return {};
}

