const KEY_ACCOUNT= 'x-account'
const KEY_INFO = 'x-info'
const KEY_SEAL = 'x-seal'
const KEY_PWD_TIPS = 'show_pwd_tips'
const KEY_MENUS = 'x-menus'

export function savePwdTips(show) {
    localStorage.setItem(KEY_PWD_TIPS, show);
}

export function getPwdTips() {
    return localStorage.getItem(KEY_PWD_TIPS);
}

export function removePwdTips() {
    localStorage.removeItem(KEY_PWD_TIPS);
}

export function saveAccount(account) {
    localStorage.setItem(KEY_ACCOUNT, account)
}

export function getAccount() {
    return localStorage.getItem(KEY_ACCOUNT)
}

export function removeAccount() {
    localStorage.removeItem(KEY_ACCOUNT)
}

export function saveSeal(data) {
    localStorage.setItem(KEY_SEAL, JSON.stringify(data));
}

export function getSeal() {
    const json = localStorage.getItem(KEY_SEAL);
    return json ? JSON.parse(json) : null;
}

export function removeSeal() {
    localStorage.removeItem(KEY_SEAL);
}

export function saveInfo(info) {
    localStorage.setItem(KEY_INFO, JSON.stringify(info));
}

export function updateUserHeader(content) {
    const json = getInfo();
    if (json && content) {
        json.avatar = content;
        saveInfo(json);
    }
}

export function getInfo() {
    const json = localStorage.getItem(KEY_INFO);
    return json ? JSON.parse(json) : null;
}

export function removeInfo() {
    localStorage.removeItem(KEY_INFO)
}

export function saveMenus(menus) {
    localStorage.setItem(KEY_MENUS, JSON.stringify(menus));
}

export function getMenus() {
    const json = localStorage.getItem(KEY_MENUS);
    if (json) {
        return JSON.parse(json);
    }
    return [];
}

export function removeMenus() {
    localStorage.removeItem(KEY_MENUS);
}

export function logout() {
    localStorage.removeItem(KEY_PWD_TIPS);
    localStorage.removeItem(KEY_ACCOUNT);
    localStorage.removeItem(KEY_INFO);
    localStorage.removeItem(KEY_SEAL);
    localStorage.removeItem(KEY_MENUS);
}