"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = EditorHelp;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
var _eventTypes = require("../../../constants/event-types");
var _hotkeysHelper = _interopRequireDefault(require("../../../containers/hotkeys-helper"));
var _articleInfo = _interopRequireDefault(require("../../../containers/article-info"));
require("./style.css");
function EditorHelp(_ref) {
  let {
    children
  } = _ref;
  const [isShowHelpInfo, setIsShowHelpInfo] = (0, _react.useState)(false);
  const [isShowArticleInfo, setIsShowArticleInfo] = (0, _react.useState)(false);
  const updateArticleInfoState = (0, _react.useCallback)(() => {
    setIsShowArticleInfo(prevState => !prevState);
    setIsShowHelpInfo(false);
  }, []);
  const updateHelpInfoState = (0, _react.useCallback)(state => {
    setIsShowHelpInfo(state);
    setIsShowArticleInfo(false);
    const eventBus = _eventBus.default.getInstance();
    eventBus.dispatch(_eventTypes.INTERNAL_EVENTS.RESIZE_ARTICLE);
  }, []);
  (0, _react.useEffect)(() => {
    const eventBus = _eventBus.default.getInstance();
    const unsubscribeArticleInfo = eventBus.subscribe(_eventTypes.EXTERNAL_EVENTS.ON_ARTICLE_INFO_TOGGLE, updateArticleInfoState);
    const unsubscribeHelpInfo = eventBus.subscribe(_eventTypes.EXTERNAL_EVENTS.ON_HELP_INFO_TOGGLE, updateHelpInfoState);
    return () => {
      unsubscribeHelpInfo();
      unsubscribeArticleInfo();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [updateArticleInfoState, updateHelpInfoState]);
  const containerClass = (0, _classnames.default)('sf-markdown-help-wrapper', {
    'active': isShowArticleInfo || isShowHelpInfo
  });
  return /*#__PURE__*/_react.default.createElement("div", {
    className: containerClass
  }, /*#__PURE__*/_react.default.createElement(_articleInfo.default, {
    isVisible: isShowArticleInfo
  }), isShowHelpInfo && /*#__PURE__*/_react.default.createElement(_hotkeysHelper.default, null));
}