import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import React from "react";
import NLPAnnotator from "react-nlp-annotate";
import Box from "@material-ui/core/Box";
import { simpleSequenceAndRelationsToEntitySequence, entitySequenceToSimpleSeq } from "../TextEntityRecognition/convert-react-nlp-annotate-types";
export var TextEntityRelations = function TextEntityRelations(_ref) {
  var _sample$annotation, _sample$annotation2;

  var sample = _ref.sample,
      iface = _ref.interface,
      onExit = _ref.onExit,
      onModifySample = _ref.onModifySample,
      disableHotkeys = _ref.disableHotkeys,
      sampleIndex = _ref.sampleIndex;
  var initialSequence = (sample === null || sample === void 0 ? void 0 : sample.annotation) ? entitySequenceToSimpleSeq(sample === null || sample === void 0 ? void 0 : sample.document, sample === null || sample === void 0 ? void 0 : (_sample$annotation = sample.annotation) === null || _sample$annotation === void 0 ? void 0 : _sample$annotation.entities) : undefined;
  var initialRelations = (sample === null || sample === void 0 ? void 0 : (_sample$annotation2 = sample.annotation) === null || _sample$annotation2 === void 0 ? void 0 : _sample$annotation2.relations) || [];

  if (!(iface === null || iface === void 0 ? void 0 : iface.relationLabels)) {
    throw new Error("Relation labels not defined. Try adding some labels in setup.");
  }

  return /*#__PURE__*/React.createElement(NLPAnnotator, {
    key: sampleIndex,
    titleContent: /*#__PURE__*/React.createElement(Box, {
      paddingLeft: 4
    }, "Sample ", sampleIndex),
    type: "label-relationships",
    separatorRegex: iface === null || iface === void 0 ? void 0 : iface.wordSplitRegex,
    document: sample === null || sample === void 0 ? void 0 : sample.document,
    entityLabels: iface === null || iface === void 0 ? void 0 : iface.entityLabels,
    relationshipLabels: iface === null || iface === void 0 ? void 0 : iface.relationLabels,
    initialSequence: initialSequence,
    initialRelationships: initialRelations,
    hotkeysEnabled: !disableHotkeys,
    onPrev: function onPrev(result) {
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: simpleSequenceAndRelationsToEntitySequence(result)
      }));
      onExit("go-to-previous");
    },
    onNext: function onNext(result) {
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: simpleSequenceAndRelationsToEntitySequence(result)
      }));
      onExit("go-to-next");
    },
    onFinish: function onFinish(result) {
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: simpleSequenceAndRelationsToEntitySequence(result)
      }));
      onExit();
    }
  });
};
export default TextEntityRelations;