import Cookies from 'js-cookie'

const TokenKey = 'Dms-Admin-Token'

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

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

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

/** tentant 缓存 */
const TenantKey = 'Dms-Tenant-Key'

export function getTenant() {
  const cookieTenant = Cookies.get(TenantKey)
  return cookieTenant ? JSON.parse(cookieTenant) : null
}

export function setTenant(tenant) {
  const tenantStr = JSON.stringify(tenant)
  return Cookies.set(TenantKey, tenantStr)
}

/** 已阅读公告缓存 */
const notificationKey = 'Dms-Notification'
export function setShowedNotification(id) {
  const showedNotification = !Cookies.get(notificationKey) ? [] : JSON.parse(Cookies.get(notificationKey))
  showedNotification.push(id)
  return Cookies.set(notificationKey, JSON.stringify(showedNotification))
}
export function getShowedNotification() {
  const showedNotification = Cookies.get(notificationKey)
  return showedNotification ? JSON.parse(showedNotification) : null
}
