import cacheMixin from '@/components/Cache/mx-cache-mixin.js'

export default {
  mixins: [cacheMixin],
  data() {
    return {
      listGroupsOptions: [],
      listGroupTranslateReady: false
    }
  },
  beforeMount() {
    this.loadTranslateGroup()
  },
  methods: {
    async loadTranslateGroup() {
      this.listGroupsOptions = await this.getListGroupsByCache()
      this.listGroupTranslateReady = true
      this.translateGroupReady()
    },
    translateGroupReady() {
      //to be overrided for non-computed needs
    },
    translateGroupIds(item) {
      if (!this.listGroupTranslateReady) return
      const groupNames = item.groupIds && item.groupIds.split(',').map(this.translateGroup).toString() || ''
      this.$set(item, 'groupIdsName', groupNames)
    },
    translateGroup(groupId) {
      return this.listGroupsOptions.find(g => g.value == groupId)?.text || '未知选科组合'
    },
    translateCourse0(groupId) {
      return this.listGroupsOptions.find(g => g.value == groupId)?.course0
    },
    translateCourse1(groupId) {
      return this.listGroupsOptions.find(g => g.value == groupId)?.course1
    }
  }
}
