import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";
import dayjs from "dayjs";
import { Howl } from "howler";
const store = createStore({
  plugins: [createPersistedState()],
  state: () => ({
    token: "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjllNTU3NDk1LWQyOGQtNDMyNy1hYTBjLTdjOTk2OTk5NTk1YiJ9.GvGgys5erlFYJMLEhk2S1e7W_9CKDJohfXfW8fZpitkpZ8RWni5u9VvTGjl8dhD1916s-4MTM_7TsNaTNwsuPg",
    userData: {
      schoolName: "",
      realName: ""
    },
    lightAudio: null,
    lightConfig: {
      interval: 5,
      directives: 5,
      isTipSound: false,
      type: 0,
      typelist: [{
        name: "随机抽取多条指令"
      }, {
        name: "随机抽取一个组合"
      }]
    },
    carType: "0",
    suject: "0",
  }),
  getters: {
    getLightInterval(state) {
      return state.lightConfig.interval * 1000
    },
    getSchoolName(state) {
      return state.userData.schoolName

    },
    getRealName(state) {
      return state.userData.realName
    },
    getCarType(state) {
      return state.carType;
    },
    getToken(state) {
      return state.token;
    },
    getUserData(state) {
      return state.userData;
    },
    getIsVip(state): Boolean {
      const userTime: number = dayjs(store.getters.getUserData.expireTime).valueOf();
      const currentTime: number = dayjs().valueOf();
      //return (userTime - currentTime) > 0
      return true
    }
  },
  mutations: {
    setLightConfig(state, lightConfig: {
      interval: number;
      directives: number;
      isTipSound: boolean;
      typelist: {
        name: string;
      }[]
    }) {
      state.lightConfig = lightConfig

    },
    setSuject(state, suject: string) {
      state.suject = suject;
    },
    setCatType(state, carType: string) {
      state.carType = carType;
    },
    setToken(state, token: string) {
      state.token = token;
    },
    setUserData(state, userData: object) {
      state.userData = userData;
    },
  },
});

export default store;
