import type { PropType} from 'vue'; import { computed, defineComponent, ref, toRef, watch } from 'vue' import { tools } from '@tools' import type { IDiscipline, IEvents } from 'model' import { useCalendarStore } from '@store/CalendarStore' import { CMyTeacher } from '@src/components/CMyTeacher' // @ts-ignore import MixinOperator from '../../mixins/mixin-operator' import MixinUsers from '../../mixins/mixin-users' import { useI18n } from 'vue-i18n'; export default defineComponent({ name: 'CCardDiscipline', components: { CMyTeacher }, props: { discipline: { Type: Object as PropType, required: false, default: {} }, directory: { type: String, required: false, default: '', }, mystyle: { type: String, required: false, default: '', }, autoplay: { type: Boolean, required: false, default: false, }, }, setup(props) { const { t } = useI18n() const nextlesson = ref() const calendarStore = useCalendarStore() const { getImgTeacherByUsername } = MixinOperator() const { isValidUsername } = MixinUsers() // const mydiscipline = toRef(props, 'discipline'); const getLinkEvent = computed(() => `event/${nextlesson.value.typol}/${nextlesson.value._id}`) function getNextLesson(typol: any): IEvents | undefined { // Get next lesson const datenow = tools.addDays(tools.getDateNow(), -1) return calendarStore.eventlist.find((myevent: IEvents) => (myevent.typol === typol) && (new Date(myevent.dateTimeEnd!) >= datenow)) } function disciplinechanged(myrec: IDiscipline) { nextlesson.value = getNextLesson(myrec.typol_code) // console.log('nextlesson', this.nextlesson) } watch(() => props.discipline, (value: any, oldval: any) => { nextlesson.value = getNextLesson(value.typol_code) }, ) function ExistLesson() { return !!nextlesson.value } function NextEventDate() { return tools.getstrDateTimeEventSimple(nextlesson.value) } function created() { if (tools.isObject(props.discipline)) disciplinechanged(props.discipline) } created() return { ExistLesson, NextEventDate, tools, getImgTeacherByUsername, getLinkEvent, isValidUsername, t, } }, })