"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
var _eventTypes = require("../constants/event-types");
var _helper = require("../extension/plugins/image/helper");
var _helper2 = require("../extension/plugins/link/helper");
const useAttachments = editor => {
  (0, _react.useEffect)(() => {
    const insertImage = (targetEditor, _ref) => {
      let {
        title,
        url,
        isImage,
        selection = editor.selection
      } = _ref;
      if ((targetEditor === null || targetEditor === void 0 ? void 0 : targetEditor._id) !== editor._id) return;
      if (isImage) {
        (0, _helper.insertSeafileImage)({
          editor,
          title,
          url,
          selection
        });
      } else {
        (0, _helper2.insertSeafileLink)({
          editor,
          title,
          url,
          selection
        });
      }
    };
    const eventBus = _eventBus.default.getInstance();
    const subscribe = eventBus.subscribe(_eventTypes.EXTERNAL_EVENTS.INSERT_ATTACHMENTS, insertImage);
    return subscribe;
  }, [editor]);
};
var _default = exports.default = useAttachments;