'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _Icon = require('../Icon');

var _Icon2 = _interopRequireDefault(_Icon);

var _style = require('./style.scss');

var _style2 = _interopRequireDefault(_style);

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

var Node = function Node(props) {
  var childnodes = null;
  var iconParent = props.node.icon ? props.node.icon : null;

  if (props.children) {
    childnodes = props.children.map(function (childnode, index) {
      return _react2.default.createElement(Node, { node: childnode, children: childnode.nav, key: index });
    });
  }

  return _react2.default.createElement(
    'li',
    null,
    props.node.external ? _react2.default.createElement(
      'div',
      null,
      _react2.default.createElement(
        'a',
        { href: props.node.route, target: '_blank' },
        iconParent ? _react2.default.createElement(_Icon2.default, { name: iconParent, fill: 'currentColor' }) : null,
        props.node.name
      ),
      childnodes ? _react2.default.createElement(
        'ul',
        { className: iconParent ? _style2.default.indent : null },
        childnodes
      ) : null
    ) : _react2.default.createElement(
      'div',
      null,
      _react2.default.createElement(
        _reactRouter.Link,
        { to: props.node.route, activeClassName: _style2.default.active },
        iconParent ? _react2.default.createElement(_Icon2.default, { name: iconParent, fill: 'currentColor' }) : null,
        props.node.name
      ),
      childnodes ? _react2.default.createElement(
        'ul',
        { className: iconParent ? _style2.default.indent : null },
        childnodes
      ) : null
    )
  );
};

exports.default = Node;