import Cookies from 'js-cookie'

const MenuKey = 'Conference-Console-Menu'
const BtnKey = 'Conference-Console-MenuBtn'
const NoticeKey = 'Conference-Console-Notice'
const mainMenuKey = 'Conference-Console-MainMenu'
const businessCompanyKey = 'Conference-Console-businessCompany'
const businessCompanyNoKey = 'Conference-Console-businessCompanyNo'
const privateFieldKey = 'Conference-Console-privateField'
const actionDataKey = 'Conference-Console-actionData'
const roleLevelKey = 'Conference-Console-roleLevel'
const companyKey = 'Conference-Console-company'
const userLevelkey = 'puchase-Console-level'
const userKey = 'Conference-Console-user'

export const TokenKey = 'Conference-Console-Token'
// 业务公司business 供应商supplier
const companyTypeKey = 'Conference-Console-companyType'

export function setUserLevel(type) {
  return localStorage.setItem(userLevelkey, type)
}

export function getUserLevel() {
  return localStorage.getItem(userLevelkey) || ''
}

export function removeUserLevel() {
  return localStorage.removeItem(userLevelkey) || ''
}

export function setCompanyType(type) {
  return localStorage.setItem(companyTypeKey, type)
}
export function getCompanyType() {
  return localStorage.getItem(companyTypeKey) || ''
}
export function removeCompanyType() {
  return localStorage.removeItem(companyKey)
}

export function setUserInfo(info) {
  return localStorage.setItem(userKey, info ? JSON.stringify(info) : '')
}

export function removeUserInfo() {
  return localStorage.removeItem(userKey)
}

export function getUserInfo() {
  const userInfo = localStorage.getItem(userKey)
  return userInfo ? JSON.parse(userInfo) : ''
}

export function setUserCompany(company) {
  return localStorage.setItem(companyKey, company ? JSON.stringify(company) : '')
}

export function removeUserCompany() {
  return localStorage.removeItem(companyKey)
}

export function getUserCompany() {
  const company = localStorage.getItem(companyKey)
  return company ? JSON.parse(company) : ''
}

export function getToken() {
  return localStorage.getItem(TokenKey)
}

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

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

export function getMenu() {
  const menu = localStorage.getItem(MenuKey)
  if (menu) {
    return JSON.parse(menu)
  } else {
    return []
  }
}

export function setMenu(menu) {
  return localStorage.setItem(MenuKey, JSON.stringify(menu))
}

export function removeMenu() {
  return localStorage.removeItem(MenuKey)
}

export function getBtn() {
  return localStorage.getItem(BtnKey)
}

export function setBtn(has) {
  return localStorage.setItem(BtnKey, has)
}

export function removeBtn() {
  return localStorage.removeItem(BtnKey)
}

export function getNotice() {
  return Cookies.get(NoticeKey)
}

export function setNotice(has) {
  return Cookies.set(NoticeKey, has)
}

export function removeNotice() {
  return Cookies.remove(NoticeKey)
}

export function getMainList() {
  return Cookies.get(mainMenuKey)
}

export function setMainList(has) {
  return Cookies.set(mainMenuKey, has)
}

export function removeMainList() {
  return Cookies.remove(mainMenuKey)
}

export function get_business_company() {
  return Cookies.get(businessCompanyKey)
}

export function set_business_company(has) {
  return Cookies.set(businessCompanyKey, has)
}

export function remove_business_company() {
  return Cookies.remove(businessCompanyKey)
}
export function get_business_companyNo() {
  return Cookies.get(businessCompanyNoKey)
}

export function set_business_companyNo(has) {
  return Cookies.set(businessCompanyNoKey, has)
}

export function remove_business_companyNo() {
  return Cookies.remove(businessCompanyNoKey)
}

export function get_private_field() {
  return Cookies.get(privateFieldKey)
}

export function set_private_field(has) {
  return Cookies.set(privateFieldKey, has)
}

export function remove_private_field() {
  return Cookies.remove(privateFieldKey)
}

export function get_action_data() {
  const process = Cookies.get(actionDataKey)
  return process && typeof process === 'string' ? JSON.parse(process) : []
}

export function set_action_data(has) {
  return Cookies.set(actionDataKey, has)
}

export function remove_action_data() {
  return Cookies.remove(actionDataKey)
}

export function get_role_level() {
  return Cookies.get(roleLevelKey)
}

export function set_role_level(has) {
  return Cookies.set(roleLevelKey, has)
}

export function remove_role_level() {
  return Cookies.remove(roleLevelKey)
}
