import React from "react";
import { DataTable } from "teselagen-react-components";
import { CutsiteTag } from "../../CutsiteFilter/AdditionalCutsiteInfoDialog";
import EnzymeViewer from "../../EnzymeViewer";
import { getEnzymeAliases } from "../../utils/editorUtils";
export default function SingleEnzymeCutsiteInfo(_ref) {
  var cutsiteGroup = _ref.cutsiteGroup,
    enzyme = _ref.enzyme,
    dispatch = _ref.dispatch,
    allRestrictionEnzymes = _ref.allRestrictionEnzymes,
    editorName = _ref.editorName,
    selectedAnnotationId = _ref.selectedAnnotationId,
    allCutsites = _ref.allCutsites,
    cutsitesByNameActive = _ref.filteredCutsites.cutsitesByName;
  var onRowSelect = function onRowSelect(_ref2) {
    var record = _ref2[0];
    if (!record) return;
    dispatch({
      type: "CARET_POSITION_UPDATE",
      payload: record.topSnipPosition,
      meta: {
        editorName: editorName
      }
    });
  };
  var aliases = getEnzymeAliases(enzyme);
  var entities = cutsiteGroup.sort(function (a, b) {
    return a.topSnipPosition - b.topSnipPosition;
  }).map(function (_ref3) {
    var _ref3$restrictionEnzy = _ref3.restrictionEnzyme;
    _ref3$restrictionEnzy = _ref3$restrictionEnzy === void 0 ? {} : _ref3$restrictionEnzy;
    var forwardRegex = _ref3$restrictionEnzy.forwardRegex,
      reverseRegex = _ref3$restrictionEnzy.reverseRegex,
      forward = _ref3.forward,
      id = _ref3.id,
      topSnipBeforeBottom = _ref3.topSnipBeforeBottom,
      topSnipPosition = _ref3.topSnipPosition,
      bottomSnipPosition = _ref3.bottomSnipPosition;
    return {
      id: id,
      topSnipPosition: topSnipPosition,
      position: topSnipBeforeBottom ? topSnipPosition + " - " + bottomSnipPosition : bottomSnipPosition + " - " + topSnipPosition,
      strand: forwardRegex === reverseRegex ? "Palindromic" : forward ? "1" : "-1"
    };
  });
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: "ve-enzymeSubrow",
    style: {
      margin: 10
    }
  }, enzyme && /*#__PURE__*/React.createElement(EnzymeViewer, {
    sequence: enzyme.site,
    reverseSnipPosition: enzyme.bottomSnipOffset,
    forwardSnipPosition: enzyme.topSnipOffset
  }), /*#__PURE__*/React.createElement("br", null), entities && !!entities.length && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(DataTable, {
    style: {
      minHeight: 0,
      maxHeight: 200
    },
    selectedIds: selectedAnnotationId,
    maxHeight: 300,
    onRowSelect: onRowSelect,
    formName: "cutLocations",
    isSingleSelect: true,
    compact: true,
    noRouter: true,
    minimalStyle: true,
    scrollToSelectedRowRelativeToDom: true,
    noHeader: true,
    isSimple: true,
    noFullscreenButton: true,
    isInfinite: true,
    withSearch: false,
    withFilter: false,
    schema: schema,
    entities: entities
  })), aliases && aliases.length && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 10
    }
  }, "\u522B\u540D:", /*#__PURE__*/React.createElement("div", {
    style: {
      display: "flex",
      flexWrap: "wrap"
    }
  }, aliases.map(function (n, i) {
    return /*#__PURE__*/React.createElement(CutsiteTag, {
      allRestrictionEnzymes: allRestrictionEnzymes,
      cutsitesByNameActive: cutsitesByNameActive,
      cutsitesByName: allCutsites.cutsitesByName,
      key: i,
      name: n,
      doNotShowCuts: true
    });
  })))));
}
var schema = {
  fields: [{
    path: "topSnipPosition",
    displayName: "正（上）链切口",
    type: "string"
  }, {
    path: "position",
    type: "string",
    displayName: "位置"
  }, {
    path: "strand",
    type: "string",
    displayName: "位于正/负链"
  }]
};

// export default compose(
//   withEditorProps,
//   withRestrictionEnzymes
// )(SingleEnzymeCutsiteInfo);