'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactRedux = require('react-redux');

var _reactRouter = require('react-router');

var _reactRouterRedux = require('react-router-redux');

var _qs = require('qs');

var _qs2 = _interopRequireDefault(_qs);

var _loadingBar = require('../modules/loading-bar');

var _loadingBar2 = _interopRequireDefault(_loadingBar);

var _configureStore = require('../store/configureStore');

var _configureStore2 = _interopRequireDefault(_configureStore);

var _analytics = require('../service/analytics');

var _analytics2 = _interopRequireDefault(_analytics);

var _ServiceInitHelper = require('../service/ServiceInitHelper');

var _routes = require('./routes');

var _routes2 = _interopRequireDefault(_routes);

var _global = require('../actions/global');

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

// import LoadingBar from 'react-redux-loading-bar';
var appStyle = {
  appLoadBar: {
    color: '#FE880B',
    backgroundColor: '#FE880B',
    height: 5,
    position: 'absolute',
    zIndex: 999999
  }
};

var setup = function setup() {
  var store = (0, _configureStore2.default)({});
  store.dispatch((0, _global.initApp)());
  (0, _ServiceInitHelper.executeInit)(store);
  var history = (0, _reactRouterRedux.syncHistoryWithStore)(_reactRouter.browserHistory, store);
  history.listen(function (location) {
    _analytics2.default.track(location.pathname);
    if (location.query.p === undefined) {
      store.dispatch((0, _global.updateQuery)({}));
    } else {
      var query = atob(location.query.p);
      store.dispatch((0, _global.updateQuery)(_qs2.default.parse(query)));
    }
  });

  var AppContainer = function AppContainer(props) {
    return _react2.default.createElement(
      _reactRedux.Provider,
      { store: store },
      _react2.default.createElement(
        'div',
        { className: 'body-wrapper' },
        _react2.default.createElement(_loadingBar2.default, { className: appStyle.appLoadBar }),
        _react2.default.createElement(_reactRouter.Router, { history: history, routes: (0, _routes2.default)(props.homePage) })
      )
    );
  };
  return AppContainer;
};

exports.default = setup();