import Cookies from "js-cookie"

/* code */
// eslint-disable-next-line prefer-const
export let CODE401 = 5000 // 没有权限
export const CODE_ERR_CANCELED = "ERR_CANCELED" // 取消请求的code
export function setCODE401(code: number) {
  CODE401 = code
}

/** cookie */
const TokenKey = "ppt-Token"
const expiresDate = 7

export let TokenInvalidFlag = true // 令牌是否有效
export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token: string) {
  TokenInvalidFlag = true
  return Cookies.set(TokenKey, token, { expires: expiresDate })
}

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