"use strict";

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

var _craftAi = require("craft-ai");

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

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

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

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

var Split = function Split(_ref) {
  var context = _ref.context,
      dtNode = _ref.dtNode;

  var displaySplit = function displaySplit(child, key) {
    try {
      var propertyType = context[child.decision_rule.property].type;

      var text = _craftAi.interpreter.formatDecisionRules([{
        operand: child.decision_rule.operand,
        operator: child.decision_rule.operator,
        type: propertyType
      }]);

      if (key !== 0) {
        return _react.default.createElement("tr", {
          key: key
        }, _react.default.createElement(_utils.TdNodeInformation, null, _react.default.createElement("code", null, child.decision_rule.property)), _react.default.createElement(_utils.TdNodeInformation, null, text));
      }

      return _react.default.createElement("tr", {
        key: key
      }, _react.default.createElement("td", null, _react.default.createElement("code", null, child.decision_rule.property)), _react.default.createElement("td", null, text));
    } catch (err) {
      return _react.default.createElement("tr", {
        style: {
          color: 'red'
        },
        key: key
      }, _react.default.createElement("td", null, err.message));
    }
  };

  return _react.default.createElement("div", {
    className: "node-split"
  }, _react.default.createElement(_utils.H3NodeInformation, null, "Splits"), !dtNode.children ? _react.default.createElement(_utils.TextCenterDiv, null, "N/A (leaf node)") : _react.default.createElement(_utils.TableNodeInformation, null, _react.default.createElement("tbody", null, dtNode.children.map(displaySplit))));
};

Split.propTypes = {
  dtNode: _propTypes.default.object.isRequired,
  context: _propTypes.default.object.isRequired
};
var _default = Split;
exports.default = _default;