'use strict';

require('babel-polyfill');

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

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

var _configureStore2 = _interopRequireDefault(_configureStore);

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

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

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

var _routes2 = _interopRequireDefault(_routes);

var _DeviceProvider = require('./components/DeviceProvider');

var _DeviceProvider2 = _interopRequireDefault(_DeviceProvider);

var _mobileDetect = require('mobile-detect');

var _mobileDetect2 = _interopRequireDefault(_mobileDetect);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

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

/* global __REDUX_STATE__ */
var reduxState = void 0;
if (window.__REDUX_STATE__) {
  try {
    reduxState = JSON.parse(unescape(__REDUX_STATE__));
  } catch (e) {
    reduxState = '';
  }
  var md = new _mobileDetect2.default(window.navigator.userAgent);
  if (md.tablet()) {
    reduxState.device = 'tablet';
  } else if (md.mobile()) {
    reduxState.device = 'mobile';
  } else {
    reduxState.device = 'desktop';
  }
}

var store = (0, _configureStore2.default)(reduxState);

var history = (0, _reactRouterRedux.syncHistoryWithStore)(_reactRouter.browserHistory, store);

var device = store.getState().device;
_reactDom2.default.render(_react2.default.createElement(
  _reactRedux.Provider,
  { store: store },
  _react2.default.createElement(
    _DeviceProvider2.default,
    { device: device },
    (0, _routes2.default)(history)
  )
), document.getElementById('root'));