function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React from "react";
import { DataTable, withSelectedEntities, createCommandMenu } from "teselagen-react-components";
import { map, get } from "lodash";
import CutsiteFilter from "../../CutsiteFilter";
import { Button, ButtonGroup } from "@blueprintjs/core";
import { connectToEditor } from "../../withEditorProps";
import { compose } from "recompose";
import selectors from "../../selectors";
import commands from "../../commands";
import { userDefinedHandlersAndOpts } from "../../Editor/userDefinedHandlersAndOpts";
import { pick } from "lodash";
import SingleEnzymeCutsiteInfo from "./SingleEnzymeCutsiteInfo";
import { withRestrictionEnzymes } from "../../CutsiteFilter/withRestrictionEnzymes";
import { cutsitesSubmenu } from "../../MenuBar/viewSubmenu";
import { getVisFilter } from "./GenericAnnotationProperties";
var CutsiteProperties = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(CutsiteProperties, _React$Component);
  function CutsiteProperties(props) {
    var _this;
    _this = _React$Component.call(this, props) || this;
    _defineProperty(_assertThisInitialized(_this), "SubComponent", function (row) {
      return /*#__PURE__*/React.createElement(SingleEnzymeCutsiteInfo, {
        allRestrictionEnzymes: _this.props.allRestrictionEnzymes,
        allCutsites: _this.props.allCutsites,
        filteredCutsites: _this.props.filteredCutsites,
        editorName: _this.props.editorName,
        dispatch: _this.props.dispatch,
        selectedAnnotationId: _this.props.selectedAnnotationId,
        cutsiteGroup: row.original.cutsiteGroup,
        enzyme: row.original.enzyme
      });
    });
    _defineProperty(_assertThisInitialized(_this), "schema", {
      fields: [{
        path: "name",
        type: "string",
        displayName: "名称"
      }, {
        path: "numberOfCuts",
        type: "number"
      }, {
        path: "groups",
        type: "string",
        displayName: "分组"
      }]
    });
    _defineProperty(_assertThisInitialized(_this), "onChangeHook", function () {
      _this.props.annotationVisibilityShow("cutsites");
    });
    _this.commands = commands(_assertThisInitialized(_this));
    return _this;
  }
  var _proto = CutsiteProperties.prototype;
  _proto.render = function render() {
    var _this$props = this.props,
      editorName = _this$props.editorName,
      createNewDigest = _this$props.createNewDigest,
      allCutsites = _this$props.filteredCutsites,
      selectedAnnotationId = _this$props.selectedAnnotationId;
    var cutsitesByName = allCutsites.cutsitesByName,
      cutsitesById = allCutsites.cutsitesById;
    var cutsitesToUse = map(cutsitesByName, function (cutsiteGroup) {
      var name = cutsiteGroup[0].restrictionEnzyme.name;
      var groups = "";
      var exisitingEnzymeGroups = window.getExistingEnzymeGroups();
      Object.keys(exisitingEnzymeGroups).forEach(function (key) {
        if (exisitingEnzymeGroups[key].includes(name)) groups += key;
        groups += " ";
      });
      return {
        cutsiteGroup: cutsiteGroup,
        id: name,
        name: name,
        numberOfCuts: cutsiteGroup.length,
        enzyme: cutsiteGroup[0].restrictionEnzyme,
        groups: groups
        // size: getRangeLength(cutsiteGroup, sequenceData.sequence.length)
      };
    });

    return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 10,
        paddingTop: 3,
        display: "flex",
        // flexWrap: 'wrap',
        width: "100%",
        // justifyContent: "space-between",
        alignItems: "center"
      }
    }, getVisFilter(createCommandMenu(cutsitesSubmenu, this.commands, {
      useTicks: true
    })), /*#__PURE__*/React.createElement(ButtonGroup, null, /*#__PURE__*/React.createElement(Button, {
      intent: "success",
      "data-tip": "Virtual Digest",
      icon: "cut",
      style: {
        marginLeft: 15,
        flexGrow: -1
      },
      onClick: function onClick() {
        createNewDigest();
      }
    })), /*#__PURE__*/React.createElement(CutsiteFilter, _extends({}, pick(this.props, userDefinedHandlersAndOpts), {
      style: {
        marginLeft: "auto",
        marginRight: 3
      },
      editorName: editorName,
      manageEnzymesToLeft: true,
      onChangeHook: this.onChangeHook
    }))), /*#__PURE__*/React.createElement(DataTable, {
      selectedIds: get(cutsitesById[selectedAnnotationId], "restrictionEnzyme.name"),
      compact: true,
      noSelect: true,
      noHeader: true,
      noFooter: true,
      withExpandAndCollapseAllButton: true,
      noFullscreenButton: true,
      noPadding: true,
      defaults: {
        order: ["numberOfCuts"]
      },
      formName: "cutsiteProperties",
      noRouter: true,
      withSort: false,
      withSearch: false,
      SubComponent: this.SubComponent,
      isInfinite: true,
      schema: this.schema,
      entities: cutsitesToUse
    }));
  };
  return CutsiteProperties;
}(React.Component);
export default compose(connectToEditor(function (editorState, ownProps) {
  var cutsites = selectors.filteredCutsitesSelector(editorState, ownProps.additionalEnzymes, ownProps.enzymeGroupsOverride);
  var allCutsites = selectors.cutsitesSelector(editorState, ownProps.additionalEnzymes);
  return {
    annotationVisibility: editorState.annotationVisibility || {},
    filteredCutsites: cutsites,
    allCutsites: allCutsites,
    cutsites: cutsites.cutsitesArray
  };
}), withRestrictionEnzymes, withSelectedEntities("cutsiteProperties"))(CutsiteProperties);