"use strict";

exports.__esModule = true;
exports.default = exports.Node = exports.RootNode = exports.LeafNode = exports.TreeContext = void 0;

var _react = _interopRequireDefault(require("react"));

var _Branch = require("./Branch");

var _Leaf = require("./Leaf");

var _Label = require("./Label");

var _utils = require("../../utils");

var _excluded = ["dark", "isSelectedNode"],
    _excluded2 = ["isSelectedNode"];

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

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

function _extends() { _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; }; return _extends.apply(this, arguments); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var TreeContext = _react.default.createContext();

exports.TreeContext = TreeContext;

var LeafNode = function LeafNode(_ref) {
  var dark = _ref.dark,
      isSelectedNode = _ref.isSelectedNode,
      nodeData = _objectWithoutProperties(_ref, _excluded);

  return /*#__PURE__*/_react.default.createElement(_Leaf.Leaf, {
    dark: dark
  }, /*#__PURE__*/_react.default.createElement(TreeContext.Consumer, null, function (_ref2) {
    var Content = _ref2.Content,
        nodeState = _ref2.nodeState,
        updateNodeState = _ref2.updateNodeState,
        dark = _ref2.dark,
        otherProps = _ref2.otherProps;

    var toggle = function toggle() {
      return updateNodeState(_objectSpread(_objectSpread({}, nodeState), {}, _defineProperty({}, nodeData.id, !nodeData.open)));
    };

    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (0, _utils.safeGet)(nodeData, "children", "length") ? [/*#__PURE__*/_react.default.createElement(_Label.BeforeIndicator, {
      key: "a"
    }), /*#__PURE__*/_react.default.createElement(_Label.Indicator, {
      key: "b",
      open: nodeData.open,
      onClick: toggle,
      dark: dark
    })] : /*#__PURE__*/_react.default.createElement(_Label.NonIndicator, null), /*#__PURE__*/_react.default.createElement(_Label.Label, {
      isSelectedNode: isSelectedNode
    }, /*#__PURE__*/_react.default.createElement(Content, _extends({}, (0, _utils.stripKey)("children", nodeData), otherProps))));
  }));
};

exports.LeafNode = LeafNode;
LeafNode.displayName = "LeafNode";

var RootNode = function RootNode(_ref3) {
  var isSelectedNode = _ref3.isSelectedNode,
      nodeData = _objectWithoutProperties(_ref3, _excluded2);

  return /*#__PURE__*/_react.default.createElement(_Leaf.Root, null, /*#__PURE__*/_react.default.createElement(_Label.Label, {
    isSelectedNode: isSelectedNode
  }, /*#__PURE__*/_react.default.createElement(TreeContext.Consumer, null, function (_ref4) {
    var Content = _ref4.Content,
        otherProps = _ref4.otherProps;
    return /*#__PURE__*/_react.default.createElement(Content, _extends({}, (0, _utils.stripKey)("children", nodeData), otherProps));
  })));
};

exports.RootNode = RootNode;
RootNode.displayName = "RootNode";

var Node = function Node(_ref5) {
  var root = _ref5.root,
      id = _ref5.id;
  return /*#__PURE__*/_react.default.createElement(TreeContext.Consumer, null, function (_ref6) {
    var openAll = _ref6.openAll,
        getNode = _ref6.getNode,
        selectedNodeId = _ref6.selectedNodeId,
        nodeState = _ref6.nodeState,
        dark = _ref6.dark;
    var nodeData = getNode(id);
    if (!nodeData) return null;
    var isSelectedNode = selectedNodeId === id;
    var open = root || openAll || nodeState[id] || false;
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, root ? /*#__PURE__*/_react.default.createElement(RootNode, _extends({}, nodeData, {
      isSelectedNode: isSelectedNode
    })) : /*#__PURE__*/_react.default.createElement(LeafNode, _extends({}, nodeData, {
      open: open,
      dark: dark,
      isSelectedNode: isSelectedNode
    })), open && (0, _utils.safeGet)(nodeData, "children", "length") ? /*#__PURE__*/_react.default.createElement(_Branch.Branch, {
      dark: dark
    }, nodeData.children.map(function (id) {
      return /*#__PURE__*/_react.default.createElement(Node, {
        key: id,
        id: id
      });
    })) : null);
  });
};

exports.Node = Node;
Node.displayName = "Node";
var _default = Node;
var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(TreeContext, "TreeContext", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(LeafNode, "LeafNode", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(RootNode, "RootNode", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(Node, "Node", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(TreeContext, "TreeContext", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(LeafNode, "LeafNode", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(RootNode, "RootNode", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(Node, "Node", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/Treeview/Node.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();