import Cookies from 'js-cookie'
const TokenKeyMain = 'dy_admin_token'

const TokenKey = 'live_admin_token'

export const getToken = () => {
  const mainToken = Cookies.get(TokenKeyMain)
  const token = localStorage.getItem(TokenKey)
  let returnToken: string | null = null
  if (token) {
    returnToken = token
  } else if (mainToken) {
    // 如果有主系统的token，则设置为主系统的token
    localStorage.setItem(TokenKey, mainToken)
    returnToken = mainToken
  }
  return returnToken
}

export function setToken (token: string) {
  return localStorage.setItem(TokenKey, token)
}

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

