export const studentVideoList = [
  {
    seq: null,
    examName: "20220506",
    examActivityCode: "1",
    examId: "255274328714129408",
    examActivityId: "255274329125171200",
    examStudentId: "1522766012435914753",
    examRecordId: "259318134736424960",
    identity: "42011406159-12345678901234",
    roomCode: "001",
    roomName: "测试001",
    name: "李萌",
    courseName: "测试",
    courseCode: "A0002",
    paperDownload: 1,
    status: "已待考",
    statusCode: "FIRST_PREPARE",
    progress: 0.0,
    warningCount: 0,
    clientWebsocketStatus: "OFF_LINE",
    cameraMonitorStatusSource: null,
    screenMonitorStatusSource: null,
    mobileFirstMonitorStatusSource: null,
    mobileSecondMonitorStatusSource: null,
    clientCurrentIp: "192.168.10.136",
    breachStatus: 1,
    monitorLiveUrl: "oe_test_259318134736424960_client_camera",
    updateTime: 1652767129478,
    remainTime: "00:00:00",
    warningNew: 0,
    monitorVideoSource: "CLIENT_CAMERA",
    monitorRecord: null,
  },
  {
    seq: null,
    examName: "20220506",
    examActivityCode: "1",
    examId: "255274328714129408",
    examActivityId: "255274329125171200",
    examStudentId: "1522766012473663489",
    examRecordId: "259318142240034817",
    identity: "42011406194-12345678901234",
    roomCode: "001",
    roomName: "测试001",
    name: "徐晓",
    courseName: "测试",
    courseCode: "A0002",
    paperDownload: 1,
    status: "已待考",
    statusCode: "FIRST_PREPARE",
    progress: 0.0,
    warningCount: 0,
    clientWebsocketStatus: "OFF_LINE",
    cameraMonitorStatusSource: null,
    screenMonitorStatusSource: null,
    mobileFirstMonitorStatusSource: null,
    mobileSecondMonitorStatusSource: null,
    clientCurrentIp: "192.168.10.136",
    breachStatus: 1,
    monitorLiveUrl: "oe_test_259318142240034817_client_camera",
    updateTime: 1652767129158,
    remainTime: "00:00:00",
    warningNew: 0,
    monitorVideoSource: "CLIENT_CAMERA",
    monitorRecord: null,
  },
  {
    seq: null,
    examName: "20220506",
    examActivityCode: "1",
    examId: "255274328714129408",
    examActivityId: "255274329125171200",
    examStudentId: "1522766012318474241",
    examRecordId: "259318111927799808",
    identity: "42011406050-12345678901234",
    roomCode: "001",
    roomName: "测试001",
    name: "张国",
    courseName: "测试",
    courseCode: "A0002",
    paperDownload: 1,
    status: "已待考",
    statusCode: "FIRST_PREPARE",
    progress: 0.0,
    warningCount: 0,
    clientWebsocketStatus: "OFF_LINE",
    cameraMonitorStatusSource: null,
    screenMonitorStatusSource: null,
    mobileFirstMonitorStatusSource: null,
    mobileSecondMonitorStatusSource: null,
    clientCurrentIp: "192.168.10.136",
    breachStatus: 1,
    monitorLiveUrl: "oe_test_259318111927799808_client_camera",
    updateTime: 1652767119001,
    remainTime: "00:00:00",
    warningNew: 0,
    monitorVideoSource: "CLIENT_CAMERA",
    monitorRecord: null,
  },
  {
    seq: null,
    examName: "20220506",
    examActivityCode: "1",
    examId: "255274328714129408",
    examActivityId: "255274329125171200",
    examStudentId: "1522766012553355267",
    examRecordId: "259318157805096960",
    identity: "42011406269-12345678901234",
    roomCode: "001",
    roomName: "测试001",
    name: "严惩",
    courseName: "测试",
    courseCode: "A0002",
    paperDownload: 1,
    status: "已待考",
    statusCode: "FIRST_PREPARE",
    progress: 0.0,
    warningCount: 0,
    clientWebsocketStatus: "OFF_LINE",
    cameraMonitorStatusSource: null,
    screenMonitorStatusSource: null,
    mobileFirstMonitorStatusSource: null,
    mobileSecondMonitorStatusSource: null,
    clientCurrentIp: "192.168.10.136",
    breachStatus: 1,
    monitorLiveUrl: "oe_test_259318157805096960_client_camera",
    updateTime: 1652767140219,
    remainTime: "00:00:00",
    warningNew: 0,
    monitorVideoSource: "CLIENT_CAMERA",
    monitorRecord: null,
  },
  {
    seq: null,
    examName: "20220506",
    examActivityCode: "1",
    examId: "255274328714129408",
    examActivityId: "255274329125171201",
    examStudentId: "1522766012553355270",
    examRecordId: "259318157805096961",
    identity: "42011406269-12345678901234",
    roomCode: "001",
    roomName: "测试001",
    name: "周旋",
    courseName: "测试",
    courseCode: "A0002",
    paperDownload: 1,
    status: "已待考",
    statusCode: "FIRST_PREPARE",
    progress: 0.0,
    warningCount: 0,
    clientWebsocketStatus: "OFF_LINE",
    cameraMonitorStatusSource: null,
    screenMonitorStatusSource: null,
    mobileFirstMonitorStatusSource: null,
    mobileSecondMonitorStatusSource: null,
    clientCurrentIp: "192.168.10.136",
    breachStatus: 1,
    monitorLiveUrl: "oe_test_259318157805096961_client_camera",
    updateTime: 1652767140219,
    remainTime: "00:00:00",
    warningNew: 0,
    monitorVideoSource: "CLIENT_CAMERA",
    monitorRecord: null,
  },
];
export const getStudentVideoList = () => {
  const excludeInd = Math.floor(Math.random() * 5);
  return studentVideoList.filter((item, index) => index !== excludeInd);
};

