/*
 * @Author: wjc
 * @Date: 2023-11-27 15:35:24
 * @LastEditors: LiZhiWei
 * @LastEditTime: 2026-01-09 16:45:59
 * @Description:
 */
import { getToken } from '@/utils/auth'

interface IUser {
  id?: string
}

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      userInfo: {} as IUser,
      navMenu: [],
    }
  },
  getters: {
    getUser(): IUser {
      if (process.browser) {
        const token = getToken()
        const userInfo = localStorage.getItem('userInfo')
        if (userInfo && token) {
          return JSON.parse(userInfo)
        }
        return this.userInfo
      } else {
        return this.userInfo
      }
    },
    getEnterpriseUserId(): string {
      return this.userInfo.id || ''
    },
  },
  actions: {
    clearUserInfo() {
      this.userInfo = {}
    },
  },
})
