import type { LocalCourseRoom, RemoteCourseRoom } from '@/api/meeting';
import { StorageSerializers, useStorage } from '@vueuse/core';
import { defineStore } from 'pinia';

/**
 * 注册全局状态相关的store
 */
export const useMeetingStore = defineStore('meeting', () => {
  /** 当前选择的课程房间 */
  const currCourseRoom = useStorage<LocalCourseRoom | RemoteCourseRoom | null>('my_store_curr_curr_course_room', null, window.sessionStorage, {
    serializer: StorageSerializers.object,
  });

  return {
    /** 当前选择的课程房间 */
    currCourseRoom,

    /** 设置当前选择的辅导信息 */
    setCurrCourseRoom(courseRoom: LocalCourseRoom | RemoteCourseRoom) {
      currCourseRoom.value = courseRoom || null;
    },
    /** 清除 */
    clear() {
      currCourseRoom.value = null;
    },
  };
});
