import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let studentInfo = {}
let examInfo = {}
try {
  studentInfo = JSON.parse(window.localStorage.getItem('studentInfo')) || {}
  examInfo = JSON.parse(window.localStorage.getItem('examInfo')) || {}
} catch (error) {
  console.log(error)
}

export default new Vuex.Store({
  state: {
    studentInfo,
    examInfo
  },
  mutations: {
    setExamInfo(state, info) {
      state.examInfo = info
      window.localStorage.setItem('examInfo', JSON.stringify(info))
    },
    setStudentInfo(state, info) {
      state.studentInfo = info
      window.localStorage.setItem('studentInfo', JSON.stringify(info))
    }
  }
})
