import Vue from "vue";
import {
  TEMPLATE_CLASSIFY,
  TEMPLATE_TYPE,
  EXAM_TASK_STATUS,
  AUDITING_STATUS,
  AUDITING_RESULT,
  PRINT_PLAN_STATUS,
  PRINT_TASK_STATUS,
  DATA_TASK_STATUS,
  DATA_TASK_TYPE,
  DATA_TASK_RESULT,
  ORG_TYPE,
  CARD_SOURCE_TYPE,
  MARK_TASK_SYNC_STATUS,
  STMMS_SYNC_TYPE,
  SYNC_PRINT_STATUS,
  PRINT_PDF_TYPE,
  EXAM_TYPE,
  CARD_TYPE,
  PUSH_CARD_TYPE,
  CARD_CREATE_METHOD_TYPE,
  FLOW_APPROVE_OPERATION_TYPE,
  ANALYSIS_BATCH_STATUS,
  EXAM_NUMBER_STYLE,
  FLOW_TYPE,
  MARK_MODE_TYPE,
  STUDENT_STATUS,
  EVALUATION_MODE,
  COURSE_TYPE,
} from "../constants/enumerate";
import { formatDate } from "../plugins/utils";

const DEFAULT_FIELD = "--";

Vue.filter("defaultFieldFilter", function (val) {
  return val || val === 0 ? val : DEFAULT_FIELD;
});
Vue.filter("enableFilter", function (val) {
  return val ? "启用" : "禁用";
});
Vue.filter("templateClassifyFilter", function (val) {
  return TEMPLATE_CLASSIFY[val] || DEFAULT_FIELD;
});
Vue.filter("templateTypeFilter", function (val) {
  return TEMPLATE_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("orgsFilter", function (val) {
  return val.map((item) => item.name).join();
});
Vue.filter("rolesFilter", function (val) {
  return val.map((item) => item.name).join();
});
Vue.filter("coursesFilter", function (val) {
  return val.map((item) => `${item.name}(${item.code})`).join("，");
});
Vue.filter("examTaskStatusFilter", function (val) {
  return EXAM_TASK_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("auditStatusFilter", function (val) {
  return AUDITING_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("reviewStatusFilter", function (val) {
  return AUDITING_RESULT[val] || DEFAULT_FIELD;
});
Vue.filter("printPlanStatusFilter", function (val) {
  return PRINT_PLAN_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("printTaskStatusFilter", function (val) {
  return PRINT_TASK_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("dataTaskTypeFilter", function (val) {
  return DATA_TASK_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("dataTaskStatusFilter", function (val) {
  return DATA_TASK_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("dataTaskResultFilter", function (val) {
  return DATA_TASK_RESULT[val] || DEFAULT_FIELD;
});
Vue.filter("orgTypeFilter", function (val) {
  return ORG_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("cardSourceTypeFilter", function (val) {
  return CARD_SOURCE_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("timestampFilter", function (val) {
  return val
    ? formatDate("YYYY-MM-DD HH:mm:ss", new Date(val * 1))
    : DEFAULT_FIELD;
});
Vue.filter("flowTaskNameFilter", function (val) {
  return val ? val.replace(/\(.+?\)/g, "") : DEFAULT_FIELD;
});
Vue.filter("markTaskSyncStatusFilter", function (val) {
  return MARK_TASK_SYNC_STATUS[val] || "失败";
});
Vue.filter("stmmsSyncTypeFilter", function (val) {
  return STMMS_SYNC_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("syncPrintStatusFilter", function (val) {
  return SYNC_PRINT_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("printPdfTypeFilter", function (val) {
  return PRINT_PDF_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("examTypeFilter", function (val) {
  return EXAM_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("cardTypeFilter", function (val) {
  return CARD_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("pushCardTypeFilter", function (val) {
  return PUSH_CARD_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("cardCreateMethodTypeFilter", function (val) {
  return CARD_CREATE_METHOD_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("flowApproveOperationTypeFilter", function (val) {
  return FLOW_APPROVE_OPERATION_TYPE[val] || "";
});
Vue.filter("flowTypeFilter", function (val) {
  return FLOW_TYPE[val] || "";
});
Vue.filter("analysisBatchStatusFilter", function (val) {
  return ANALYSIS_BATCH_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("examNumberStyleFilter", function (val) {
  return EXAM_NUMBER_STYLE[val] || DEFAULT_FIELD;
});
Vue.filter("markModeTypeFilter", function (val) {
  return MARK_MODE_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("studentStatusFilter", function (val) {
  return STUDENT_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("evaluationModeFilter", function (val) {
  return EVALUATION_MODE[val] || DEFAULT_FIELD;
});
Vue.filter("courseTypeFilter", function (val) {
  return COURSE_TYPE[val] || DEFAULT_FIELD;
});
Vue.filter("progressFilter", function (val) {
  return !val && val !== 0 ? "0" : val * 100;
});
