var _excluded = ["modifyTools", "contentLeft", "showMenuBar", "displayMenuBarAboveTools", "isProtein", "openHotkeyDialog", "onSave", "userDefinedHandlersAndOpts", "editorName", "annotationsToSupport", "handleFullscreenClose", "closeFullscreen", "additionalTopRightToolbarButtons", "toolList"];
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 _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 { flatMap, isString, pick } from "lodash";
import versionHistoryTool from "./versionHistoryTool";
// import {connectToEditor} from "../withEditorProps";
import MenuBar from "../MenuBar";
import "./style.css";
import { Button, Tooltip } from "@blueprintjs/core";
import downloadTool from "./downloadTool";
import importTool from "./importTool";
import cutsiteTool from "./cutsiteTool";
import featureTool from "./featureTool";
import partTool from "./partTool";
import oligoTool from "./oligoTool";
import orfTool from "./orfTool";
import editTool from "./editTool";
import findTool from "./findTool";
import inlineFindTool from "./inlineFindTool";
import alignmentTool from "./alignmentTool";
import saveTool from "./saveTool";
import visibilityTool from "./visibilityTool";
import undoTool from "./undoTool";
import redoTool from "./redoTool";
import isMobile from "is-mobile";
import { useMemo } from "react";
var allTools = {
  downloadTool: downloadTool,
  importTool: importTool,
  cutsiteTool: cutsiteTool,
  alignmentTool: alignmentTool,
  featureTool: featureTool,
  partTool: partTool,
  oligoTool: oligoTool,
  orfTool: orfTool,
  editTool: editTool,
  findTool: findTool,
  inlineFindTool: inlineFindTool,
  versionHistoryTool: versionHistoryTool,
  saveTool: saveTool,
  visibilityTool: visibilityTool,
  undoTool: undoTool,
  redoTool: redoTool
};
export function ToolBar(props) {
  var modifyTools = props.modifyTools,
    contentLeft = props.contentLeft,
    showMenuBar = props.showMenuBar,
    displayMenuBarAboveTools = props.displayMenuBarAboveTools,
    isProtein = props.isProtein,
    openHotkeyDialog = props.openHotkeyDialog,
    onSave = props.onSave,
    userDefinedHandlersAndOpts = props.userDefinedHandlersAndOpts,
    editorName = props.editorName,
    annotationsToSupport = props.annotationsToSupport,
    handleFullscreenClose = props.handleFullscreenClose,
    closeFullscreen = props.closeFullscreen,
    additionalTopRightToolbarButtons = props.additionalTopRightToolbarButtons,
    _props$toolList = props.toolList,
    toolList = _props$toolList === void 0 ? defaultToolList : _props$toolList,
    rest = _objectWithoutPropertiesLoose(props, _excluded);
  var userDefinedProps = _extends({}, pick(props, userDefinedHandlersAndOpts));
  var toolListToUse = useMemo(function () {
    return flatMap(toolList, function (toolNameOrOverrides) {
      var toolName;
      var toolOverride;
      if (isString(toolNameOrOverrides)) {
        toolName = toolNameOrOverrides;
      } else {
        toolOverride = toolNameOrOverrides;
        toolName = toolNameOrOverrides.name;
      }
      if (toolName === "oligoTool" && annotationsToSupport && annotationsToSupport.primers === false) return [];
      var Tool = toolOverride ? allTools[toolOverride.name] : allTools[toolName];
      if (!Tool) {
        console.error("You're trying to load a tool that doesn't appear to exist: " + toolName);
        return [];
      }
      if (isProtein) {
        if (toolName === "cutsiteTool" || toolName === "orfTool" || toolName === "alignmentTool") {
          return [];
        }
      }
      if (toolName === "saveTool" && !onSave) {
        return [];
      } //don't show the option to save if no onSave handler is passed

      return {
        toolName: toolName,
        toolOverride: toolOverride,
        Tool: Tool
      };
    });
  }, [toolList, annotationsToSupport, isProtein, onSave]);
  var items = flatMap(toolListToUse, function (_ref, index) {
    var toolName = _ref.toolName,
      toolOverride = _ref.toolOverride,
      Tool = _ref.Tool;
    if (!Tool) return [];
    return /*#__PURE__*/React.createElement(Tool, _extends({}, rest, userDefinedProps, {
      toolbarItemProps: _extends({}, userDefinedProps, {
        index: index,
        toolName: toolName,
        editorName: editorName
      }, toolOverride),
      editorName: editorName,
      key: toolName
    }));
  });
  if (modifyTools) {
    items = modifyTools(items);
  }
  return /*#__PURE__*/React.createElement("div", {
    className: "veToolbar-outer",
    style: {
      display: "flex"
    }
  }, contentLeft, /*#__PURE__*/React.createElement("div", {
    style: _extends({}, displayMenuBarAboveTools && showMenuBar ? {
      display: "flex",
      width: "100%",
      flexDirection: "column",
      alignItems: "flex-start"
    } : {
      display: "flex",
      width: "100%",
      justifyContent: "center",
      flexWrap: "wrap"
    }),
    className: "veToolbar"
  }, showMenuBar && /*#__PURE__*/React.createElement(MenuBar, _extends({
    openHotkeyDialog: openHotkeyDialog
  }, userDefinedProps, {
    onSave: onSave //needs to be passed so that editor commands will have it
    ,
    style: {
      marginLeft: 0
    },
    editorName: editorName
  })), displayMenuBarAboveTools && showMenuBar ? /*#__PURE__*/React.createElement("div", {
    className: "veTools-displayMenuBarAboveTools",
    style: _extends({
      display: "flex",
      paddingLeft: 15,
      paddingRight: 15,
      flexWrap: "wrap"
    }, isMobile() && {
      overflow: "auto",
      flexWrap: "nowrap",
      width: "100%"
    })
  }, items) : items), additionalTopRightToolbarButtons, closeFullscreen && /*#__PURE__*/React.createElement(CloseFullscreenButton, {
    onClick: handleFullscreenClose
  }));
}
var CloseFullscreenButton = function CloseFullscreenButton(props) {
  return /*#__PURE__*/React.createElement(Tooltip, {
    content: "Close Fullscreen Mode"
  }, /*#__PURE__*/React.createElement(Button, {
    minimal: true,
    style: {
      marginTop: 2,
      marginRight: 2
    },
    onClick: props.onClick,
    className: "ve-close-fullscreen-button",
    icon: "minimize"
  }));
};
var defaultToolList = ["saveTool", "downloadTool", "importTool", "undoTool", "redoTool", "cutsiteTool", "featureTool", "partTool", "oligoTool", "orfTool", "alignmentTool", "editTool", "findTool", "visibilityTool"];