"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = DragDropPaste;
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
const rich_text_1 = require("@lexical/rich-text");
const utils_1 = require("@lexical/utils");
const lexical_1 = require("lexical");
const react_1 = require("react");
const ImagesPlugin_1 = require("../ImagesPlugin");
const ACCEPTABLE_IMAGE_TYPES = ['image/', 'image/heic', 'image/heif', 'image/gif', 'image/webp'];
function DragDropPaste() {
    const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
    (0, react_1.useEffect)(() => editor.registerCommand(rich_text_1.DRAG_DROP_PASTE, (files) => {
        // eslint-disable-next-line @typescript-eslint/no-extra-semi
        ;
        (async () => {
            const filesResult = await (0, utils_1.mediaFileReader)(files, [ACCEPTABLE_IMAGE_TYPES].flatMap((x) => x));
            for (const { file, result } of filesResult) {
                if ((0, utils_1.isMimeType)(file, ACCEPTABLE_IMAGE_TYPES)) {
                    editor.dispatchCommand(ImagesPlugin_1.INSERT_IMAGE_COMMAND, {
                        altText: file.name,
                        src: result,
                    });
                }
            }
        })();
        return true;
    }, lexical_1.COMMAND_PRIORITY_LOW), [editor]);
    return null;
}
//# sourceMappingURL=index.js.map