'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPageData = exports.updateSecurityToken = exports.getSecurityToken = exports.savePageData = exports.getRouting = exports.getLoadingBarStatus = exports.getSubMenu = exports.getMenu = exports.getToken = exports.isInitDataFromServer = exports.init = undefined;

var _fetch = require('../system/fetch');

var _links = require('../constant/links');

var _links2 = _interopRequireDefault(_links);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Created by baoyinghai on 10/21/16.
 */
var _store = null;
/* eslint-disable */
var init = exports.init = function init(store) {
  _store = store;
};

var isInitDataFromServer = exports.isInitDataFromServer = function isInitDataFromServer() {
  return _store.getState().global.isInit;
};

var getToken = exports.getToken = function getToken() {
  return _store.getState().global.token;
};

var getMenu = exports.getMenu = function getMenu() {
  return _store.getState().menu;
};
var getSubMenu = exports.getSubMenu = function getSubMenu() {
  return _store.getState().subMenu;
};

var getLoadingBarStatus = exports.getLoadingBarStatus = function getLoadingBarStatus() {
  return _store.getState().loadingBar;
};

var getRouting = exports.getRouting = function getRouting() {
  return _store.getState().routing || {};
};

var _cache = {
  enterMenuId: null,
  processMenuId: null,
  securityToken: {} // Object
};

var savePageData = exports.savePageData = function savePageData(data) {
  _cache.data = data;
};

var getSecurityToken = exports.getSecurityToken = function getSecurityToken() {
  return _cache.securityToken;
};

var updateSecurityToken = exports.updateSecurityToken = function updateSecurityToken() {
  return (0, _fetch.PFetchNoContext)(_links2.default.getStsToken, {}).then(function (response) {
    _cache.securityToken = response;
    return response;
  });
};

var getPageData = exports.getPageData = function getPageData() {
  return _cache.data;
};