import { ProjectStatus } from '@/utils/enums';

export const ProjectUtils = {
  // 获取项目截止时间展示
  getProjectExpireTime(row) {
    switch (row.status) {
      case ProjectStatus.WAIT_START:
        return {
          label: '截止日期',
          value: row.expireTime
        };
      case ProjectStatus.IN_PROGRESS:
      case ProjectStatus.DEVELOPMENT_OVERDUE:
        return {
          label: '开发预计',
          value: row.expectedCompleteTime
        };
      case ProjectStatus.MAINTENANCE:
      case ProjectStatus.MAINTENANCE_OVERDUE:
        return {
          label: '运维结束',
          value: row.maintenanceEndDate
        };
      default:
        return {
          label: '截止日期',
          value: row.expireTime
        };
    }
  },
  // 判断项目是否逾期
  isOverdue(row) {
    const { value } = this.getProjectExpireTime(row);
    return new Date(value) < new Date();
  },
  // 判断项目是否即将到期
  isExpireSoon(row) {
    const { value } = this.getProjectExpireTime(row);
    const expireTime = new Date(value);
    const now = new Date();
    const days = (expireTime - now) / 24 / 60 / 60 / 1000;
    return days <= 7 && days > 0;
  }
}
