import {
  ROLE_TYPE,
  CUSTOMER_TYPE,
  SUPPLIER_TYPE,
  RUNNING_STATUS,
  NOTICE_TYPE,
  PUBLISH_STATUS,
  SERVICE_UNIT_STATUS,
  ISSUES_TYPE,
  ISSUES_REASON_TYPE,
  FLOW_STATUS,
  AUDITING_RESULT,
  ATTENDANCE_TYPE,
  ATTENDANCE_RESULT,
  AUTHENTICATION_STATUS,
  AUTHENTICATION_ROLE,
  INOUT_TYPE,
  GENDER_TYPE,
  EDUCATION_TYPE,
  DATA_TASK_STATUS,
  DATA_TASK_RESULT,
  DATA_TASK_TYPE,
  MESSAGE_TYPE,
  WAIT_HANDLE_TYPE,
  DEVICE_USAGE_TYPE,
  ATTENDANCE_SUBMIT_STATUS,
  ATTENDANCE_STATISTICS_SUBMIT_STATUS,
  VIOLATION_TYPE,
  VIOLATION_FLOW_STATUS,
  WARN_TYPE,
  WARN_FLOW_STATUS,
  CRM_STATUS,
} from '@/config/constants';
import { dateFormat } from './tool';

const DEFAULT_FIELD = '--';

// 常规
export function enableFilter(val) {
  return val ? '启用' : '禁用';
}
export function auditingResultFilter(val) {
  return AUDITING_RESULT[val] || DEFAULT_FIELD;
}
export function roleTypeFilter(val) {
  return ROLE_TYPE[val] || DEFAULT_FIELD;
}
export function genderTypeFilter(val) {
  return GENDER_TYPE[val] || DEFAULT_FIELD;
}
export function educationTypeFilter(val) {
  return EDUCATION_TYPE[val] || DEFAULT_FIELD;
}
export function timestampFilter(val, fmt = 'mm') {
  // fmt: dd or yyyy-MM-dd
  const formats = {
    dd: 'yyyy/MM/dd',
    mm: 'yyyy/MM/dd HH:mm',
    ss: 'yyyy/MM/dd HH:mm:ss',
    tt: 'HH:mm',
  };
  return val ? dateFormat(val, formats[fmt] || fmt) : DEFAULT_FIELD;
}
export function dayCountFilter(val) {
  return Math.ceil(val / (24 * 60 * 60 * 1000));
}
// 工作台
export function messageTypeFilter(val) {
  return MESSAGE_TYPE[val] || DEFAULT_FIELD;
}
export function waitHandleTypeFilter(val) {
  return WAIT_HANDLE_TYPE[val] || DEFAULT_FIELD;
}
// 系统管理
export function customerTypeFilter(val) {
  return CUSTOMER_TYPE[val] || DEFAULT_FIELD;
}
export function supplierTypeFilter(val) {
  return SUPPLIER_TYPE[val] || DEFAULT_FIELD;
}
export function runningStatusFilter(val) {
  return RUNNING_STATUS[val] || DEFAULT_FIELD;
}
export function noticeTypeFilter(val) {
  return NOTICE_TYPE[val] || DEFAULT_FIELD;
}
export function publishStatusFilter(val) {
  return PUBLISH_STATUS[val] || DEFAULT_FIELD;
}
export function dataTaskStatusFilter(val) {
  return DATA_TASK_STATUS[val] || DEFAULT_FIELD;
}
export function dataTaskResultFilter(val) {
  return DATA_TASK_RESULT[val] || DEFAULT_FIELD;
}
export function dataTaskTypeFilter(val) {
  return DATA_TASK_TYPE[val] || DEFAULT_FIELD;
}
// 服务单元管理
export function serviceUnitStatusFilter(val) {
  return SERVICE_UNIT_STATUS[val] || DEFAULT_FIELD;
}
// 项目质量管理
export function issuesTypeFilter(val) {
  return ISSUES_TYPE[val] || DEFAULT_FIELD;
}
export function issuesReasonTypeFilter(val) {
  return ISSUES_REASON_TYPE[val] || DEFAULT_FIELD;
}
// 工时管理
export function attendanceTypeFilter(val) {
  return ATTENDANCE_TYPE[val] || DEFAULT_FIELD;
}
export function attendanceResultFilter(val) {
  return ATTENDANCE_RESULT[val] || DEFAULT_FIELD;
}
// 资源保障
export function authenticationStatusFilter(val) {
  return AUTHENTICATION_STATUS[val + ''] || DEFAULT_FIELD;
}
export function authenticationRoleFilter(val) {
  return AUTHENTICATION_ROLE[val] || DEFAULT_FIELD;
}
export function inoutTypeFilter(val) {
  return INOUT_TYPE[val] || DEFAULT_FIELD;
}
export function deviceUsageTypeFilter(val) {
  return DEVICE_USAGE_TYPE[val] || DEFAULT_FIELD;
}
// sop
export function flowStatusFilter(val) {
  return FLOW_STATUS[val] || DEFAULT_FIELD;
}
export function attendanceSubmitStatusFilter(val) {
  return ATTENDANCE_SUBMIT_STATUS[val] || DEFAULT_FIELD;
}
export function attendanceStatisticsSubmitStatusFilter(val) {
  return ATTENDANCE_STATISTICS_SUBMIT_STATUS[val] || DEFAULT_FIELD;
}
export function violationTypeFilter(val) {
  return VIOLATION_TYPE[val] || DEFAULT_FIELD;
}
export function violationFlowStatusFilter(val) {
  return VIOLATION_FLOW_STATUS[val] || DEFAULT_FIELD;
}
export function warnTypeFilter(val) {
  return WARN_TYPE[val] || DEFAULT_FIELD;
}
export function warnFlowStatusFilter(val) {
  return WARN_FLOW_STATUS[val] || DEFAULT_FIELD;
}
export function crmStatusFilter(val) {
  return CRM_STATUS[val] || DEFAULT_FIELD;
}
