import Vue from "vue";
import { PUBLISH_STATUS } from "../constants/enumerate";
import { formatDate } from "./utils";

const DEFAULT_FIELD = "--";

Vue.filter("publishStatusFilter", function(val) {
  return PUBLISH_STATUS[val] || DEFAULT_FIELD;
});
Vue.filter("studentExamTypeFilter", function(val) {
  return val ? "应届" : "非应届";
});
Vue.filter("percentFilter", function(val) {
  if (val === "" || val === null || val === undefined) return DEFAULT_FIELD;
  return (val * 100).toFixed(2) + "%";
});
Vue.filter("timestampFilter", function(val) {
  return val
    ? formatDate("YYYY-MM-DD HH:mm:ss", new Date(val * 1))
    : 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("enableFilter", function(val) {
  return val ? "启用" : "禁用";
});
