require('../style/index.less');
require('babel-polyfill');

var config = require('/opt/cocorico/app-web/config.json');

var Raven = require('raven-js');
var React = require('react');
var ReactRouter = require('react-router');
var ReactDOM = require('react-dom');

var Router = ReactRouter.Router,
  Route = ReactRouter.Route,
  IndexRoute = ReactRouter.IndexRoute,
  browserHistory = ReactRouter.browserHistory,

  App = require('./App'),
  Embed = require('./Embed'),
  Page = require('./page/Page'),
  Home = require('./page/Home'),
  Login = require('./page/Login'),
  ServiceStatus = require('./page/ServiceStatus'),
  VotePage = require('./page/VotePage'),
  EmbedVoteWidgetPage = require('./page/embed/VoteWidgetPage'),
  BallotBox = require('./page/BallotBox'),

  RouteAction = require('./action/RouteAction');

var messages = require('./intl/locale.js').getCurrentLocaleMessages();

function main() {
  // window.Intl polyfill
  // https://github.com/andyearnshaw/Intl.js/issues/118#issuecomment-120123392
  if (!window.Intl) {
    require.ensure(['intl'], (require) => {
      window.Intl = require('intl');
      run();
    }, 'IntlPolyfillBundle');
  } else {
    run();
  }
}

function run() {
  browserHistory.listen((location, action) => {
    RouteAction.change(browserHistory, location, action);
  });

  return ReactDOM.render(
    <Router history={browserHistory}>
      <Route path="/" component={App}>
        <IndexRoute component={Home}/>
        <Route path={messages.route.SIGN_IN} component={Login}/>
        <Route path={messages.route.SERVICE_STATUS} component={ServiceStatus}/>
        <Route path="vote/:slug" component={VotePage}/>
        <Route path={messages.route.BALLOT_BOX + '/:voteId'} component={BallotBox}/>
      </Route>
      <Route path="/embed" component={Embed}>
        <Route path="vote-widget/:voteId" component={EmbedVoteWidgetPage}/>
      </Route>
      <Route path="/" component={App}>
        <Route path=":slug" component={Page}/>
      </Route>
    </Router>,
    document.getElementById('root')
  );
}

console.log('commit hash:', __COMMIT_HASH__);
console.log('build number:', __BUILD_NUMBER__);
console.log('build date:', __BUILD_DATE__);
console.log('env:', __ENV__);

if (!!Raven) {
  Raven
    .config('https://' + config.sentry.public_key + '@sentry.io/' + config.sentry.project_id)
    .install();
  Raven.context(
    {
      release: __BUILD_NUMBER__,
      environment: __ENV__,
      tags: {
        commit: __COMMIT_HASH__,
      },
    },
    main
  );
} else {
  main();
}

@@ -142,24 +142,342 @@
 raven-js');%0A
+%0Afunction main() %7B%0A  // window.Intl polyfill%0A  // https://github.com/andyearnshaw/Intl.js/issues/118#issuecomment-120123392%0A  if (!window.Intl) %7B%0A    require.ensure(%5B'intl'%5D, (require) =%3E %7B%0A      window.Intl = require('intl');%0A      run();%0A    %7D, 'IntlPolyfillBundle');%0A  %7D else %7B%0A    run();%0A  %7D%0A%7D%0A%0Afunction run() %7B%0A  
 var React = 
@@ -490,24 +490,26 @@
 e('react');%0A
+  
 var ReactRou
@@ -539,16 +539,18 @@
 uter');%0A
+  
 var Reac
@@ -575,24 +575,26 @@
 act-dom');%0A%0A
+  
 var Router =
@@ -614,16 +614,18 @@
 Router,%0A
+  
   Route 
@@ -645,16 +645,18 @@
 .Route,%0A
+  
   IndexR
@@ -688,16 +688,18 @@
 oute,%0A  
+ 
+ 
 browserH
@@ -736,16 +736,18 @@
 story,%0A%0A
+  
   App = 
@@ -760,24 +760,26 @@
 e('./App'),%0A
+  
   Embed = re
@@ -796,16 +796,18 @@
 mbed'),%0A
+  
   Page =
@@ -833,16 +833,18 @@
 ge'),%0A  
+ 
+ 
 Home = r
@@ -866,16 +866,18 @@
 Home'),%0A
+  
   Login 
@@ -903,16 +903,18 @@
 ogin'),%0A
+  
   Servic
@@ -956,16 +956,18 @@
 atus'),%0A
+  
   VotePa
@@ -1001,16 +1001,18 @@
 ge'),%0A  
+ 
+ 
 EmbedVot
@@ -1065,16 +1065,18 @@
 Page'),%0A
+  
   Ballot
@@ -1111,16 +1111,18 @@
 Box'),%0A%0A
+  
   RouteA
@@ -1159,24 +1159,26 @@
 eAction');%0A%0A
+  
 var messages
@@ -1241,323 +1241,8 @@
 );%0A%0A
-function main() %7B%0A  // window.Intl polyfill%0A  // https://github.com/andyearnshaw/Intl.js/issues/118#issuecomment-120123392%0A  if (!window.Intl) %7B%0A    require.ensure(%5B'intl'%5D, (require) =%3E %7B%0A      window.Intl = require('intl');%0A      run();%0A    %7D, 'IntlPolyfillBundle');%0A  %7D else %7B%0A    run();%0A  %7D%0A%7D%0A%0Afunction run() %7B%0A
   br

Fix the window.Intl polyfill init.