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); }
import React from "react";
import { MenuBar, commandMenuEnhancer } from "teselagen-react-components";
import { compose } from "redux";
import { memoize } from "lodash";
import withEditorProps from "../withEditorProps";
import menuDef from "./defaultConfig";
import getCommands from "../commands";
import { Icon, Spinner } from "@blueprintjs/core";
var ident = function ident(x) {
  return x;
};
var OveMenuBar = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(OveMenuBar, _React$Component);
  function OveMenuBar(props) {
    var _this;
    _this = _React$Component.call(this, props) || this;
    _defineProperty(_assertThisInitialized(_this), "state", {
      // successMessage: "asdfasdf",
      // successMessageLoading: true
    });
    _defineProperty(_assertThisInitialized(_this), "getFilteredMenu", memoize(function (menuFilter, menuDef) {
      _this.counter++;
      if (_this.counter === 50) console.warn("It's likely you're passing a new \"menuFilter\" function every time. This will cause unecessary re-renders. Try not to recreate a new function each time!");
      return menuFilter(menuDef);
    }));
    _defineProperty(_assertThisInitialized(_this), "oveMenuToastrSuccess", function (message, _temp) {
      var _ref = _temp === void 0 ? {} : _temp,
        loading = _ref.loading;
      _this.setState({
        successMessage: message,
        successMessageLoading: loading
      });
      if (_this.clearId) {
        clearTimeout(_this.clearId);
      }
      _this.clearId = setTimeout(function () {
        _this.setState({
          successMessage: "",
          successMessageLoading: false
        });
      }, 5000);
    });
    var commands = getCommands(_assertThisInitialized(_this));
    window.oveMenuToastrSuccess = _this.oveMenuToastrSuccess;
    _this.enhancers = [commandMenuEnhancer(commands, {
      useTicks: true,
      omitIcons: true
    })];
    _this.counter = 0;
    return _this;
  }
  var _proto = OveMenuBar.prototype;
  _proto.render = function render() {
    var _this$props$menuFilte = this.props.menuFilter,
      menuFilter = _this$props$menuFilte === void 0 ? ident : _this$props$menuFilte;

    // Clone original menu def to protect it from accidental mutation
    return /*#__PURE__*/React.createElement("div", {
      className: "veMenuBarContainer",
      style: {
        display: "flex",
        width: "100%" /* height: "100%" */
      }
    }, /*#__PURE__*/React.createElement(MenuBar, {
      extraContent: this.state.successMessage && /*#__PURE__*/React.createElement("div", {
        className: "ove-menu-toast",
        style: {
          display: "flex",
          alignItems: "center",
          marginLeft: "auto",
          marginRight: 10
        }
      }, this.state.successMessageLoading ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Spinner, {
        size: 15
      })) : /*#__PURE__*/React.createElement(Icon, {
        icon: "tick-circle",
        intent: "success"
      }), " ", "\xA0", this.state.successMessage),
      menu: this.getFilteredMenu(menuFilter, menuDef),
      enhancers: this.enhancers
    }));
  };
  return OveMenuBar;
}(React.Component);
export default compose(withEditorProps)(OveMenuBar);