import Cookies from 'js-cookie'

// Token
const TokenKey = 'User-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

// 用户基本信息
const UserData = 'User-Data'

export function getUserData() {
  const userDataStr = Cookies.get(UserData)
  if (userDataStr) {
    return JSON.parse(userDataStr)
  }
}

export function setUserData(userData) {
  return Cookies.set(UserData, JSON.stringify(userData))
}

export function removeUserData() {
  return Cookies.remove(UserData)
}

// 用户权限
const UserPermit = 'User-Permit'

export function getUserPermit() {
  const userPermitStr = Cookies.get(UserPermit)
  if (userPermitStr) {
    return JSON.parse(userPermitStr)
  }
}

export function setUserPermit(userPermit) {
  return Cookies.set(UserPermit, JSON.stringify(userPermit))
}

export function removeUserPermit() {
  return Cookies.remove(UserPermit)
}
