import { Random } from 'mockjs'
import {  post } from '@/api/http'
//----------
// 使用 Mock 測試

// ES Modules syntax
import fetch from 'node-fetch';
global.fetch = fetch;
var Mock = require('mockjs')

var mockdata = [];
var mocktime = [];
var mockStudydata = [];
var mockStudydata2 = [];
var mockQASheet = [];
var courseList = [];
var students = [];
for (var i = 1; i <= 30; i++) {
    var data = Mock.mock({

        "string|1-5": "★",//隨意產生1-10個星星
        'teacher': Random.name(),
        'title': Random.ctitle(),
        'date': Random.date('yyyy.MM.dd'),
        'deadline': Random.date('yyyy.MM.dd'),
        'time': Random.time('HH:00'),
        "isDone|1-2": true,
        'desc': Random.cparagraph(1, 7),
        'img1|1-10': 'https://source.unsplash.com/random/300x200/?water',
        'img2|1-10': 'https://source.unsplash.com/random/300x200/?moutain',
        'img3|1-10': 'https://source.unsplash.com/random/?moutain',
        'subPage': true,
        'eventType|1': ['logo-octocat', 'md-game-controller-b', 'md-leaf', 'md-car'],
        'eventId': Random.id(),
        'className|1': ['國文', '數學'],
        'isClosed|1-2': true,



    });
    for (let p = 1; p <= 38; p++) {
        let studentsData = Mock.mock({
            name: Random.cname(),
            group: Random.integer(1, 5),
            "isUploadHomework|1": true, //一個是否有交作業的參數，同學互評使用
            "isGivenComment|1": true, //一個是否有被給評的參數，同學互評使用
        });
        students.push(studentsData); //學生名單資料
    }
    var courseItem = Mock.mock({
        "courseType|1": ["表定", "臨時"],
        courseName: Random.ctitle(12, 20),
        courseID: Random.id(), //課程代碼
        courseAddDate: Random.date('2020.01.dd'), //加入課程的日期
        "courseSubject|1": ["國文", "英文", "數學"],
        //tab1 基本資料
        attendTime: "每星期三 " + Random.time("HH:00"), //上課時間
        classroom: "classroom A" + Random.integer(60, 70), //上課地點
        teacher: Random.cname(), //授課教師
        assistantTeachers: [Random.cname(), Random.cname(), Random.cname()], //授課教師

        //tab2 課程概述
        courseDesc: Random.cparagraph(17, 27), //課程描述

        //tab3 學生名單
        students: students,
    });
    courseList.push(courseItem);
    var data2 = Mock.mock({

        "string|1-5": "★",//隨意產生1-10個星星
        'title': "編序式自學：" + Random.ctitle(),
        'date': Random.date('yyyy.MM.dd'),
        "isDone|1-2": true,
        'desc': Random.cparagraph(1, 7),
        'img1|1-10': 'https://source.unsplash.com/random/300x200/?water',
        'img2|1-10': 'https://source.unsplash.com/random/300x200/?moutain',
        'subPage': true,
        'eventType|1': ['md-filing'],
        'className|1': ['國文', '數學'],



    });
    var data3 = Mock.mock({

        "string|1-5": "★",//隨意產生1-10個星星
        'title': "其他教材：" + Random.ctitle(),
        'date': Random.date('yyyy.MM.dd'),
        "isDone|1-2": true,
        'desc': Random.paragraph(1, 7),
        'subPage': true,
        'eventType|1': ['md-beer', 'md-paper-plane', 'md-paper'],
        'className|1': ['國文', '數學'],
        'doctitle': Random.ctitle()


    });
    var data4 = Mock.mock({

        'rightAns|1': ['A', 'B', 'C', 'D'],
        'MyAns|1': ['A', 'B', 'C', 'D', ''],
        'ansDesc': localStorage.getItem('lang')=='tw'?[Random.cparagraph(1, 3), Random.cparagraph(1, 3), Random.cparagraph(1, 3), Random.cparagraph(1, 3)]:[Random.paragraph(1, 3), Random.paragraph(1, 3), Random.paragraph(1, 3), Random.paragraph(1, 3)],
        'qtype|1': ['單選', '多選'],
        'questionDesc': localStorage.getItem('lang')=='tw'?Random.cparagraph(1, 8):Random.paragraph(1, 8),
        'relatedQ1': localStorage.getItem('lang')=='tw'?Random.cparagraph(1, 8):Random.paragraph(1, 8),
        'relatedQ2': localStorage.getItem('lang')=='tw'?Random.cparagraph(1, 8):Random.paragraph(1, 8),
        "rightrate|1-100": 100,
        'img1|1-10': 'https://source.unsplash.com/random/300x200/?water',
        'img2|1-10': 'https://source.unsplash.com/random/300x200/?line',
        "haveImgAns|1-2": true,
        'AnsImgs|1-10':'https://source.unsplash.com/random/300x200/?green',
       
    });


    mockdata.push(data);
    mockStudydata.push(data2);
    mockStudydata2.push(data3);
    mockQASheet.push(data4);
}