const getRandomNum = (minNum, maxNum) => {
  return minNum + Math.floor(Math.random() * (maxNum - minNum));
};
const getSiteNum = (val, zeros = "00") => {
  return (zeros + val).substring(("" + val).length);
};
const getRandomListFromList = (dataList, randomCount) => {
  if (randomCount >= dataList.length) return dataList;
  if (!randomCount) return [];

  let nList = [...dataList];
  let randomList = [];
  for (let i = 0; i < randomCount; i++) {
    const ind = getRandomNum(0, nList.length);
    randomList[i] = nList.splice(ind, 1)[0];
  }
  return randomList;
};

export const summary = {
  onlineCount: 65432,
  waitingCount: 6532,
  examingCount: 1342,
  breachCount: 1112,
  warnCount: 4453,
  id: "1",
  name: "武汉大学",
  code: "whdx",
};

export const getSummary = () => {
  return Object.assign({}, summary, {
    onlineCount: getRandomNum(60000, 70000),
    waitingCount: getRandomNum(5000, 7000),
    examingCount: getRandomNum(1000, 2000),
    breachCount: getRandomNum(1000, 2000),
    warnCount: getRandomNum(2000, 4000),
  });
};

export const inviTypesList = [
  {
    type: "违规动作",
    warnCount: 320,
  },
  {
    type: "替考",
    warnCount: 98,
  },
  {
    type: "求助第三方",
    warnCount: 58,
  },
  {
    type: "采用照片",
    warnCount: 54,
  },
  {
    type: "虚拟摄像头",
    warnCount: 30,
  },
  {
    type: "切出考试窗口",
    warnCount: 17,
  },
  {
    type: "雷同卷",
    warnCount: 4,
  },
];

export const getTypesList = () => {
  return inviTypesList.map((item) => {
    return {
      type: item.type,
      warnCount: getRandomNum(5, 300),
    };
  });
};

let cacheTimeMap = {};
export const getTimeList = () => {
  let inviTimeList = [];
  let nowTime = new Date();
  let hour = nowTime.getHours();
  let minute = nowTime.getMinutes();
  for (let i = 0; i < 60; i++) {
    let m = minute - i;
    let h = m < 0 ? hour - 1 : hour;
    m = m < 0 ? 60 + m : m;
    h = h < 0 ? 24 + h : h;
    const hourMinute = `${getSiteNum(h)}:${getSiteNum(m)}`;
    let timeData = {
      hour: hourMinute,
      onlineCount: getRandomNum(100, 600),
      warnCount: getRandomNum(0, 90),
    };
    if (cacheTimeMap[hourMinute]) {
      timeData.onlineCount = cacheTimeMap[hourMinute].onlineCount;
      timeData.warnCount = cacheTimeMap[hourMinute].warnCount;
    } else {
      cacheTimeMap[timeData.hour] = timeData;
    }
    inviTimeList.push(timeData);
  }
  return inviTimeList.reverse();
};

