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 } from "lodash";
// import { Button } from "@blueprintjs/core";
import { getRangeLength } from "@teselagen/range-utils";
import { getOrfColor } from "../../constants/orfFrameToColorMap";
import { connectToEditor } from "../../withEditorProps";
import { compose } from "recompose";
import selectors from "../../selectors";
import getCommands from "../../commands";
import { sizeSchema } from "./utils";
import { orfsSubmenu } from "../../MenuBar/viewSubmenu";
import { getVisFilter } from "./GenericAnnotationProperties";
var OrfProperties = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(OrfProperties, _React$Component);
  function OrfProperties(props) {
    var _this;
    _this = _React$Component.call(this, props) || this;
    _defineProperty(_assertThisInitialized(_this), "onRowSelect", function (_ref) {
      var record = _ref[0];
      if (!record) return;
      var _this$props = _this.props,
        dispatch = _this$props.dispatch,
        editorName = _this$props.editorName;
      dispatch({
        type: "SELECTION_LAYER_UPDATE",
        payload: record,
        meta: {
          editorName: editorName
        }
      });
    });
    _this.commands = getCommands(_assertThisInitialized(_this));
    return _this;
  }
  var _proto = OrfProperties.prototype;
  _proto.render = function render() {
    var _this$props2 = this.props,
      orfs = _this$props2.orfs,
      sequenceLength = _this$props2.sequenceLength,
      annotationVisibility = _this$props2.annotationVisibility;
    var orfsToUse = map(orfs, function (orf) {
      return _extends({}, orf, {
        color: getOrfColor(orf),
        frame: orf.frame + 1
      }, orf.strand === undefined && {
        strand: orf.forward ? 1 : -1
      }, {
        size: getRangeLength(orf, sequenceLength),
        sizeAa: Math.floor(getRangeLength(orf, sequenceLength) / 3 - 1)
      });
    });
    return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataTable, {
      topLeftItems: getVisFilter(createCommandMenu(orfsSubmenu, this.commands, {
        useTicks: true
      })),
      annotationVisibility: annotationVisibility //we need to pass this in order to force the DT to rerender
      ,
      noPadding: true,
      noFullscreenButton: true,
      onRowSelect: this.onRowSelect,
      withSearch: false,
      formName: "orfProperties",
      noRouter: true,
      compact: true,
      isInfinite: true,
      schema: {
        fields: [{
          path: "color",
          displayName: "颜色",
          type: "string",
          render: function render(color) {
            return /*#__PURE__*/React.createElement("div", {
              style: {
                height: 20,
                width: 20,
                background: color
              }
            });
          }
        }, {
          path: "sizeAa",
          displayName: "尺寸 (aa)",
          type: "number"
        }, sizeSchema, {
          path: "frame",
          displayName: "框",
          type: "number"
        }, {
          path: "strand",
          displayName: "位于正/负链",
          type: "number"
        }]
      },
      entities: orfsToUse
    }), /*#__PURE__*/React.createElement("br", null));
  };
  return OrfProperties;
}(React.Component);
export default compose(connectToEditor(function (editorState) {
  var readOnly = editorState.readOnly,
    _editorState$annotati = editorState.annotationVisibility,
    annotationVisibility = _editorState$annotati === void 0 ? {} : _editorState$annotati,
    _editorState$sequence = editorState.sequenceData;
  _editorState$sequence = _editorState$sequence === void 0 ? {} : _editorState$sequence;
  var _editorState$sequence2 = _editorState$sequence.sequence,
    sequence = _editorState$sequence2 === void 0 ? "" : _editorState$sequence2,
    sequenceData = editorState.sequenceData,
    minimumOrfSize = editorState.minimumOrfSize,
    useAdditionalOrfStartCodons = editorState.useAdditionalOrfStartCodons;
  return {
    readOnly: readOnly,
    annotationVisibility: annotationVisibility,
    useAdditionalOrfStartCodons: useAdditionalOrfStartCodons,
    orfs: selectors.orfsSelector(editorState),
    sequenceLength: sequence.length,
    sequenceData: sequenceData,
    minimumOrfSize: minimumOrfSize
  };
}), withSelectedEntities("orfProperties"))(OrfProperties);