"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _interpreter = _interopRequireDefault(require("../utils/interpreter"));

var _decisionTreeContainer = _interopRequireDefault(require("./decisionTreeContainer"));

var _nodeInformation = _interopRequireDefault(require("./nodeInformation/nodeInformation"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _styled = _interopRequireDefault(require("@emotion/styled"));

var _tree = _interopRequireDefault(require("./tree"));

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var NodeInformationsOverlay =
/*#__PURE__*/
(0, _styled.default)('div', {
  target: "el87jhv0"
})("position:absolute;height:", function (_ref) {
  var height = _ref.height;
  return height;
}, "px;z-index:10;");

var DecisionTreeWithPanel = function DecisionTreeWithPanel(_ref2) {
  var scale = _ref2.scale,
      position = _ref2.position,
      data = _ref2.data,
      selectedNode = _ref2.selectedNode,
      updatePositionAndZoom = _ref2.updatePositionAndZoom,
      edgeType = _ref2.edgeType,
      foldedNodes = _ref2.foldedNodes,
      style = _ref2.style;

  var _useState = (0, _react.useState)(selectedNode),
      _useState2 = _slicedToArray(_useState, 2),
      selectedNodeState = _useState2[0],
      setSelectedNode = _useState2[1];

  (0, _react.useEffect)(function () {
    return setSelectedNode(selectedNode);
  }, [selectedNode]);
  var interpreter = (0, _react.useMemo)(function () {
    setSelectedNode(undefined);
    return (0, _interpreter.default)(data, Object.keys(data.trees)[0]);
  }, [data]);
  var closeNodeInformation = (0, _react.useCallback)(function () {
    setSelectedNode(undefined);
  }, []);
  return _react.default.createElement(_decisionTreeContainer.default, {
    style: style
  }, function (_ref3) {
    var height = _ref3.height,
        width = _ref3.width;
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(NodeInformationsOverlay, {
      height: height
    }, _react.default.createElement(_nodeInformation.default, {
      tree: data,
      selectedNodePath: selectedNodeState || '',
      closeNodeInformation: closeNodeInformation,
      width: 400
    })), _react.default.createElement(_tree.default, {
      interpreter: interpreter,
      updateSelectedNode: setSelectedNode,
      height: height,
      width: width,
      position: position,
      scale: scale,
      updatePositionAndZoom: updatePositionAndZoom,
      configuration: data.configuration,
      edgeType: edgeType,
      selectedNode: selectedNodeState,
      foldedNodes: foldedNodes
    }));
  });
};

DecisionTreeWithPanel.defaultProps = {
  position: [0, 0],
  scale: -1,
  updatePositionAndZoom: null,
  auto: false,
  edgeType: 'constant'
};
DecisionTreeWithPanel.propTypes = {
  scale: _propTypes.default.number,
  position: _propTypes.default.array,
  data: _propTypes.default.object.isRequired,
  updatePositionAndZoom: _propTypes.default.func,
  edgeType: _propTypes.default.string,
  selectedNode: _propTypes.default.string,
  foldedNodes: _propTypes.default.arrayOf(_propTypes.default.string),
  style: _propTypes.default.object
};
var _default = DecisionTreeWithPanel;
exports.default = _default;