'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
/**
 * Created by baoyinghai on 4/13/17.
 */
var menuKey = 'QUICK_MENU';
var menuGlob = 'MENU';
var dashboardKey = 'DASHBOARD';
if (!localStorage) {
  console.error('not support localStorage');
}

var cache = localStorage || {};

var getValue = function getValue(key) {
  return cache[key] && JSON.parse(cache[key]);
};

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

var getMenus = exports.getMenus = function getMenus() {
  var menu = getValue(menuKey);
  return menu || [];
};

var saveMenuCode = exports.saveMenuCode = function saveMenuCode(menuCode) {
  var menus = getMenus();
  if (menus.indexOf(menuCode) === -1) {
    menus.push(menuCode);
  }
  saveValue(menuKey, menus);
};

var saveMenus = exports.saveMenus = function saveMenus(menusList) {
  saveValue(menuKey, menusList);
};

var saveDashBoardPlugins = exports.saveDashBoardPlugins = function saveDashBoardPlugins(data) {
  saveValue(dashboardKey, data);
};

var getDashBoardPlugins = exports.getDashBoardPlugins = function getDashBoardPlugins() {
  return getValue(dashboardKey);
};

var saveMenuGlobal = exports.saveMenuGlobal = function saveMenuGlobal(menu) {
  saveValue(menuGlob, menu);
};

var getMenuClobal = exports.getMenuClobal = function getMenuClobal() {
  return getValue(menuGlob);
};