"use strict";

exports.__esModule = true;
exports.PartTagSearch = void 0;
var _react = _interopRequireDefault(require("react"));
var _withEditorProps = _interopRequireDefault(require("../withEditorProps"));
var _teselagenReactComponents = require("teselagen-react-components");
var _lodash = require("lodash");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var PartTagSearch = (0, _withEditorProps["default"])(PartToolDropdown);
exports.PartTagSearch = PartTagSearch;
function PartToolDropdown(_ref) {
  var sequenceData = _ref.sequenceData,
    updateSelectedPartTags = _ref.updateSelectedPartTags,
    selectedPartTags = _ref.selectedPartTags,
    allPartTags = _ref.allPartTags,
    annotationVisibilityShow = _ref.annotationVisibilityShow,
    editTagsLink = _ref.editTagsLink,
    dontAutoOpen = _ref.dontAutoOpen;
  if (!sequenceData) return /*#__PURE__*/_react["default"].createElement("div", null, "No Parts Present");
  var keyedTags = (0, _teselagenReactComponents.getKeyedTagsAndTagOptions)(allPartTags);

  // this is what keyedTags looks like:
  // keyedTags = {
  //   '12:4': {label,value,id},
  //   '12:1': {label,value,id},
  //   '44': {label,value,id},
  // }

  var tags = (0, _lodash.uniqBy)((0, _lodash.flatMap)(sequenceData.parts, function (_ref2) {
    var tags = _ref2.tags;
    return (0, _lodash.flatMap)(tags, function (t) {
      var tag = keyedTags[t];
      if (!tag) return [];
      return tag;
    });
  }), "value");
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: "100%"
    }
  }, /*#__PURE__*/_react["default"].createElement("div", null, "\u6309\u6807\u7B7E\u8FC7\u6EE4: "), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      display: "flex"
    }
  }, /*#__PURE__*/_react["default"].createElement(_teselagenReactComponents.TgSelect, {
    value: selectedPartTags.parts,
    onChange: function onChange() {
      annotationVisibilityShow("parts");
      updateSelectedPartTags.apply(void 0, arguments);
    },
    isTagSelect: true,
    multi: true,
    popoverProps: {
      usePortal: false,
      modifiers: {
        preventOverflow: {
          enabled: false
        },
        hide: {
          enabled: false
        },
        flip: {
          boundariesElement: "viewport"
        }
      }
    },
    options: tags,
    autoOpen: !dontAutoOpen
  }), editTagsLink || null));
}