var _excluded = ["additionalFooterEls", "additionalHeaderEls"];
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 _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 _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from "react";
import { compose } from "redux";
import { Tab, Tabs } from "@blueprintjs/core";
import { flatMap, startCase } from "lodash";
import FeatureProperties from "./FeatureProperties";
import GeneralProperties from "./GeneralProperties";
import CutsiteProperties from "./CutsiteProperties";
import OrfProperties from "./OrfProperties";
import GenbankView from "./GenbankView";
import TranslationProperties from "./TranslationProperties";
import PrimerProperties from "./PrimerProperties";
import PartProperties from "./PartProperties";
import { connectToEditor } from "../../withEditorProps";
import "./style.css";
import { userDefinedHandlersAndOpts } from "../../Editor/userDefinedHandlersAndOpts";
import { pick } from "lodash";
var PropertiesContainer = function PropertiesContainer(Comp) {
  return function (props) {
    var additionalFooterEls = props.additionalFooterEls,
      additionalHeaderEls = props.additionalHeaderEls,
      rest = _objectWithoutPropertiesLoose(props, _excluded);
    return /*#__PURE__*/React.createElement(React.Fragment, null, additionalHeaderEls, /*#__PURE__*/React.createElement(Comp, rest), additionalFooterEls);
  };
};
var allTabs = {
  general: PropertiesContainer(GeneralProperties),
  features: PropertiesContainer(FeatureProperties),
  parts: PropertiesContainer(PartProperties),
  primers: PropertiesContainer(PrimerProperties),
  translations: PropertiesContainer(TranslationProperties),
  cutsites: PropertiesContainer(CutsiteProperties),
  orfs: PropertiesContainer(OrfProperties),
  genbank: PropertiesContainer(GenbankView)
};
export var PropertiesDialog = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(PropertiesDialog, _React$Component);
  function PropertiesDialog() {
    return _React$Component.apply(this, arguments) || this;
  }
  var _proto = PropertiesDialog.prototype;
  _proto.render = function render() {
    var _this = this;
    var _this$props$this$prop = _extends({}, this.props, this.props.PropertiesProps),
      _this$props$this$prop2 = _this$props$this$prop.propertiesTool,
      propertiesTool = _this$props$this$prop2 === void 0 ? {} : _this$props$this$prop2,
      propertiesViewTabUpdate = _this$props$this$prop.propertiesViewTabUpdate,
      _this$props$this$prop3 = _this$props$this$prop.dimensions,
      dimensions = _this$props$this$prop3 === void 0 ? {} : _this$props$this$prop3,
      height = _this$props$this$prop.height,
      editorName = _this$props$this$prop.editorName,
      onSave = _this$props$this$prop.onSave,
      showReadOnly = _this$props$this$prop.showReadOnly,
      showAvailability = _this$props$this$prop.showAvailability,
      isProtein = _this$props$this$prop.isProtein,
      _this$props$this$prop4 = _this$props$this$prop.annotationsToSupport,
      annotationsToSupport = _this$props$this$prop4 === void 0 ? {} : _this$props$this$prop4,
      disableSetReadOnly = _this$props$this$prop.disableSetReadOnly,
      _this$props$this$prop5 = _this$props$this$prop.propertiesList,
      propertiesList = _this$props$this$prop5 === void 0 ? ["general", "features", "parts", "primers", "translations", "cutsites", "orfs", "genbank"] : _this$props$this$prop5,
      closePanelButton = _this$props$this$prop.closePanelButton;
    var width = dimensions.width,
      heightFromDim = dimensions.height;
    var tabId = propertiesTool.tabId,
      selectedAnnotationId = propertiesTool.selectedAnnotationId;
    if (propertiesList.map(function (nameOrOverride) {
      return nameOrOverride.name || nameOrOverride;
    }).indexOf(tabId) === -1) {
      tabId = propertiesList[0].name || propertiesList[0];
    }
    var propertiesTabs = flatMap(propertiesList, function (nameOrOverride) {
      if (annotationsToSupport[nameOrOverride] === false) {
        return [];
      }
      var name = nameOrOverride.name || nameOrOverride;
      var Comp = nameOrOverride.Comp || allTabs[name];
      if (isProtein) {
        if (name === "translations" || name === "orfs" || name === "primers" || name === "cutsites") {
          return null;
        }
      }
      var title = function () {
        if (name === "general") return '概况';
        if (name === "primers") return '引物';
        if (name === "translations") return '翻译';
        if (nameOrOverride.Comp) return name; //just use the user supplied name because this is a custom panel
        if (name === "orfs") return "ORFs";
        if (name === "cutsites") return "酶切位点";
        return startCase(name);
      }();
      return /*#__PURE__*/React.createElement(Tab, {
        key: name,
        title: title,
        id: name,
        panel: /*#__PURE__*/React.createElement(Comp, _extends({}, pick(_this.props, userDefinedHandlersAndOpts), {
          editorName: editorName,
          onSave: onSave,
          isProtein: isProtein,
          showReadOnly: showReadOnly,
          showAvailability: showAvailability,
          disableSetReadOnly: disableSetReadOnly,
          selectedAnnotationId: selectedAnnotationId
        }, nameOrOverride.name && nameOrOverride))
      });
    });
    console.log('propertiesTabs========', propertiesTabs);
    var heightToUse = Math.max(0, Number((heightFromDim || height) - 30));
    return /*#__PURE__*/React.createElement("div", {
      style: {
        position: "relative"
      }
    }, closePanelButton, /*#__PURE__*/React.createElement("div", {
      className: "ve-propertiesPanel",
      style: {
        display: "flex",
        width: width,
        height: heightToUse || 300,
        zIndex: 10,
        padding: 10
        // paddingBottom: '31px',
      }
    }, propertiesTabs.length ? /*#__PURE__*/React.createElement(Tabs, {
      style: {
        width: width
      },
      renderActiveTabPanelOnly: true,
      selectedTabId: tabId,
      onChange: propertiesViewTabUpdate
    }, /*#__PURE__*/React.createElement(Tabs.Expander, null), propertiesTabs, /*#__PURE__*/React.createElement(Tabs.Expander, null)) : /*#__PURE__*/React.createElement("div", {
      style: {
        margin: 20,
        fontSize: 20
      }
    }, "No Properties to display")));
  };
  return PropertiesDialog;
}(React.Component);
export default compose(connectToEditor(function (_ref) {
  var propertiesTool = _ref.propertiesTool,
    annotationsToSupport = _ref.annotationsToSupport;
  return {
    propertiesTool: propertiesTool,
    annotationsToSupport: annotationsToSupport
  };
}))(PropertiesDialog);