"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _teselagenReactComponents = require("teselagen-react-components");
var _redux = require("redux");
var _lodash = require("lodash");
var _withEditorProps = _interopRequireDefault(require("../withEditorProps"));
var _defaultConfig = _interopRequireDefault(require("./defaultConfig"));
var _commands = _interopRequireDefault(require("../commands"));
var _core = require("@blueprintjs/core");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 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", (0, _lodash.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 = (0, _commands["default"])(_assertThisInitialized(_this));
    window.oveMenuToastrSuccess = _this.oveMenuToastrSuccess;
    _this.enhancers = [(0, _teselagenReactComponents.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["default"].createElement("div", {
      className: "veMenuBarContainer",
      style: {
        display: "flex",
        width: "100%" /* height: "100%" */
      }
    }, /*#__PURE__*/_react["default"].createElement(_teselagenReactComponents.MenuBar, {
      extraContent: this.state.successMessage && /*#__PURE__*/_react["default"].createElement("div", {
        className: "ove-menu-toast",
        style: {
          display: "flex",
          alignItems: "center",
          marginLeft: "auto",
          marginRight: 10
        }
      }, this.state.successMessageLoading ? /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_core.Spinner, {
        size: 15
      })) : /*#__PURE__*/_react["default"].createElement(_core.Icon, {
        icon: "tick-circle",
        intent: "success"
      }), " ", "\xA0", this.state.successMessage),
      menu: this.getFilteredMenu(menuFilter, _defaultConfig["default"]),
      enhancers: this.enhancers
    }));
  };
  return OveMenuBar;
}(_react["default"].Component);
var _default = (0, _redux.compose)(_withEditorProps["default"])(OveMenuBar);
exports["default"] = _default;
module.exports = exports.default;