"use strict";

exports.__esModule = true;
exports.default = exports.BaseScopeTreeView = void 0;
var _react = _interopRequireDefault(require("react"));
var _TreeView = _interopRequireDefault(require("@material-ui/lab/TreeView"));
var _TreeItem = _interopRequireDefault(require("./TreeItem"));
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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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 BaseScopeTreeView = exports.BaseScopeTreeView = function BaseScopeTreeView(_ref) {
  var rootId = _ref.rootId,
    getScope = _ref.getScope,
    onSelected = _ref.onSelected,
    _ref$initExpanded = _ref.initExpanded,
    initExpanded = _ref$initExpanded === void 0 ? [] : _ref$initExpanded,
    selected = _ref.selected,
    setSelected = _ref.setSelected,
    multipleSelect = _ref.multipleSelect,
    isScopeSelectable = _ref.isScopeSelectable;
  var _React$useState = _react.default.useState(initExpanded),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    expanded = _React$useState2[0],
    setExpanded = _React$useState2[1];
  var handleToggle = function handleToggle(_, nodeIds) {
    setExpanded(nodeIds);
  };
  var onScopeSelect = function onScopeSelect(event, nodeId) {
    var newSelected = !multipleSelect ? nodeId : selected.includes(nodeId) ? selected.filter(function (id) {
      return id !== nodeId;
    }) : [nodeId].concat(selected);
    setSelected(newSelected);
    onSelected(event, newSelected);
  };
  var _renderTree = function renderTree(scopeId) {
    var currentScope = getScope(scopeId);
    if (currentScope == null) return null;
    return /*#__PURE__*/_react.default.createElement(_TreeItem.default, {
      key: "ScopeSelector-".concat(currentScope.id),
      scope: currentScope,
      rootId: rootId,
      onScopeSelect: onScopeSelect,
      isScopeSelectable: isScopeSelectable
    }, currentScope.children.map(function (child) {
      return _renderTree(child);
    }));
  };
  return /*#__PURE__*/_react.default.createElement(_TreeView.default, {
    expanded: expanded,
    selected: selected,
    onNodeToggle: handleToggle
  }, _renderTree(rootId));
};
__signature__(BaseScopeTreeView, "useState{[expanded, setExpanded](initExpanded)}");
__signature__(BaseScopeTreeView, "useState{[expanded, setExpanded](initExpanded)}");
var ScopeTreeView = function ScopeTreeView(_ref2) {
  var rootId = _ref2.rootId,
    getScope = _ref2.getScope,
    selected = _ref2.selected,
    expanded = _ref2.expanded,
    onSelected = _ref2.onSelected,
    multipleSelect = _ref2.multipleSelect,
    isScopeSelectable = _ref2.isScopeSelectable;
  var initialSelected = Array.isArray(selected) ? selected : selected ? [selected] : [];
  var _React$useState3 = _react.default.useState(initialSelected),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    currentSelected = _React$useState4[0],
    setCurrentSelected = _React$useState4[1];
  return /*#__PURE__*/_react.default.createElement(BaseScopeTreeView, {
    rootId: rootId,
    getScope: getScope,
    onSelected: onSelected,
    initExpanded: expanded,
    selected: currentSelected,
    setSelected: setCurrentSelected,
    multipleSelect: multipleSelect,
    isScopeSelectable: isScopeSelectable
  });
};
__signature__(ScopeTreeView, "useState{[currentSelected, setCurrentSelected](initialSelected)}");
__signature__(ScopeTreeView, "useState{[currentSelected, setCurrentSelected](initialSelected)}");
var _default = ScopeTreeView;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(BaseScopeTreeView, "BaseScopeTreeView", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/ScopeTreeView.js");
  reactHotLoader.register(ScopeTreeView, "ScopeTreeView", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/ScopeTreeView.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/ScopeTreeView.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(BaseScopeTreeView, "BaseScopeTreeView", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/ScopeTreeView.js");
  reactHotLoader.register(ScopeTreeView, "ScopeTreeView", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/ScopeTreeView.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/ScopeTreeView.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();