"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 DecisionRules = function DecisionRules(_ref) {
  var context = _ref.context,
      decisionRules = _ref.decisionRules;

  var displayConditions = function displayConditions(key, index) {
    var decisionRule = _craftAi.interpreter.reduceDecisionRules(decisionRules[key]); // Add the type to format properly the decision rule


    decisionRule[0].type = context[key].type;

    var text = _craftAi.interpreter.formatDecisionRules(decisionRule).replace(/ /g, "\xA0");

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

    return _react.default.createElement("tr", {
      key: key
    }, _react.default.createElement("td", null, _react.default.createElement("code", null, key)), _react.default.createElement("td", null, text));
  };

  var decisionRulesKeys = decisionRules ? Object.keys(decisionRules) : [];
  return _react.default.createElement("div", {
    className: "node-decision-rules"
  }, _react.default.createElement(_utils.H3NodeInformation, null, "Decision rules"), !decisionRulesKeys.length ? _react.default.createElement(_utils.TextCenterDiv, null, "N/A (root node)") : _react.default.createElement(_utils.TableNodeInformation, null, _react.default.createElement("tbody", null, decisionRulesKeys.map(displayConditions))));
};

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