"use strict";

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

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

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

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

var _constants = require("../utils/constants");

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

/* eslint-disable react/jsx-no-bind */
var EdgeLabelDiv =
/*#__PURE__*/
(0, _styled.default)('div', {
  target: "ehqhb5n0"
})("overflow:hidden;text-overflow:ellipsis;position:absolute;text-align:center;font-size:smaller;pointer-events:auto;width:", _constants.NODE_WIDTH, "px;top:", function (_ref) {
  var y = _ref.y;
  return y;
}, "px;left:", function (_ref2) {
  var x = _ref2.x;
  return x;
}, "px;");

var EdgeLabel = function EdgeLabel(_ref3) {
  var hLink = _ref3.hLink,
      configuration = _ref3.configuration,
      _ref3$onShowTooltip = _ref3.onShowTooltip,
      onShowTooltip = _ref3$onShowTooltip === void 0 ? function (ref, text) {} : _ref3$onShowTooltip,
      _ref3$onHideTooltip = _ref3.onHideTooltip,
      onHideTooltip = _ref3$onHideTooltip === void 0 ? function () {} : _ref3$onHideTooltip;
  var dtTargetNode = hLink.target.data;
  var edgeLabelRef = (0, _react.useRef)();
  var propertyType = configuration.context[dtTargetNode.decision_rule.property].type;

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

  return _react.default.createElement(EdgeLabelDiv, {
    ref: edgeLabelRef,
    onMouseOver: function onMouseOver() {
      return onShowTooltip(edgeLabelRef.current, text);
    },
    onMouseOut: onHideTooltip,
    className: "craft-links",
    x: hLink.target.x - _constants.NODE_WIDTH / 2,
    y: hLink.target.y - _constants.NODE_DEPTH * 2 / 5
  }, text);
};

EdgeLabel.propTypes = {
  hLink: _propTypes.default.object.isRequired,
  configuration: _propTypes.default.object.isRequired,
  onShowTooltip: _propTypes.default.func,
  onHideTooltip: _propTypes.default.func
};
var _default = EdgeLabel;
exports.default = _default;