text: /*
   * Licensed to Elasticsearch B.V. under one or more contributor
   * license agreements. See the NOTICE file distributed with
   * this work for additional information regarding copyright
   * ownership. Elasticsearch B.V. licenses this file to you under
   * the Apache License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  
  require('./main.scss');
  
  import '@babel/polyfill';
  import React from 'react';
  import ReactDOM from 'react-dom';
  import { Provider } from 'react-redux';
  import {
    Router,
    hashHistory,
  } from 'react-router';
  
  // Store.
  import configureStore from './store/configure_store';
  
  // Guide views.
  import AppContainer from './views/app_container';
  import { HomeView } from './views/home/home_view';
  import { NotFoundView } from './views/not_found/not_found_view';
  
  import {
    Routes,
  } from './services';
  
  const store = configureStore();
  
  const childRoutes = [].concat(Routes.getAppRoutes());
  childRoutes.push({
    path: '*',
    component: NotFoundView,
    name: 'Page Not Found',
  });
  
  const routes = [{
    path: '/',
    component: AppContainer,
    indexRoute: {
      component: HomeView,
      source: 'views/home/HomeView',
    },
    childRoutes,
  }];
  
  // Update document title with route name.
  const onRouteEnter = route => {
    const leafRoute = route.routes[route.routes.length - 1];
    document.title = leafRoute.name ?
      `Kibana UI Framework - ${leafRoute.name}` :
      'Kibana UI Framework';
  };
  
  const syncTitleWithRoutes = routesList => {
    if (!routesList) return;
    routesList.forEach(route => {
      route.onEnter = onRouteEnter; // eslint-disable-line no-param-reassign
      if (route.indexRoute) {
        // Index routes have a weird relationship with their "parent" routes,
        // so it seems we need to give their own onEnter hooks.
        route.indexRoute.onEnter = onRouteEnter; // eslint-disable-line no-param-reassign
      }
      syncTitleWithRoutes(route.childRoutes);
    });
  };
  
  syncTitleWithRoutes(routes);
  
  ReactDOM.render(
    <Provider store={store}>
      <Router
        history={hashHistory}
        routes={routes}
      />
    </Provider>,
    document.getElementById('guide')
  );
  