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 { simpleSequenceToEntitySequence, entitySequenceToSimpleSeq } from "./convert-react-nlp-annotate-types";
export var TextEntityRecognition = function TextEntityRecognition(_ref) {
  var sample = _ref.sample,
      iface = _ref.interface,
      onModifySample = _ref.onModifySample,
      disableHotkeys = _ref.disableHotkeys,
      sampleIndex = _ref.sampleIndex,
      onExit = _ref.onExit;
  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.entities) : null;

  if (!(iface === null || iface === void 0 ? void 0 : iface.labels)) {
    throw new Error("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-sequence",
    separatorRegex: iface === null || iface === void 0 ? void 0 : iface.wordSplitRegex,
    document: sample === null || sample === void 0 ? void 0 : sample.document,
    labels: iface === null || iface === void 0 ? void 0 : iface.labels,
    initialSequence: initialSequence,
    hotkeysEnabled: !disableHotkeys,
    onPrev: function onPrev(result) {
      var annotation = {
        entities: simpleSequenceToEntitySequence(result)
      };
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: annotation
      }));
      onExit("go-to-previous");
    },
    onNext: function onNext(result) {
      var annotation = {
        entities: simpleSequenceToEntitySequence(result)
      };
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: annotation
      }));
      onExit("go-to-next");
    },
    onFinish: function onFinish(result) {
      var annotation = {
        entities: simpleSequenceToEntitySequence(result)
      };
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: annotation
      }));
      onExit();
    }
  });
};
export default TextEntityRecognition;