import dayjs from 'dayjs'

export const formatData = (times, keys, format = 'YYYY-MM-DD') => {
  const data = {}
  if (times && times.length) {
    for (let i = 0; i < keys.length; i++) {
      data[keys[i]] = dayjs(times[i]).format(format)
    }
  }
  return data
}

export const getNowDateAndMonday=(time)=> {
  let timestamp = new Date(time.replace(/-/g, "/")).getTime();
  let serverDate = new Date(time);
  if (serverDate.getDay() == 0) {
    timestamp -= 7 * 24 * 60 * 60 * 1000;
  }
  let mondayTime =
    timestamp - (serverDate.getDay() - 1) * 24 * 60 * 60 * 1000;

  let mondayData = new Date(mondayTime);
  //年
  let mondayY = mondayData.getFullYear();
  //月
  let mondayM =
    mondayData.getMonth() + 1 < 10
      ? "0" + (mondayData.getMonth() + 1)
      : mondayData.getMonth() + 1;
  //日
  let mondayD =
    mondayData.getDate() < 10
      ? "0" + mondayData.getDate()
      : mondayData.getDate();

  let str = mondayY + "-" + mondayM + "-" + mondayD;
  return str;
}
export const getNowDateAndSunday=(time) =>{
  let timestamp = new Date(time.replace(/-/g, "/")).getTime();
  let serverDate = new Date(time);

  let num = 7 - serverDate.getDay();
  if (num == 7) {
    num = 0;
  }
  let sundayTiem = timestamp + num * 24 * 60 * 60 * 1000;
  let SundayData = new Date(sundayTiem);
  //年
  let tomorrowY = SundayData.getFullYear(); //月
  let tomorrowM =
    SundayData.getMonth() + 1 < 10
      ? "0" + (SundayData.getMonth() + 1)
      : SundayData.getMonth() + 1;
  //日
  let tomorrowD =
    SundayData.getDate() < 10
      ? "0" + SundayData.getDate()
      : SundayData.getDate();
  let str = tomorrowY + "-" + tomorrowM + "-" + tomorrowD;
  return str;
}

export const getCourseType=(type)=>{
  let arr = []
  switch (type) {
    case "NORMAL": {
      arr = [
        { value: "SINGLE", label: "声部课" },
        { value: "TRAINING_SINGLE", label: "集训声部课" },
        { value: "COMPREHENSIVE", label: "综合课" },
        { value: "CLASSROOM", label: "课堂课" },
      ];
      break;
    }
    case "MIX": {
      arr = [
        { value: "MIX", label: "合奏课" },
        { value: "TRAINING_MIX", label: "集训合奏课" },
        { value: "COMPREHENSIVE", label: "综合课" },
        { value: "CLASSROOM", label: "课堂课" },
      ];
      break;
    }
    case "HIGH": {
      arr = [{ value: "HIGH", label: "基础技能课" }];
      break;
    }
    case "HIGH_ONLINE": {
      arr = [
        { value: "HIGH_ONLINE", label: "线上基础技能课" },
      ];
      break;
    }
    case "MUSIC_NETWORK": {
      arr = [
        { value: "MUSIC_NETWORK", label: "乐团网管课" },
      ];
      break;
    }
    case "SNAP": {
      arr = [
        { value: "SINGLE", label: "声部课" },
        { value: "MIX", label: "合奏课" },
        { value: "TRAINING_SINGLE", label: "集训声部课" },
        { value: "TRAINING_MIX", label: "集训合奏课" },
        { value: "HIGH", label: "基础技能课" },
        { value: "COMPREHENSIVE", label: "综合课" },
        { value: "CLASSROOM", label: "课堂课" },
      ];
    }
  }
  return arr
}
