"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _constants = require("../../constants");
var _elementTypes = require("../../constants/element-types");
var _helper = require("./helper");
const withImages = editor => {
  const {
    isInline,
    isVoid,
    insertData
  } = editor;
  const newEditor = editor;
  newEditor.isInline = element => {
    const {
      type
    } = element;
    if (type === _constants.ELementTypes.IMAGE) return true;
    return isInline(element);
  };
  newEditor.isVoid = element => {
    const {
      type
    } = element;
    if (type === _constants.ELementTypes.IMAGE) return true;
    return isVoid(element);
  };
  newEditor.insertData = data => {
    if (data.types && data.types.includes('Files') && data.files) {
      if (!newEditor.isSupportMultipleFiles) {
        const file = data.files[0];
        if (!file.type.includes(_elementTypes.IMAGE) && newEditor.isImageUploadOnly) return;
        (0, _helper.handleUpdateFile)(newEditor, file);
        return;
      }
      let files = [];
      for (let i = 0; i < data.files.length; i++) {
        const file = data.files[i];
        if (newEditor.isImageUploadOnly && !file.type.includes(_elementTypes.IMAGE)) continue;
        files.push(file);
      }
      const hasImage = files.some(file => file.type.includes(_elementTypes.IMAGE));
      for (let i = 0; i < files.length; i++) {
        const file = files[i];
        (0, _helper.handleUpdateFile)(newEditor, file, hasImage ? _constants.INSERT_POSITION.AFTER : _constants.INSERT_POSITION.CURRENT);
      }
      return;
    }
    return insertData(data);
  };
  return newEditor;
};
var _default = exports.default = withImages;