"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _reduxForm = require("redux-form");
var _teselagenReactComponents = require("teselagen-react-components");
var _redux = require("redux");
var _core = require("@blueprintjs/core");
var _classnames = _interopRequireDefault(require("classnames"));
var _withEditorProps = _interopRequireDefault(require("../../withEditorProps"));
var _lodash = require("lodash");
var _utils = require("../PropertiesDialog/utils");
var _rangeUtils = require("@teselagen/range-utils");
var _tgFormValues = _interopRequireDefault(require("../../utils/tgFormValues"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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); }
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 schema = {
  fields: [
  // ...(noColor
  //   ? []
  //   : [
  //       {
  //         path: "color",
  //         type: "string",
  //         render: color => {
  //           return (
  //             <ColorPickerPopover>
  //               <div style={{ height: 20, width: 20, background: color }} />
  //             </ColorPickerPopover>
  //           );
  //         }
  //       }
  //     ]),
  {
    path: "name",
    displayName: "名称",
    type: "string"
  },
  // ...(noType ? [] : [{ path: "type", type: "string" }]),
  _utils.sizeSchema, {
    path: "strand",
    displayName: "位于正/负链",
    type: "string"
  }]
};
var RemoveDuplicatesDialog = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(RemoveDuplicatesDialog, _React$Component);
  function RemoveDuplicatesDialog() {
    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", {
      dups: []
    });
    _defineProperty(_assertThisInitialized(_this), "checkboxStyle", {
      marginTop: 0,
      marginBottom: 0
    });
    _defineProperty(_assertThisInitialized(_this), "delayedRecomputeDups", function () {
      setTimeout(function () {
        _this.recomputeDups();
      });
    });
    _defineProperty(_assertThisInitialized(_this), "recomputeDups", function () {
      var _this$props = _this.props,
        type = _this$props.type,
        _this$props$sequenceD = _this$props.sequenceData,
        sequenceData = _this$props$sequenceD === void 0 ? {
          sequence: ""
        } : _this$props$sequenceD,
        sequenceLength = _this$props.sequenceLength,
        ignoreName = _this$props.ignoreName,
        ignoreStrand = _this$props.ignoreStrand,
        ignoreStartAndEnd = _this$props.ignoreStartAndEnd;
      var annotations = sequenceData[type];
      var dups = [];
      var seqsHashByStartEndStrandName = {};
      (0, _lodash.forEach)(annotations, function (a) {
        var hash = (ignoreStartAndEnd ? "" : a.start) + "&" + (ignoreStartAndEnd ? "" : a.end) + "&" + (ignoreStrand ? "" : a.strand) + "&" + (ignoreName ? "" : a.name);
        if (seqsHashByStartEndStrandName[hash]) {
          dups.push(_extends({}, a, {
            size: (0, _rangeUtils.getRangeLength)(a, sequenceLength)
          }));
        } else {
          seqsHashByStartEndStrandName[hash] = true;
        }
      });
      _this.setState({
        dups: dups
      });
    });
    return _this;
  }
  var _proto = RemoveDuplicatesDialog.prototype;
  _proto.componentDidMount = function componentDidMount() {
    this.recomputeDups();
  };
  _proto.render = function render() {
    var _this2 = this;
    var _this$props2 = this.props,
      duplicatesToRemoveSelectedEntities = _this$props2.duplicatesToRemoveSelectedEntities,
      hideModal = _this$props2.hideModal,
      type = _this$props2.type;
    var selectedIds = this.state.dups.map(function (d) {
      return d.id;
    });
    // const sequenceLength = sequenceData.sequence.length;
    // const isCirc = (this.state || {}).circular;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])(_core.Classes.DIALOG_BODY, "tg-min-width-dialog")
    }, /*#__PURE__*/_react["default"].createElement(_teselagenReactComponents.DataTable, {
      noPadding: true,
      withCheckboxes: true,
      noFullscreenButton: true
      // onRowSelect={this.onRowSelect}
      ,
      maxHeight: 400,
      selectedIds: selectedIds,
      formName: "duplicatesToRemove",
      noRouter: true,
      noRowsFoundMessage: "No duplicates found",
      compact: true,
      noHeader: true,
      noFooter: true,
      withSearch: false,
      hideSelectedCount: true,
      isInfinite: true,
      schema: schema,
      entities: this.state.dups
    }), /*#__PURE__*/_react["default"].createElement("div", {
      style: {
        marginTop: 10,
        display: "flex",
        justifyContent: "space-between"
      }
    }, /*#__PURE__*/_react["default"].createElement(_core.Popover, {
      target: /*#__PURE__*/_react["default"].createElement(_core.Button, {
        icon: "settings"
      }),
      content: /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          padding: 20,
          maxWidth: 250
        }
      }, /*#__PURE__*/_react["default"].createElement("div", null, "\u5728\u67E5\u627E\u91CD\u590D\u9879\u65F6\u5FFD\u7565\u8FD9\u4E9B\u5B57\u6BB5:"), /*#__PURE__*/_react["default"].createElement("br", null), /*#__PURE__*/_react["default"].createElement(_teselagenReactComponents.SwitchField, {
        containerStyle: {
          marginBottom: 2
        }
        //delay the call to recompute dups until redux has had time to update
        ,
        onFieldSubmit: this.delayedRecomputeDups,
        style: this.checkboxStyle,
        name: "ignoreName",
        label: "\u540D\u79F0"
      }), /*#__PURE__*/_react["default"].createElement(_teselagenReactComponents.SwitchField, {
        containerStyle: {
          marginBottom: 2
        }
        //delay the call to recompute dups until redux has had time to update
        ,
        onFieldSubmit: this.delayedRecomputeDups,
        style: this.checkboxStyle,
        name: "ignoreStrand",
        label: "\u4F4D\u4E8E\u6B63/\u8D1F\u94FE"
      }), /*#__PURE__*/_react["default"].createElement(_teselagenReactComponents.SwitchField, {
        containerStyle: {
          marginBottom: 2
        }
        //delay the call to recompute dups until redux has had time to update
        ,
        onFieldSubmit: this.delayedRecomputeDups,
        style: this.checkboxStyle,
        name: "ignoreStartAndEnd",
        label: "\u5F00\u59CB\u548C\u7ED3\u675F"
      }))
    }), /*#__PURE__*/_react["default"].createElement(_core.Button, {
      intent: "primary",
      onClick: function onClick() {
        _this2.props[(0, _lodash.camelCase)("delete_" + type).slice(0, -1)](duplicatesToRemoveSelectedEntities.map(function (d) {
          return d.id;
        }));
        window.toastr.success("Successfully Deleted " + duplicatesToRemoveSelectedEntities.length + " " + (0, _lodash.startCase)(type));
        hideModal();
      },
      disabled: !(duplicatesToRemoveSelectedEntities || []).length
    }, "\u5220\u9664 ", duplicatesToRemoveSelectedEntities.length, " \u4E2A\u91CD\u590D\u7684")));
  };
  return RemoveDuplicatesDialog;
}(_react["default"].Component);
var _default = (0, _redux.compose)((0, _teselagenReactComponents.wrapDialog)(), _withEditorProps["default"], (0, _teselagenReactComponents.withSelectedEntities)("duplicatesToRemove"), (0, _reduxForm.reduxForm)({
  form: "RemoveDuplicatesDialog"
}), (0, _tgFormValues["default"])("ignoreName", "ignoreStrand", "ignoreStartAndEnd"))(RemoveDuplicatesDialog);
exports["default"] = _default;
module.exports = exports.default;