"use strict";

exports.__esModule = true;
exports.CircularDnaSequence = CircularDnaSequence;
var _react = _interopRequireDefault(require("react"));
var _shouldFlipText = _interopRequireDefault(require("./shouldFlipText"));
var _sequenceUtils = require("@teselagen/sequence-utils");
var _dnaToColor = require("../constants/dnaToColor");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function CircularDnaSequence(_ref) {
  var rotationRadians = _ref.rotationRadians,
    _ref$textHeightOffset = _ref.textHeightOffset,
    textHeightOffset = _ref$textHeightOffset === void 0 ? -5 : _ref$textHeightOffset,
    annotation = _ref.annotation,
    showReverseSequence = _ref.showReverseSequence,
    showDnaColors = _ref.showDnaColors,
    showSeqText = _ref.showSeqText,
    totalAngle = _ref.totalAngle,
    radius = _ref.radius;
  var shouldFlip = (0, _shouldFlipText["default"])(annotation.startAngle + rotationRadians);
  var getShared = function getShared(_ref2) {
    var textHeightOffset = _ref2.textHeightOffset,
      isReverse = _ref2.isReverse;
    return {
      className: "ve-monospace-font " + (isReverse ? "ve-sequence-reverse" : ""),
      transform: (shouldFlip ? "rotate(180)" : "") + (" translate(0, " + (shouldFlip ? -textHeightOffset : textHeightOffset) + ")"),
      style: {
        fontSize: 12,
        textAnchor: "middle",
        dominantBaseline: "central"
      }
    };
  };
  var forward = null;
  var reverse = null;
  var dnaColors = null;
  if (showSeqText) {
    forward = /*#__PURE__*/_react["default"].createElement("text", getShared({
      textHeightOffset: showReverseSequence ? textHeightOffset - 15 : textHeightOffset
    }), annotation.letter);
  }
  if (showSeqText && showReverseSequence) {
    reverse = /*#__PURE__*/_react["default"].createElement("text", getShared({
      textHeightOffset: textHeightOffset,
      isReverse: true
    }), (0, _sequenceUtils.getComplementSequenceString)(annotation.letter));
  }
  if (!showSeqText || showDnaColors) {
    var height = showReverseSequence ? 30 : 15;
    var width = Math.max(totalAngle * radius);
    dnaColors = /*#__PURE__*/_react["default"].createElement("rect", {
      fill: (0, _dnaToColor.getDnaColor)(annotation.letter),
      height: height,
      width: width,
      transform: "translate(-" + width / 2 + ", -" + (height - 3) + ")",
      className: "veDnaColor"
    });
  }
  return /*#__PURE__*/_react["default"].createElement("g", null, dnaColors, forward, reverse);
}