import session from '@/lib/session'

export default {
  state: {
    user: '',
    isTab: '',
    expire: false,
    locale: 'cn',
    isZhCn: true,
    // 暗黑模式
    isDark: false,
  },
  mutations: {
    //个人信息/登录信息
    InitInfo(state, payload) {
      console.log(payload, '设置个人信息')
      if (payload != null) {
        session.Set('user', JSON.stringify(payload), true)
      }
      try {
        const userData = session.Get('user', true)
        state.user = userData ? JSON.parse(userData) : null
      } catch (error) {
        console.error('Error parsing user data in store:', error)
        state.user = null
      }
    },

    //tab切换
    isActiveTab(state, payload) {
      state.isTab = payload
      session.Set('isTab', payload)
    },

    //session过期
    InfoExpire(state, payload) {
      state.expire = payload
    },
    // 切换语言
    ChangeLanguage(state, payload) {
      state.locale = payload
      // 设置是否是中文
      state.isZhCn = payload === 'cn'
    },
    // 切换暗黑模式
    ChangeDark(state, payload) {
      state.isDark = payload
    },
  },
}
