(function (global, factory) {
	if (typeof define === "function" && define.amd) {
		define(['exports', 'react', 'classnames', './px-tree.scss', './px-tree-node', '../BaseComponent'], factory);
	} else if (typeof exports !== "undefined") {
		factory(exports, require('react'), require('classnames'), require('./px-tree.scss'), require('./px-tree-node'), require('../BaseComponent'));
	} else {
		var mod = {
			exports: {}
		};
		factory(mod.exports, global.react, global.classnames, global.pxTree, global.pxTreeNode, global.BaseComponent);
		global.index = mod.exports;
	}
})(this, function (exports, _react, _classnames, _pxTree, _pxTreeNode, _BaseComponent2) {
	'use strict';

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

	var _react2 = _interopRequireDefault(_react);

	var _classnames2 = _interopRequireDefault(_classnames);

	var _pxTree2 = _interopRequireDefault(_pxTree);

	var _pxTreeNode2 = _interopRequireDefault(_pxTreeNode);

	var _BaseComponent3 = _interopRequireDefault(_BaseComponent2);

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

	function _classCallCheck(instance, Constructor) {
		if (!(instance instanceof Constructor)) {
			throw new TypeError("Cannot call a class as a function");
		}
	}

	var _createClass = function () {
		function defineProperties(target, props) {
			for (var i = 0; i < props.length; i++) {
				var descriptor = props[i];
				descriptor.enumerable = descriptor.enumerable || false;
				descriptor.configurable = true;
				if ("value" in descriptor) descriptor.writable = true;
				Object.defineProperty(target, descriptor.key, descriptor);
			}
		}

		return function (Constructor, protoProps, staticProps) {
			if (protoProps) defineProperties(Constructor.prototype, protoProps);
			if (staticProps) defineProperties(Constructor, staticProps);
			return Constructor;
		};
	}();

	function _possibleConstructorReturn(self, call) {
		if (!self) {
			throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
		}

		return call && (typeof call === "object" || typeof call === "function") ? call : self;
	}

	function _inherits(subClass, superClass) {
		if (typeof superClass !== "function" && superClass !== null) {
			throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
		}

		subClass.prototype = Object.create(superClass && superClass.prototype, {
			constructor: {
				value: subClass,
				enumerable: false,
				writable: true,
				configurable: true
			}
		});
		if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
	}

	var Tree = function (_BaseComponent) {
		_inherits(Tree, _BaseComponent);

		function Tree(props) {
			_classCallCheck(this, Tree);

			var _this = _possibleConstructorReturn(this, (Tree.__proto__ || Object.getPrototypeOf(Tree)).call(this, props, { displayName: 'Tree' }));

			_this.state = {
				selectedNode: null
			};
			_this.onSelect = _this.onSelect.bind(_this);
			return _this;
		}

		_createClass(Tree, [{
			key: 'onSelect',
			value: function onSelect(node) {
				if (this.state.selected) {
					this.state.selected.setState({ selected: false });
				}
				this.setState({ selected: node });
				node.setState({ selected: true });
				if (this.props.onSelect) {}
				this._log('onSelect', node);
			}
		}, {
			key: 'render',
			value: function render() {
				var _props = this.props,
				    style = _props.style,
				    items = _props.items,
				    children = _props.children;
				var selectedNode = this.state.selectedNode;

				var baseClasses = (0, _classnames2.default)('px-tree');
				var _items = items.length ? items : [items];

				return _react2.default.createElement(
					'div',
					{ className: baseClasses, style: style },
					_react2.default.createElement(_pxTreeNode2.default, { data: items, onCategorySelect: this.onSelect }),
					_react2.default.createElement(
						'style',
						null,
						'' + _pxTree2.default
					)
				);
			}
		}]);

		return Tree;
	}(_BaseComponent3.default);

	exports.default = Tree;
});