import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const useUrl = 'Back-Url'
const useType = 'use-Type'
const expTime = 'exp-time'

//1.设置token
export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token,exp) {
  const expdays = convertSecondsToDays(exp)
  return Cookies.set(TokenKey, token, { expires: expdays })
}

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

//2.设置所属网站
export function setUserUrl(url,exp) {
  const expdays = convertSecondsToDays(exp)
  return Cookies.set(useUrl, url, { expires: expdays })
}

export function getUserUrl() {
  return Cookies.get(useUrl)
}

export function removUserUrl() {
  return Cookies.remove(useUrl)
}

//3.储存用户等级
export function setUseType(url,exp) {
  const expdays = convertSecondsToDays(exp)
  return Cookies.set(useType, url, { expires: expdays })
}

export function getUseType() {
  return Cookies.get(useType)
}

export function removUseType() {
  return Cookies.remove(useType)
}

//4.设置过期时间
export function getExp() {
  return Cookies.get(expTime)
}

export function setExp(exp) {
  const expdays = convertSecondsToDays(exp)
  return Cookies.set(exp, exp, { expires: expdays })
}

export function removeExp() {
  return Cookies.remove(expTime)
}

//5.把秒转换成天
function convertSecondsToDays(seconds) {
  return seconds/(60*60*24); //1天=60秒*60分钟*24小时
}


