"use strict";

exports.__esModule = true;
exports.StatusBar = StatusBar;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _core = require("@blueprintjs/core");
var _withEditorProps = require("../withEditorProps");
require("./style.css");
var _recompose = require("recompose");
var _proteinUtils = require("../utils/proteinUtils");
var _editorUtils = require("../utils/editorUtils");
var _useMeltingTemp2 = _interopRequireDefault(require("../utils/useMeltingTemp"));
var _MeltingTemp = _interopRequireDefault(require("./MeltingTemp"));
var _rangeUtils = require("@teselagen/range-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var EditReadOnlyItem = (0, _withEditorProps.connectToEditor)(function (_ref) {
  var readOnly = _ref.readOnly;
  return {
    readOnly: readOnly
  };
})(function (_ref2) {
  var onSave = _ref2.onSave,
    readOnly = _ref2.readOnly,
    showReadOnly = _ref2.showReadOnly,
    disableSetReadOnly = _ref2.disableSetReadOnly,
    updateReadOnlyMode = _ref2.updateReadOnlyMode;
  return showReadOnly ? /*#__PURE__*/_react["default"].createElement(StatusBarItem, {
    dataTest: "veStatusBar-readOnly"
  }, onSave ? /*#__PURE__*/_react["default"].createElement(_core.HTMLSelect, {
    options: [{
      label: "只读",
      value: "readOnly"
    }, {
      label: "可编辑",
      value: "editable"
    }],
    disabled: disableSetReadOnly || !onSave //the !onSave here is redundant
    ,
    className: _core.Classes.MINIMAL,
    value: readOnly ? "readOnly" : "editable",
    onChange: function onChange(_ref3) {
      var value = _ref3.target.value;
      updateReadOnlyMode(value === "readOnly");
    }
  }) : readOnly ? "只读" : "可编辑") : null;
});
var ShowSelectionItem = (0, _recompose.compose)((0, _withEditorProps.connectToEditor)(function (_ref5, ownProps) {
  var _ref4;
  var selectionLayer = _ref5.selectionLayer,
    caretPosition = _ref5.caretPosition,
    _ref5$sequenceData = _ref5.sequenceData,
    sequenceData = _ref5$sequenceData === void 0 ? {
      sequence: ""
    } : _ref5$sequenceData;
  return {
    showGCContent: (0, _withEditorProps.getShowGCContent)((_ref4 = (arguments.length <= 2 ? 0 : arguments.length - 2) - 1 + 2, _ref4 < 2 || arguments.length <= _ref4 ? undefined : arguments[_ref4]), ownProps),
    selectionLayer: selectionLayer,
    isProtein: sequenceData.isProtein,
    caretPosition: caretPosition,
    sequenceLength: sequenceData.sequence.length,
    sequenceData: sequenceData
  };
}), (0, _recompose.withHandlers)({
  handleInverse: _withEditorProps.handleInverse
}))(function (_ref6) {
  var _ref6$selectionLayer = _ref6.selectionLayer,
    selectionLayer = _ref6$selectionLayer === void 0 ? {
      start: -1,
      end: -1
    } : _ref6$selectionLayer,
    _ref6$caretPosition = _ref6.caretPosition,
    caretPosition = _ref6$caretPosition === void 0 ? -1 : _ref6$caretPosition,
    _ref6$sequenceLength = _ref6.sequenceLength,
    sequenceLength = _ref6$sequenceLength === void 0 ? 0 : _ref6$sequenceLength,
    isProtein = _ref6.isProtein,
    _ref6$sequenceData = _ref6.sequenceData,
    sequenceData = _ref6$sequenceData === void 0 ? {
      sequence: ""
    } : _ref6$sequenceData,
    showGCContent = _ref6.showGCContent,
    GCDecimalDigits = _ref6.GCDecimalDigits,
    handleInverse = _ref6.handleInverse;
  var _useMeltingTemp = (0, _useMeltingTemp2["default"])(),
    showMeltingTemp = _useMeltingTemp[0];
  var sequence = (0, _rangeUtils.getSequenceWithinRange)(selectionLayer, sequenceData.sequence);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(StatusBarItem, {
    dataTest: "veStatusBar-selection"
  }, (0, _editorUtils.getSelectionMessage)({
    caretPosition: caretPosition,
    selectionLayer: selectionLayer,
    sequenceLength: sequenceLength,
    sequenceData: sequenceData,
    showGCContent: showGCContent,
    GCDecimalDigits: GCDecimalDigits,
    isProtein: isProtein
  }), /*#__PURE__*/_react["default"].createElement(_core.Button, {
    minimal: true,
    disabled: sequenceLength <= 0,
    onClick: handleInverse,
    style: {
      marginLeft: 5,
      color: "#48AFF0"
    },
    small: true
  }, "\u9009\u62E9\u53CD\u5411")), showMeltingTemp && /*#__PURE__*/_react["default"].createElement(_MeltingTemp["default"], {
    WrapperToUse: StatusBarItem,
    sequence: sequence
  }));
});
var ShowLengthItem = (0, _withEditorProps.connectToEditor)(function (_ref7) {
  var _ref7$sequenceData = _ref7.sequenceData,
    sequenceData = _ref7$sequenceData === void 0 ? {
      sequence: ""
    } : _ref7$sequenceData;
  return {
    sequenceLength: sequenceData.sequence.length
  };
})(function (_ref8) {
  var isProtein = _ref8.isProtein,
    _ref8$sequenceLength = _ref8.sequenceLength,
    sequenceLength = _ref8$sequenceLength === void 0 ? 0 : _ref8$sequenceLength;
  return /*#__PURE__*/_react["default"].createElement(StatusBarItem, {
    dataTest: "veStatusBar-length"
  }, "\u957F\u5EA6: " + (0, _proteinUtils.divideBy3)(sequenceLength, isProtein) + " " + (isProtein ? "AAs" : "bps"));
});
var ShowTypeItem = (0, _withEditorProps.connectToEditor)(function (_ref9) {
  var sequenceData = _ref9.sequenceData;
  return {
    isProtein: sequenceData.isProtein,
    isOligo: sequenceData.isOligo,
    isRna: sequenceData.isRna,
    isMixedRnaAndDna: sequenceData.isMixedRnaAndDna
  };
})(function (_ref10) {
  var isProtein = _ref10.isProtein,
    isOligo = _ref10.isOligo,
    isRna = _ref10.isRna,
    isMixedRnaAndDna = _ref10.isMixedRnaAndDna;
  var type = "DNA";
  if (isProtein) type = "Protein";
  if (isRna) type = "RNA";
  if (isOligo) type = "Oligo";
  if (isMixedRnaAndDna) type = "Mixed RNA/DNA";
  return /*#__PURE__*/_react["default"].createElement(StatusBarItem, {
    dataTest: "veStatusBar-type"
  }, type);
});
var EditCircularityItem = (0, _recompose.compose)((0, _withEditorProps.connectToEditor)(function (_ref11) {
  var readOnly = _ref11.readOnly,
    sequenceData = _ref11.sequenceData,
    _ref11$sequenceData = _ref11.sequenceData;
  _ref11$sequenceData = _ref11$sequenceData === void 0 ? {} : _ref11$sequenceData;
  var circular = _ref11$sequenceData.circular;
  return {
    readOnly: readOnly,
    sequenceData: sequenceData,
    circular: circular
  };
}), (0, _recompose.withHandlers)({
  updateCircular: _withEditorProps.updateCircular
}))(function (_ref12) {
  var readOnly = _ref12.readOnly,
    showCircularity = _ref12.showCircularity,
    circular = _ref12.circular,
    updateCircular = _ref12.updateCircular;
  return showCircularity ? /*#__PURE__*/_react["default"].createElement(StatusBarItem, {
    dataTest: "veStatusBar-circularity"
  }, readOnly ? circular ? "Circular" : "Linear" : /*#__PURE__*/_react["default"].createElement(_core.HTMLSelect, {
    onChange: function onChange(_ref13) {
      var value = _ref13.target.value;
      updateCircular(value === "circular");
    },
    className: _core.Classes.MINIMAL,
    value: circular ? "circular" : "linear",
    options: [{
      label: "Circular",
      value: "circular"
    }, {
      label: "Linear",
      value: "linear"
    }]
  })) : null;
});
var EditAvailabilityItem = (0, _withEditorProps.connectToEditor)(function (_ref14) {
  var readOnly = _ref14.readOnly,
    _ref14$sequenceData = _ref14.sequenceData;
  _ref14$sequenceData = _ref14$sequenceData === void 0 ? {} : _ref14$sequenceData;
  var materiallyAvailable = _ref14$sequenceData.materiallyAvailable;
  return {
    readOnly: readOnly,
    materiallyAvailable: materiallyAvailable
  };
})(function (_ref15) {
  var readOnly = _ref15.readOnly,
    showAvailability = _ref15.showAvailability,
    materiallyAvailable = _ref15.materiallyAvailable,
    updateAvailability = _ref15.updateAvailability;
  return showAvailability ? /*#__PURE__*/_react["default"].createElement(StatusBarItem, null, readOnly ? materiallyAvailable ? "Available" : "Unavailable" : /*#__PURE__*/_react["default"].createElement(_core.HTMLSelect, {
    onChange: function onChange(_ref16) {
      var value = _ref16.target.value;
      updateAvailability(value === "available");
    },
    className: _core.Classes.MINIMAL,
    value: materiallyAvailable ? "available" : "unavailable",
    options: [{
      label: "Available",
      value: "available"
    }, {
      label: "Unavailable",
      value: "unavailable"
    }]
  })) : null;
});
function StatusBar(_ref17) {
  var disableSetReadOnly = _ref17.disableSetReadOnly,
    onSave = _ref17.onSave,
    editorName = _ref17.editorName,
    _ref17$showCircularit = _ref17.showCircularity,
    showCircularity = _ref17$showCircularit === void 0 ? true : _ref17$showCircularit,
    _ref17$showMoleculeTy = _ref17.showMoleculeType,
    showMoleculeType = _ref17$showMoleculeTy === void 0 ? true : _ref17$showMoleculeTy,
    _ref17$showReadOnly = _ref17.showReadOnly,
    showReadOnly = _ref17$showReadOnly === void 0 ? true : _ref17$showReadOnly,
    _ref17$showAvailabili = _ref17.showAvailability,
    showAvailability = _ref17$showAvailabili === void 0 ? false : _ref17$showAvailabili,
    showGCContentByDefault = _ref17.showGCContentByDefault,
    onSelectionOrCaretChanged = _ref17.onSelectionOrCaretChanged,
    _ref17$GCDecimalDigit = _ref17.GCDecimalDigits,
    GCDecimalDigits = _ref17$GCDecimalDigit === void 0 ? 1 : _ref17$GCDecimalDigit,
    isProtein = _ref17.isProtein;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "veStatusBar"
  }, showMoleculeType && /*#__PURE__*/_react["default"].createElement(ShowTypeItem, {
    editorName: editorName
  }), /*#__PURE__*/_react["default"].createElement(EditReadOnlyItem, {
    editorName: editorName,
    onSave: onSave,
    disableSetReadOnly: disableSetReadOnly,
    showReadOnly: showReadOnly
  }), /*#__PURE__*/_react["default"].createElement(EditCircularityItem, {
    editorName: editorName,
    showCircularity: showCircularity
  }), /*#__PURE__*/_react["default"].createElement(EditAvailabilityItem, {
    editorName: editorName,
    showAvailability: showAvailability
  }), /*#__PURE__*/_react["default"].createElement(ShowSelectionItem, {
    editorName: editorName,
    isProtein: isProtein,
    showGCContentByDefault: showGCContentByDefault,
    onSelectionOrCaretChanged: onSelectionOrCaretChanged,
    GCDecimalDigits: GCDecimalDigits
  }), /*#__PURE__*/_react["default"].createElement(ShowLengthItem, {
    isProtein: isProtein,
    editorName: editorName
  }));
}
function StatusBarItem(_ref18) {
  var children = _ref18.children,
    dataTest = _ref18.dataTest;
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    "data-test": dataTest,
    className: "veStatusBarItem"
  }, children), /*#__PURE__*/_react["default"].createElement("div", {
    className: "veStatusBarSpacer"
  }));
}
var _default = StatusBar;
exports["default"] = _default;