import { reactive, ref } from 'vue'

const runtime = reactive({
  messageList: [] as Array<any>,
  joinList: {} as { [key: string]: any },
  joinTips: false as boolean, // 是否显示加入提示
  lookList: {} as { [key: string]: any },
})

export default runtime

// 添加消息
type Message = {
  name: string,
  id: number,
  isSelf?: boolean,
  content?: string,
  sendTime?: string
  type?: string | number,
  audienceName?: string,
  audienceId?: string | number,
  teacherId?: string | number,
  userRoomType?: string | number, // 讲师状态
  teacherName?: string,
}
/**
 * 添加消息
 * @param message 消息对象
 */
export const addMessage = (message: Message) => {
  runtime.messageList.push(message)
}
/**
 * 添加上麦消息
 */
export const addJoin = (key: string, message: Message) => {
  runtime.joinTips = true
  runtime.joinList[key] = message
}
/**
 * 移除下麦
 * @param key 用户编号
 */
export const removeJoin = (key: string) => {
  delete runtime.joinList[key]
}

/**
 * 添加观看人数
 * @param key 用户编号
 * @param message
 */
export const addLook = (key: string,message: Message) => {
  runtime.lookList[key] = message
}
/**
 * 移除观看人数
 * @param key 用户编号
 */
 export const removeLook = (key: string) => {
  delete runtime.lookList[key]
}
