"use strict";

exports.__esModule = true;
exports.default = exports.TreeContext = exports.RootNode = exports.Node = exports.LeafNode = 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(e) { return e && e.__esModule ? e : { default: e }; }
(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() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
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 = exports.TreeContext = _react.default.createContext();
var LeafNode = exports.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))));
  }));
};
LeafNode.displayName = "LeafNode";
var RootNode = exports.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));
  })));
};
RootNode.displayName = "RootNode";
var _Node = exports.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);
  });
};
_Node.displayName = "Node";
var _default = _Node;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(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);
})();