import {createRoutesFromReactChildren} from 'react-router';
import React from 'react';

import Util from './Util';

const RouterUtil = {

  /**
   * Creates a tree of React components for an array of route configurations
   *
   * @param  {Array} routes
   * @return {Array} React tree of routes
   */
  createComponentsFromRoutes(routes) {
    return routes.map(function (route) {
      let args = [route.type, Util.omit(route, ['type', 'children'])];

      if (route.children) {
        let children = RouterUtil.createComponentsFromRoutes(route.children);
        args = args.concat(children);
      }

      return React.createElement(...args);
    });
  },

  /**
   * Sets missing configuration properties to the routes that are generated by
   * react router. This is needed because react router will strip those out.¡
   *
   * @param  {Array} routes of Route instances
   * @param  {Array} originalRoutes of original route configuration
   * @return {Array} Modified routes with original configuration
   */
  setRouteConfiguration(routes, originalRoutes) {
    return routes.map(function (route, index) {
      let originalConfiguration = originalRoutes[index];

      if (!originalConfiguration) {
        return route;
      }

      if (route.childRoutes && originalConfiguration.children) {
        route.childRoutes = RouterUtil.setRouteConfiguration(
          route.childRoutes, originalConfiguration.children
        );
      }

      if (originalConfiguration.buildBreadCrumb) {
        route.buildBreadCrumb = originalConfiguration.buildBreadCrumb;
      }

      return route;
    });
  },

  /**
   * Builds a route array that react router can use,
   * with the correct configuration.
   *
   * @param  {Array} originalRoutes Original Route configuration
   * @return {Array} Routes ready to use by react router
   */
  buildRoutes(originalRoutes) {
    let elementRoutes = RouterUtil.createComponentsFromRoutes(originalRoutes);
    let routes = createRoutesFromReactChildren(elementRoutes[0]);

    return RouterUtil.setRouteConfiguration(routes, originalRoutes);
  }

};

module.exports = RouterUtil;

@@ -1451,49 +1451,182 @@
     
-if (originalConfiguration.buildBreadCrumb
+// Transfer any property that is not already present on route,%0A      // but available in originalConfiguration%0A      Object.keys(originalConfiguration).forEach(function (prop
 ) %7B%0A
@@ -1637,29 +1637,64 @@
     
+if (!
 route.
-buildBreadCrumb
+hasOwnProperty(prop)) %7B%0A          route%5Bprop%5D
  = o
@@ -1717,32 +1717,22 @@
 tion
-.buildBreadCrumb
+%5Bprop%5D
 ;%0A      
 %7D%0A%0A 
@@ -1719,33 +1719,45 @@
 on%5Bprop%5D;%0A      
+ 
-%7D
+ %7D%0A      %7D);
 %0A%0A      return r

Make routes take any property, that is not already present