import React from "react";
import { Button, Icon, Popover, RadioGroup } from "@blueprintjs/core";
import { calculateTm, calculateNebTm } from "@teselagen/sequence-utils";
import { isString } from "lodash";
import { popoverOverflowModifiers } from "teselagen-react-components";
import useTmType from "../utils/useTmType";
export default function MeltingTemp(_ref) {
  var sequence = _ref.sequence,
    _ref$WrapperToUse = _ref.WrapperToUse,
    WrapperToUse = _ref$WrapperToUse === void 0 ? function (p) {
      return /*#__PURE__*/React.createElement("div", null, p.children);
    } : _ref$WrapperToUse,
    _ref$InnerWrapper = _ref.InnerWrapper,
    InnerWrapper = _ref$InnerWrapper === void 0 ? function (p) {
      return /*#__PURE__*/React.createElement(Button, {
        minimal: true,
        small: true
      }, p.children);
    } : _ref$InnerWrapper;
  var _useTmType = useTmType(),
    tmType = _useTmType[0],
    setTmType = _useTmType[1];
  var tm = ({
    "default": calculateTm,
    neb_tm: calculateNebTm
  }[tmType] || calculateTm)((sequence || "").toLowerCase());
  var hasWarning = isString(tm) && tm.length > 7 && tm;
  return /*#__PURE__*/React.createElement(WrapperToUse, {
    dataTest: "veStatusBar-selection-tm"
  }, /*#__PURE__*/React.createElement(Popover, {
    modifiers: popoverOverflowModifiers,
    content: /*#__PURE__*/React.createElement("div", {
      style: {
        maxWidth: 300,
        padding: 20
      }
    }, "\u4F7F\u7528\u57FA\u4E8E\u8FD9\u4E9B\u7684Tm\u8BA1\u7B97", " ", /*#__PURE__*/React.createElement("a", {
      rel: "noopener noreferrer",
      target: "_blank",
      href: "https://github.com/TeselaGen/@teselagen/sequence-utils"
    }, "\u7B97\u6CD5"), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(RadioGroup, {
      label: "\u9009\u62E9Tm\u7C7B\u578B:",
      options: [{
        value: "default",
        label: "默认Tm"
      }, {
        value: "neb_tm",
        label: "NEB Tm"
      }],
      onChange: function onChange(e) {
        return setTmType(e.target.value);
      },
      selectedValue: tmType
    }), hasWarning && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Icon, {
      style: {
        marginLeft: 5,
        marginRight: 5
      },
      size: 10,
      icon: "warning-sign"
    }), hasWarning, /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), "\u5C1D\u8BD5\u4F7F\u7528\u9ED8\u8BA4Tm"))
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InnerWrapper, null, "Tm\u503C: ", Number(tm) || 0, " "), hasWarning && /*#__PURE__*/React.createElement(Icon, {
    style: {
      marginLeft: 5,
      marginRight: 5
    },
    size: 10,
    icon: "warning-sign"
  }))));
}