// 视图
import { getLastDate, getLastDateTimeEnd, getLastDateTimeStart, getLastMonth, getLastMonthTimeEnd } from '@/utils/index';

export const views = {
}

// 日期选择器快捷选项
export const DatePickerOptions = {
  // 默认
  DEFAULT: {
    shortcuts: [{
      text: '最近一周',
      onClick(picker) {
        const end = getLastDate(0);
        const start = getLastDate(6);
        picker.$emit('pick', [start, end]);
      }
    }, {
      text: '最近一个月',
      onClick(picker) {
        const end = getLastDate(0);
        const start = getLastMonth(1);
        picker.$emit('pick', [start, end]);
      }
    }, {
      text: '最近三个月',
      onClick(picker) {
        const end = getLastDate(0);
        const start = getLastMonth(3);
        picker.$emit('pick', [start, end]);
      }
    }]
  },
  // 未来
  FUTURE: {
    shortcuts: [{
      text: '明天',
      onClick(picker) {
        const end = getLastDateTimeEnd(-1);
        const start = getLastDateTimeStart(-1);
        picker.$emit('pick', [start, end]);
      }
    },{
      text: '未来一周',
      onClick(picker) {
        const end = getLastDateTimeEnd(-6);
        const start = getLastDateTimeStart(0);
        picker.$emit('pick', [start, end]);
      }
    }, {
      text: '未来一个月',
      onClick(picker) {
        const end = getLastMonthTimeEnd(-1);
        const start = getLastDateTimeStart(0);
        picker.$emit('pick', [start, end]);
      }
    }, {
      text: '未来三个月',
      onClick(picker) {
        const end = getLastMonthTimeEnd(-3);
        const start = getLastDateTimeStart(0);
        picker.$emit('pick', [start, end]);
      }
    }]
  },
  // 禁用未来
  DISABLE_FUTURE: {
    disabledDate(date) {
      return parseInt(date.getTime() / 86400000) > parseInt(Date.now() / 86400000) - 1;
    }
  },
  // 禁用过去
  DISABLE_PAST: {
    disabledDate(date) {
      return parseInt(date.getTime() / 86400000) < parseInt(Date.now() / 86400000) - 1;
    }
  }
}

// 进度颜色
export const ProgressColors = [
  {color: '#5cb87a', percentage: 90},
  {color: '#f3ab40', percentage: 60},
  {color: '#f56c6c', percentage: 30},
]

// 进度条格式化
export function ProgressFormat(val) {
  if (val == null) {
    return '0%';
  }
  return val.toFixed(0) + '%';
}

// 文件类型
export const FileType = {
  // 图片
  IMAGE: ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'ico'],
  // 办公
  OFFICE: ['doc', 'docx', 'xls', 'xlsx', 'pdf', 'ppt', 'pptx'],
  // 音频
  AUDIO: ['mp3', 'wav', 'm4a', 'ogg', 'flac', 'aac'],
  // 视频
  VIDEO: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mpeg', 'mpg', 'm4v', 'webm', 'mkv'],
  // 压缩文件
  ZIP: ['zip', 'rar', '7z'],
  // 其他
  OTHER: ['exe'],
  // 全部
  all() {
    return [...this.IMAGE, ...this.OFFICE, ...this.AUDIO, ...this.VIDEO, ...this.OTHER, ...this.ZIP];
  }
}
