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); }
import shortid from "shortid";
import { cloneDeep, startCase } from "lodash";
import { convertRangeTo1Based } from "@teselagen/range-utils";
export var dialogHolder = {};
//if an overrideName is passed, then that dialog can be overridden if an overriding dialog is passed as a prop to the <Editor/>
export function showDialog(_ref) {
  var ModalComponent = _ref.ModalComponent,
    dialogType = _ref.dialogType,
    props = _ref.props,
    overrideName = _ref.overrideName;
  dialogHolder.dialogType = dialogType;
  if (!dialogHolder.dialogType && ModalComponent) {
    dialogHolder.dialogType = "TGCustomModal";
  }
  dialogHolder.CustomModalComponent = ModalComponent;
  dialogHolder.props = props;
  dialogHolder.overrideName = overrideName;
  dialogHolder.setUniqKey(shortid());
}
export function hideDialog() {
  delete dialogHolder.dialogType;
  delete dialogHolder.CustomModalComponent;
  delete dialogHolder.props;
  delete dialogHolder.overrideName;
  dialogHolder.setUniqKey();
}
var typeToDialogType = {
  part: "AddOrEditPartDialog",
  feature: "AddOrEditFeatureDialog",
  primer: "AddOrEditPrimerDialog"
};
export function showAddOrEditAnnotationDialog(_ref2) {
  var type = _ref2.type,
    _annotation = _ref2.annotation;
  // AddOrEditPartDialog
  // AddOrEditFeatureDialog
  // AddOrEditPrimerDialog
  var dialogType = typeToDialogType[type];
  if (Object.values(typeToDialogType).includes(dialogHolder.dialogType)) {
    return;
  }
  var nameUpper = startCase(type);
  if (nameUpper == 'Primer') {
    nameUpper = '引物';
  }
  var annotation = cloneDeep(_annotation);
  if (_annotation.isWrappedAddon) {
    delete annotation.isWrappedAddon;
    delete annotation.rangeTypeOverride;
    annotation.start = _annotation.end + 1;
    annotation.end = _annotation.start - 1;
  }
  var forward = annotation.strand === -1 ? false : annotation.forward !== undefined ? !!annotation.forward : true;
  showDialog({
    overrideName: "AddOrEdit" + nameUpper + "DialogOverride",
    dialogType: dialogType,
    props: {
      dialogProps: {
        title: annotation && annotation.id ? "\u7F16\u8F91" + nameUpper : "\u65B0\u5EFA" + nameUpper
      },
      initialValues: _extends({}, annotation ? _extends({}, convertRangeTo1Based(annotation), {
        forward: forward,
        arrowheadType: annotation.arrowheadType || (!forward ? "BOTTOM" : "TOP")
      }, annotation.locations && {
        locations: annotation.locations.map(convertRangeTo1Based)
      }) : {})
    }
  });
}