import Cookie from 'js-cookie'
import { Base64 } from 'js-base64'
import { getAccessToken } from '@/api/login'

const TokenKey = 'TOKEN'
function setToken(value: string) {
  Cookie.set(TokenKey, value)
}
function getToken() {
  return Cookie.get(TokenKey)
}
function removeToken() {
  Cookie.remove(TokenKey)
}

function setStorage(StorageKey: string, value: string) {
  return localStorage.setItem(StorageKey, value)
}

function getStorage(StorageKey: string) {
  return localStorage.getItem(StorageKey)
}

function removeStorage(StorageKey: string) {
  return localStorage.removeItem(StorageKey)
}

function setAccessToken(){
  getAccessToken().then((res) => {
    if(res.data.code == 'success'){
      setToken(res.data.data.token)
    }
  })
}

export {
  removeToken,
  getToken,
  setToken,
  setStorage,
  getStorage,
  removeStorage,
  setAccessToken
}
