/**
 * Created by baoyinghai on 10/21/16.
 */
import { PFetchNoContext } from '../system/fetch';
import Links from '../constant/links';

let _store = null;
/* eslint-disable */
export const init = store => {
  _store = store;
};

export const isInitDataFromServer = () => _store.getState().global.isInit;

export const getToken = () => _store.getState().global.token;

export const getMenu = () => _store.getState().menu;
export const getSubMenu = () => _store.getState().subMenu;

export const getLoadingBarStatus = () => _store.getState().loadingBar;

export const getRouting = () => {
  return _store.getState().routing || {};
}

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

export const savePageData = data => {
  _cache.data = data;
};

export const getSecurityToken = () => {
  return _cache.securityToken;
};

export const updateSecurityToken = () => {
  return PFetchNoContext(Links.getStsToken, {}).then(response => {
    _cache.securityToken = response;
    return response;
  });
};

export const getPageData = () => _cache.data;
