/**
 * Created by baoyinghai on 4/13/17.
 */
const menuKey = 'QUICK_MENU';
const menuGlob = 'MENU';
const dashboardKey = 'DASHBOARD';
if (!localStorage) {
  console.error('not support localStorage');
}

const cache = localStorage || {};

const getValue = key => cache[key] && JSON.parse(cache[key]);

const saveValue = (key, value) => {
  cache[key] = JSON.stringify(value);
};

export const getMenus = () => {
  const menu = getValue(menuKey);
  return menu || [];
};

export const saveMenuCode = menuCode => {
  const menus = getMenus();
  if (menus.indexOf(menuCode) === -1) {
    menus.push(menuCode);
  }
  saveValue(menuKey, menus);
};

export const saveMenus = menusList => {
  saveValue(menuKey, menusList);
};

export const saveDashBoardPlugins = data => {
  saveValue(dashboardKey, data);
};

export const getDashBoardPlugins = () => {
  return getValue(dashboardKey);
};

export const saveMenuGlobal = menu => {
  saveValue(menuGlob, menu);
};

export const getMenuClobal = () => {
  return getValue(menuGlob);
};