export const inviAreaList = [
  {
    country: "中国",
    province: "河南",
    warnCount: 1147,
  },
  {
    country: "中国",
    province: "山西",
    warnCount: 498,
  },
  {
    country: "中国",
    province: "湖南",
    warnCount: 461,
  },
  {
    country: "中国",
    province: "湖北",
    warnCount: 349,
  },
  {
    country: "中国",
    province: "河北",
    warnCount: 332,
  },
  {
    country: "中国",
    province: "四川",
    warnCount: 332,
  },
  {
    country: "中国",
    province: "江苏",
    warnCount: 332,
  },
  {
    country: "中国",
    province: "广州",
    warnCount: 332,
  },
  {
    country: "中国",
    province: "上海",
    warnCount: 332,
  },
];
export const getAreaList = () => {
  const dataList = getRandomListFromList(inviAreaList, 8);
  return dataList.map((item) => {
    let nitem = { ...item };
    nitem.warnCount = getRandomNum(5, 300);
    return nitem;
  });
};

export const inviMapList = [
  {
    country: "中国",
    province: "湖北",
    onlineCount: 120,
    warnCount: 10,
  },
  {
    country: "中国",
    province: "河北",
    onlineCount: 145,
    warnCount: 11,
  },
  {
    country: "中国",
    province: "湖南",
    onlineCount: 123,
    warnCount: 8,
  },
  {
    country: "中国",
    province: "河南",
    onlineCount: 245,
    warnCount: 20,
  },
  {
    country: "中国",
    province: "四川",
    onlineCount: 89,
    warnCount: 5,
  },
  {
    country: "中国",
    province: "上海",
    onlineCount: 156,
    warnCount: 5,
  },
  {
    country: "中国",
    province: "广东",
    onlineCount: 156,
    warnCount: 5,
  },
  {
    country: "中国",
    province: "广西",
    onlineCount: 156,
    warnCount: 5,
  },
  {
    country: "中国",
    province: "浙江",
    onlineCount: 156,
    warnCount: 5,
  },
  {
    country: "中国",
    province: "江苏",
    onlineCount: 156,
    warnCount: 5,
  },
  {
    country: "中国",
    province: "云南",
    onlineCount: 156,
    warnCount: 5,
  },
];

export const getMapList = () => {
  const count = inviMapList.length - getRandomNum(0, 3);
  return getRandomListFromList(inviMapList, count);
};

export const inviWarnMsgList = [
  {
    examId: "1",
    examStudentId: "1",
    name: "丰玉",
    identity: "42000198710082825",
    info: "疑似违规动作",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "2",
    name: "司莎寒",
    identity: "42000198710082825",
    info: "疑似替考",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "3",
    name: "伦珊桂",
    identity: "42000198710082825",
    info: "疑似求助第三方",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "4",
    name: "牛山",
    identity: "42000198710082825",
    info: "疑似采用照片",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "5",
    name: "孙康启",
    identity: "42000198710082825",
    info: "疑似采用照片或虚拟电饭锅手动阀牢固树立",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "6",
    name: "牛天",
    identity: "42000198710082825",
    info: "疑似采用照片",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "7",
    name: "吴勇",
    identity: "42000198710082825",
    info: "疑似求助第三方",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "8",
    name: "孙家",
    identity: "42000198710082825",
    info: "疑似替考",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "9",
    name: "李涛",
    identity: "42000198710082825",
    info: "疑似求助第三方",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
  {
    examId: "1",
    examStudentId: "10",
    name: "徐辉",
    identity: "42000198710082825",
    info: "疑似替考",
    level: "预警等级",
    warningId: "1",
    remark: "1",
    examRecordId: "1",
    roomCode: "1",
    createTime: Date.now(),
    approveStatus: "已处理",
  },
];
export const getWarnMsgList = () => {
  return getRandomListFromList(inviWarnMsgList, 6);
};

// fetch
function fetchData(getData) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      try {
        const data = getData();
        resolve({ data: { data } });
      } catch (error) {
        reject(error);
      }
    }, 100);
  });
}

export function examInvigilationCount() {
  return fetchData(getSummary);
}
export function examInvigilationWarnDistribution() {
  return fetchData(getTypesList);
}
export function examInvigilationWarnTrend() {
  return fetchData(getTimeList);
}
export function examInvigilationVideoRandomList() {
  return fetchData(getStudentVideoList);
}
export function examInvigilationWarnMessage() {
  return fetchData(getWarnMsgList);
}
export function examinationMonitorMapList() {
  return fetchData(getMapList);
}
export function examinationMonitorAreaList() {
  return fetchData(getAreaList);
}
