import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import React from "react";
import NLPAnnotator from "react-nlp-annotate";
export var TextClassification = function TextClassification(_ref) {
  var sample = _ref.sample,
      iface = _ref.interface,
      onExit = _ref.onExit,
      sampleIndex = _ref.sampleIndex,
      onModifySample = _ref.onModifySample,
      disableHotkeys = _ref.disableHotkeys;

  var _ref2 = sample || {},
      _ref2$annotation = _ref2.annotation,
      annotation = _ref2$annotation === void 0 ? null : _ref2$annotation;

  var initialLabels = annotation ? typeof annotation === "string" ? [annotation] : annotation : undefined;

  if (!iface.labels) {
    throw new Error("Labels not defined. Try defining some labels in Setup");
  }

  var labels = iface.labels.map(function (l) {
    return typeof l === "string" ? {
      id: l,
      description: l,
      displayName: l
    } : l;
  }).map(function (l) {
    return !l.displayName ? _objectSpread(_objectSpread({}, l), {}, {
      displayName: l.id
    }) : l;
  });
  return /*#__PURE__*/React.createElement(NLPAnnotator, {
    key: sampleIndex,
    type: "label-document",
    labels: labels,
    multipleLabels: iface === null || iface === void 0 ? void 0 : iface.multiple,
    separatorRegex: iface === null || iface === void 0 ? void 0 : iface.wordSplitRegex,
    document: sample === null || sample === void 0 ? void 0 : sample.document,
    initialLabels: initialLabels,
    hotkeysEnabled: !disableHotkeys,
    onPrev: function onPrev(result) {
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: result
      }));
      onExit("go-to-previous");
    },
    onNext: function onNext(result) {
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: result
      }));
      onExit("go-to-next");
    },
    onFinish: function onFinish(result) {
      onModifySample(_objectSpread(_objectSpread({}, sample), {}, {
        annotation: result
      }));
      onExit();
    }
  });
};
export default TextClassification;