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

export default {
	mixins: [cacheMixin],
	data() {
		return {
			userSubjectList: [],
      userSubjectListReady: false
		}
	},
	beforeMount() {
		this.loadUserSubjectList()
	},
	methods: {
		async loadUserSubjectList() {
			this.userSubjectList = await this.getUserSubjectListByCache()
      this.userSubjectListReady = true
			this.translateSubjectReady()
		},
		translateSubjectReady() {
			//to be overrided for non-computed needs
		},
		translateSubjectName(subjectId) {
			if (!subjectId) return ''
			let idArr = subjectId
			if (!Array.isArray(idArr)) {
				idArr = idArr.includes(',') ? idArr.split(',') : [idArr]
			}

			return idArr.map(id => this.userSubjectList
					.find(s => s.subjectid == id)?.subjectname || '未知科目')
				.toString()
		},
	}
}
