"use strict";

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

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

var _decisionRules = _interopRequireDefault(require("./decisionRules"));

var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");

var _reactFontawesome = require("@fortawesome/react-fontawesome");

var _prediction = _interopRequireDefault(require("./prediction"));

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

var _split = _interopRequireDefault(require("./split"));

var _statistics = _interopRequireDefault(require("./statistics"));

var _reactEmotion = _interopRequireDefault(require("react-emotion"));

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 }; }

var NodeInformationContainer =
/*#__PURE__*/
(0, _reactEmotion.default)('div', {
  target: "e10b6ant0"
})("height:100%;", function (_ref) {
  var width = _ref.width;
  return width ? "width: ".concat(width) : '';
}, " display:flex;flex-direction:column;float:left;z-index:586;padding:10px;position:relative;background-color:white;border-right:solid 1px;overflow-y:auto;");
var InformationContainer =
/*#__PURE__*/
(0, _reactEmotion.default)('div', {
  target: "e10b6ant1"
})("flex:1 1 auto;");
var CloseButton =
/*#__PURE__*/
(0, _reactEmotion.default)('button', {
  target: "e10b6ant2"
})("cursor:pointer;border:none;outline:none;");
var CloseButtonDiv =
/*#__PURE__*/
(0, _reactEmotion.default)('div', {
  target: "e10b6ant3"
})("display:flex;justify-content:flex-end;margin-bottom:10px;");

var NodeInformation = function NodeInformation(_ref2) {
  var closeNodeInformation = _ref2.closeNodeInformation,
      selectedNodePath = _ref2.selectedNodePath,
      style = _ref2.style,
      tree = _ref2.tree,
      width = _ref2.width;
  var interpreter = (0, _react.useMemo)(function () {
    return (0, _interpreter.default)(tree, Object.keys(tree.trees)[0]);
  }, [tree]);

  if (selectedNodePath) {
    var _interpreter$findNode = interpreter.findNode(selectedNodePath),
        dtNode = _interpreter$findNode.dtNode,
        decisionRules = _interpreter$findNode.decisionRules;

    var _interpreter$getPredi = interpreter.getPrediction(interpreter.dt),
        distribution = _interpreter$getPredi.distribution;

    var _ref3 = distribution || {
      min: undefined,
      max: undefined
    },
        min = _ref3.min,
        max = _ref3.max;

    return _react.default.createElement(NodeInformationContainer, {
      className: "node-informations",
      style: style
    }, _react.default.createElement(InformationContainer, null, closeNodeInformation ? _react.default.createElement(CloseButtonDiv, null, _react.default.createElement(CloseButton, {
      onClick: closeNodeInformation
    }, _react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
      icon: _freeSolidSvgIcons.faTimes
    }))) : null, _react.default.createElement(_prediction.default, {
      dtNode: dtNode,
      interpreter: interpreter
    }), _react.default.createElement(_decisionRules.default, {
      context: tree.configuration.context,
      decisionRules: decisionRules
    }), _react.default.createElement(_split.default, {
      context: tree.configuration.context,
      dtNode: dtNode
    }), _react.default.createElement(_statistics.default, {
      dtNode: dtNode,
      totalMin: min,
      totalMax: max,
      interpreter: interpreter,
      outputValues: interpreter.dt.output_values
    })));
  } else {
    return _react.default.createElement("div", {
      className: "node-informations"
    });
  }
};

NodeInformation.defaultProps = {
  style: {}
};
NodeInformation.propTypes = {
  closeNodeInformation: _propTypes.default.func,
  tree: _propTypes.default.object.isRequired,
  selectedNodePath: _propTypes.default.string.isRequired,
  width: _propTypes.default.number,
  style: _propTypes.default.object
};
var _default = NodeInformation;
exports.default = _default;