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

import browser from "@/utils/browser";

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    userAvatar: '',
    userNickName: '',
    
    info:'',
    backupInfo:'',
    showInfo:'',
    hotspot:'',
    backupHotSpot:'',
    initScene:'',
    tablist:[],
    temptablist:[],
    vrlist:[],
    allVrlist:[],
    sceneList:[],
    activeItem:'',
    isEditing:false,
    isShow: false,

    uploadStatusListAudio: [],
    uploadStatusListImage: [],
    uploadStatusListPano: [],
    uploadStatusListVideo: [],
  },
  getters: {
    userAvatar: state => state.userAvatar,
    userNickName: state => state.userNickName,

    isEditing:state=>state.isEditing,
    info:state=>state.info,
    showInfo:state=>state.showInfo,
    backupInfo:state=>state.backupInfo,
    hotspot:state=>state.hotspot,
    backupHotSpot:state=>state.backupHotSpot,
    initScene:state=>state.initScene,
    activeItem:state=>state.activeItem,
    vrlist:state=>state.vrlist,
    tablist:state=>state.tablist,
    temptablist:state=>state.temptablist,
    sceneList:state=>state.sceneList,
    isShow:state=>state.isShow,
    allVrlist:state=>state.allVrlist,

    uploadStatusListAudio: state => state.uploadStatusListAudio,
    uploadStatusListImage: state => state.uploadStatusListImage,
    uploadStatusListPano: state => state.uploadStatusListPano,
    uploadStatusListVideo: state => state.uploadStatusListVideo,
  },
  mutations: {
    SetUserAvatar(state, avatar) {
      if (typeof avatar === 'string') {
        state.userAvatar = avatar
      }
    },
    SetUserNickName(state, nickName) {
      if (typeof nickName === 'string') {
        state.userNickName = nickName
      }
    },
    
    SetTabList(state, list) {
      state.tablist = list
    },
    SetTempTabList(state, list) {
      state.temptablist = list
    },
    SetVrList(state, list) {
      state.vrlist = list
    },
    SetSceneList(state, list) {
      state.sceneList = list
    },
    UpdateIsShowState(state, isShow) {
      state.isShow = isShow
    },
    UpdateIsEditingState(state, isShow) {
      state.isEditing = isShow
    },
    SetAllVrlist(state, list) {
      state.allVrlist = list
    },
    SetInitScene(state, scene) {
      state.initScene = scene
    },
    SetActiveItem(state, scene) {
      state.activeItem = scene
    },
    SetShowInfo(state, data) {
      state.showInfo = data
    },
    SetInfo(state, data) {
      state.info = data
      this.commit("BackupInfo", browser.CloneObject(data));
    },
    BackupInfo(state, data) {
      state.backupInfo = data
    },
    SetHotspot(state, data) {
      state.hotspot = data
      this.commit("BackupHotSpot", browser.CloneObject(data));
    },
    BackupHotSpot(state, data) {
      state.backupHotSpot = data
    }
    
  },
  actions: {
    refreshUserInfo(context) {
      try {
        const userInfo = JSON.parse(localStorage.getItem('info'))
        context.commit('SetUserAvatar', userInfo.head)
        context.commit('SetUserNickName', userInfo.nickName)
      } catch (error) {
        console.log(error)
      }
    },
  },
  modules: {

  }
})

export default store