import 'whatwg-fetch';
import './public-path';
import '!file-loader?name=[name].[ext]!./images/favicon.ico';
import './global.less';
import 'animate.css/animate.css';
import 'antd/dist/antd.less';
import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/extensions
import '@wisdom-utils/utils/lib/helpers/format';
import 'sanitize.css/sanitize.css';
import { event } from '@wisdom-utils/utils';
import { ConfigProvider } from 'antd';
import { Storeage } from '@wisdom-utils/utils/lib/helpers';
import { history } from '@wisdom-utils/runtime';
import { actionCreators } from './containers/App/store';
import { initGlobalConfig } from './initConfig';
import './utils/event';

import store from './stores';
// eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace);
ConfigProvider.config({
  prefixCls: 'panda-console-base',
});
const initLocale = () => {
  localStorage.setItem('umi_locale', 'zh-CN');
};
// const PRODUCT_NAME = ['civ_water', 'civ_monitor'];

initGlobalConfig();
initLocale();
const unlisten = (function() {
  let prePathname = '';
  return history.listen(location => {
    if (location.pathname.indexOf('/civbase/user/login') > -1 && location.pathname !== prePathname) {
      initGlobalConfig();
    }
    prePathname = location.pathname;
  });
})();

event.on('event:logout', () => {
  store.dispatch(actionCreators.logout());
});