for (var j = 1; j <= 7; j++) {
    var time = Mock.mock({
        "number|1-100": 100,

    });
    mocktime.push(time);

}



//物件按時間排序
mockdata = mockdata.sort(function (a, b) {
    return a.deadline < b.deadline ? 1 : -1;
});

mockStudydata = mockStudydata.sort(function (a, b) {
    return a.deadline < b.deadline ? 1 : -1;
});
mockStudydata2 = mockStudydata2.sort(function (a, b) {
    return a.deadline < b.deadline ? 1 : -1;
});

function finishPercent() {
    var count = 0;
    for (var i = 0; i < mockdata.length; i++) {
        if (mockdata[i].isDone == true) {
            count++;
        }
    }
    var Result = (count / mockdata.length) * 100
    return Result.toFixed(2);
}



var initialfinishResult = finishPercent();

//console.log(mockStudydata)

export default {
    mockdata,
    initialfinishResult,
    mocktime,
    mockStudydata,
    mockStudydata2,
    mockQASheet,
    courseList,
    //查询学生参与评量数据
    FindExamPaper: function (data) {
        return post('/common/exam/find-all-by-student', data)
    },
    //查询学生的评量数据
    FindStudentPaper: function (data) {
        return post('/common/exam/find-summary-by-student', data)
    },
    //保存学生评量数据
    SaveStuExamPaper: function (data) {
        return post('/common/exam/upsert-record', data)
    },
    //保存学生评量数据
    getStudentAnalysis: function (data) {
        return post('/analysis/studentAnalysis', data)
    },
    //查询评量Sas
    getStudentSas: function (data) {
        return post('/blob/sas-r', data)
    },
    //查询文件授权
    getFileSas: function (data) {
        return post('/blob/sas-url-r', data)
    },
    //查詢學生端活動信息
    getActivityInfo: function (data) {
        return post('/student/stu-activity',data)
    },
    //查詢學生端投票活动
    getVoteInfo: function (data) {
        return post('/common/vote/find-id',data)
    },
    //查詢學生端个人投票结果
    getVoteResult: function (data) {
        return post('/common/vote/decided',data)
    },
    //查詢活动投票结果
    getVoteRecord: function (data) {
        return post('/common/vote/record',data)
    },
    //提交投票结果数据
    sendVoteResult: function (data) {
        return post('/common/vote/decide',data)
    },
	//查詢學生端问卷活动
	getSurveyInfo: function (data) {
	    return post('/common/survey/find-id',data)
	},
	
	//查詢學生端问卷活动
	answerSurvey: function (data) {
	    return post('/common/survey/answer',data)
	},
	
	isAnswerd: function (data) {
	    return post('/common/survey/answered',data)
	},
}