/*
 * @Author: zhanyoulin<zhanyoulin456@163.com>
 * @Date: 2023-06-13 09:41:17
 * @LastEditors: xiejiang
 * @LastEditTime: 2024-12-10 17:13:53
 * @Description:
 */

/* GlobalState */
import { ComputedRef } from 'vue'
import { ResVersion } from '@/api/interface/version/index'

export interface GlobalState {
  isCollapse: boolean
  isDark: boolean
}

export interface UserInfo {
  avatar: string
  hasPassword: boolean
  menuButtonIDs: string[]
  menuButtonSigns: string[]
  menuTree: any[]
  roleNames: string[]
  loginInfo: {
    device: string
    ip: string
    loginIp?: string
    location?: string
    loginAddress?: string
    time: string
  }
  clientLastVersion?: ResVersion
  status: string
  telephone: string
  token: string
  needUpd?: Boolean
  userType: number | string
  userId: string
  userName: string
}

/* UserState */
export interface UserState {
  token: string
  userInfo: Nullable<UserInfo>
}

/* tabsMenuProps */
export interface TabsMenuProps {
  title: string
  path: string
  name: string
  close: boolean
}

/* TabsState */
export interface TabsState {
  tabsMenuList: TabsMenuProps[]
}

/* AuthState */
export interface AuthState {
  authButtonList: string[]
  authMenuList: Menu.MenuOptions[]
  menuSign: string
  activeMenuId: string
  routeNameMap: {
    [key: string]: boolean
  }
  breadcrumbList: any[]
}

// AuthGetters
export interface AuthGetters {
  // 按钮权限列表
  authButtonListGet: ComputedRef<AuthState['authButtonList']>
  // 菜单权限列表 ==> 去除掉按钮权限级别后的菜单
  authMenuListGet: ComputedRef<Menu.MenuOptions[]>
  // 扁平化菜单，用于菜单搜索
  flatMenuListGet: ComputedRef<Menu.MenuOptions[]>
}

// AuthActions
export interface AuthActions {
  // 设置可访问按钮数据
  setAuthButtonList(data: string[]): Promise<void>
  // 设置可访问菜单数据
  setAuthMenuList(data: Menu.MenuOptions[]): Promise<void>
  // 设置当前页面的路由name
  setMenuSign(name: string): Promise<void>
  // 设置激活当前激活菜单ID
  setActiveMenuId(id: string): Promise<void>
  // 用户菜单权限的name集合
  setRouteNameMap(menuTree: any[]): void
  // 设置面包屑数据
  setBreadcrumb(data: any[]): void
}

export interface AuthStore extends AuthState, AuthGetters, AuthActions {}

/* KeepAliveState */
export interface KeepAliveState {
  keepAliveName: string[]
}
