"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _bioParsers = require("@teselagen/bio-parsers");
var _core = require("@blueprintjs/core");
var _withEditorProps = require("../../withEditorProps");
var _recompose = require("recompose");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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); }
var GenbankView = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(GenbankView, _React$Component);
  function GenbankView() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _defineProperty(_assertThisInitialized(_this), "state", {
      fileTypeToView: "genbank"
    });
    _defineProperty(_assertThisInitialized(_this), "select", function () {
      var _this$_input;
      return (_this$_input = _this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.select();
    });
    return _this;
  }
  var _proto = GenbankView.prototype;
  _proto.render = function render() {
    var _this2 = this;
    var _this$props$sequenceD = this.props.sequenceData,
      sequenceData = _this$props$sequenceD === void 0 ? {} : _this$props$sequenceD;
    var filestring;
    switch (this.state.fileTypeToView) {
      case "fasta":
        filestring = (0, _bioParsers.jsonToFasta)(sequenceData);
        break;
      case "teselagen":
        filestring = JSON.stringify((0, _bioParsers.cleanUpTeselagenJsonForExport)(sequenceData), null, 4);
        break;
      default:
        filestring = (0, _bioParsers.jsonToGenbank)(sequenceData);
    }
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_core.HTMLSelect, {
      className: "genbankFileView-type",
      fill: false,
      options: [{
        label: "Genbank",
        value: "genbank"
      }, {
        label: "Fasta",
        value: "fasta"
      }, {
        label: "Teselagen JSON",
        value: "teselagen"
      }],
      onChange: function onChange(e) {
        _this2.setState({
          fileTypeToView: e.target.value
        });
      }
    }), /*#__PURE__*/_react["default"].createElement("textarea", {
      "data-test": "ve-genbank-text",
      readOnly: true,
      onClick: this.select,
      style: {
        whiteSpace: "pre",
        overflowWrap: "normal",
        overflowX: "scroll",
        fontSize: 11,
        fontFamily: "monospace",
        height: 350
      },
      ref: function ref(_ref) {
        return _this2._input = _ref;
      },
      value: filestring
    }));
  };
  return GenbankView;
}(_react["default"].Component);
var _default = (0, _recompose.compose)((0, _withEditorProps.connectToEditor)(function (_ref2) {
  var _ref2$sequenceData = _ref2.sequenceData,
    sequenceData = _ref2$sequenceData === void 0 ? {} : _ref2$sequenceData;
  return {
    sequenceData: sequenceData
  };
}))(GenbankView);
exports["default"] = _default;
module.exports = exports.default;