/*globals require,module */
/* jshint -W097,esnext: true */

"use strict";

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var React = require("react");

var NavGroup = require("./NavGroup");
var Nav = require("./Nav");

/**
 * The SideNav is a Side Navigation component duH!
 *
 * navs = [
 *     { title: "Main Group" , navlist: [
 *          { title: "Nav 1" }
 *       ]
 *     }
 * ]
 * @type {*|Function}
 */
var SideNav = React.createClass({
    displayName: "SideNav",

    getInitialState: function getInitialState() {
        return { selected: { id: this.props.selectedId } };
    },

    buildFromSettings: function buildFromSettings() {
        var _this = this;
        var words = (this.props.words) ? this.props.words : {};
        return this.props.navs.map(function (navkind) {
            //nav kind could have a navlist, which we assume it contains a group of navs options
            if(navkind.active === false){
                return;
            }

            if (navkind.navlist) {
                var selected = {
                    id    : _this.state.selected.id,
                    group : navkind.id
                };
                return React.createElement(
                    NavGroup,
                    { key : navkind.id, id : navkind.id, selectedId : _this.state.selected.id, selected: selected, onClick: _this.onSubNavClick, anotherAction : _this.onClick, nav: navkind, words : words }
                );
            } else {
                return React.createElement(
                    Nav,
                    _extends( {key : navkind.id}, {id : navkind.id}, {selectedId : _this.state.selected.id}, {selected: _this.state.selected }, navkind, { onClick: _this.onClick }, {group : navkind.id}, {words : words})
                );
            }
        });
    },

    onSubNavClick: function onSubNavClick(group, child, options) {
        if(this.props.selectedId){
            delete(this.props.selectedId);
        }
        var selection = { group: group, id: child, options : options};
        this.setState({ selected: selection });
        this.dispatchSelection(selection);
    },

    onClick: function onClick(id, options) {
        if(this.props.selectedId){
            delete(this.props.selectedId);
        }
        var selection = { id: id, options : options };
        this.setState({ selected: selection });
        this.dispatchSelection(selection);
    },

    dispatchSelection: function dispatchSelection(selection) {
        if (this.props.onSelection) {
            this.props.onSelection(selection);
        }
    },

    buildChildren: function buildChildren() {

        if (this.props.navs) {
            return this.buildFromSettings();
        } else {
            return this.props.children;
        }
    },

    render: function render() {
        return React.createElement(
            "div",
            { style: { width: "100%" } },
            this.buildChildren()
        );
    }

});

module.exports = SideNav;

@@ -2028,131 +2028,144 @@
     
-onSubNavClick: function onSubNavClick(group, child, options) %7B%0A        if(this.props.selectedId)%7B%0A            d
+componentWillReceiveProps : function(nextProps) %7B%0A        if(nextProps !== undefined) %7B%0A            this.setState(%7Bs
 ele
+c
 te
-(this.p
+d: %7B id: nextP
 rops
@@ -2167,32 +2167,35 @@
 Props.selectedId
+ %7D%7D
 );%0A        %7D%0A   
@@ -2183,32 +2183,107 @@
  %7D%7D);%0A        %7D%0A
+    %7D,%0A%0A    onSubNavClick: function onSubNavClick(group, child, options) %7B%0A
         var sele
@@ -2485,96 +2485,8 @@
 ) %7B%0A
-        if(this.props.selectedId)%7B%0A            delete(this.props.selectedId);%0A        %7D%0A
     

add componentWillReceiveProps