import { useAppStoreWithOut } from '@/store/modules/app'
import { useStorage } from '@/hooks/web/useStorage'

/**
 * @param userInfo 获取登录信息存储字段
 * @returns
 */
export const getUserInfo = (): any => {
  const appStore = useAppStoreWithOut()
  const { getStorage } = useStorage()
  const userInfo = getStorage(appStore.getUserInfo)
  return userInfo
}

/**
 * @param userInfo 根据登录信息存储字段获取登录名
 * @returns
 */
export const getNameByUserInfo = (userInfo?: any): any => {
  if (!userInfo) {
    const appStore = useAppStoreWithOut()
    const { getStorage } = useStorage()
    userInfo = getStorage(appStore.getUserInfo)
  }
  return userInfo?.session_userName
}

/**
 * 根据登录信息存储字段获取登录号
 * @returns
 */
export const getLoginNameByUserInfo = (): any => {
  const appStore = useAppStoreWithOut()
  const { getStorage } = useStorage()
  const userInfo = getStorage(appStore.getUserInfo)
  return userInfo?.session_loginName
}

/**
 * 根据登录信息存储字段当前登录用户机构号
 * @returns
 */
export const getLoginOrganCodeByUserInfo = (): any => {
  const appStore = useAppStoreWithOut()
  const { getStorage } = useStorage()
  const userInfo = getStorage(appStore.getUserInfo)
  return userInfo?.session_organCode
}

/**
 * 获取当前登录用户的ID
 */
export const getUserIdByUserInfo = (): any => {
  const appStore = useAppStoreWithOut()
  const { getStorage } = useStorage()
  const userInfo = getStorage(appStore.getUserInfo)
  return userInfo?.session_userId
}
