import Vue from 'vue'

// 乐团状态
Vue.filter('bandStatus', value => {
    let templateStatus = {
        APPLY: '报名中',
        PAY: '缴费中',
        PREPARE: '筹备中',
        UNDERWAY: '进行中',
        CANCELED: '取消'
    }
    return templateStatus[value]
})

// 课程类型
Vue.filter('coursesType', (value) => {
    let template = {
      NORMAL: '声部课',
      SINGLE: '声部课',
      MIX: "合奏课",
      HIGH: "基础技能课",
      VIP: "VIP课",
      DEMO: "试听课",
      COMPREHENSIVE: '综合课',
      ENLIGHTENMENT: '启蒙课',
      TRAINING: '集训课',
      TRAINING_SINGLE: '集训声部课',
      TRAINING_MIX: '集训合奏课',
      CLASSROOM: '课堂课',
      PRACTICE: '网管课',
      COMM: '对外课',
      MUSIC: '乐团课',
      HIGH_ONLINE: '线上基础技能课',
      MUSIC_NETWORK: '乐团网管课'
    }
    return template[value]
  })

// 合并数组
Vue.filter('joinArray', (value, type) => {
    if (!type) {
        type = ' '
    }
    if (typeof value == 'object' && value != null) {
        return value.join(type)
    } else {
        return value
    }
})

// 数据类型
Vue.filter('dataStatusCN', value => {
    let templateStatus = {
        '到课': '',
        '请假': 'truant',
        '旷课': 'leave'
    }
    return templateStatus[value]
})

// 考勤类型
Vue.filter('clockingIn', value => {
    let templateStatus = {
        NORMAL: "正常",
        TRUANT: "旷课",
        LEAVE: "请假",
        QUIT_SCHOOL: "休学",
        DROP_OUT: "退学"
    }
    return templateStatus[value]
})

// 课程类型
Vue.filter('teachModeStatus', value => {
    let templateStatus = {
        ONLINE: "线上课",
        OFFLINE: "线下课"
    }
    return templateStatus[value]
})

// 消耗类型
Vue.filter('periodRecordStatus', value => {
    let templateStatus = {
        NOT_START: "未开始",
        APPLYING: "报名中",
        NORMAL: "正常",
        LOCK: "锁定",
        FINISH: "结束",
        CANCEL: "取消"
    }
    return templateStatus[value]
})

// 计算分钟数
Vue.filter('calcMinute', (minute) => {
    if (minute <= 0) {
        return '0分钟'
    }
    let minutes = minute % 60 // 算出分钟
    let hours = 0 // 小时
    if (minute >= 60) {
        hours = (minute - minutes) / 60
    }
    let text = ''
    if (hours) {
        text = hours + '小时'
    }
    if (minutes) {
        text += minutes + '分钟'
    }
    return text
})

Vue.filter('formatDate', value => {
    let d = new Date(value.replace(/-/ig, '/'))
    let hour = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours()
    let minute = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes()
    return hour + ':' + minute
})

Vue.filter('formatTimer', (value) => {
    if (value) {
      return value.split(' ')[0]
    } else {
      return value
    }
  })