"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.$isImageNode = exports.$createImageNode = exports.ImageNode = void 0;
const LexicalDecoratorBlockNode_1 = require("@lexical/react/LexicalDecoratorBlockNode");
const react_1 = __importDefault(require("react"));
const ImageComponent_1 = require("../components/ImageComponent");
class ImageNode extends LexicalDecoratorBlockNode_1.DecoratorBlockNode {
    static getType() {
        return 'image';
    }
    static clone(node) {
        return new ImageNode(node.__src, node.__caption, node.__format, node.__key);
    }
    constructor(src, caption, format, key) {
        super(format, key);
        this.__src = src;
        this.__caption = caption;
    }
    createDOM() {
        return document.createElement('div');
    }
    updateDOM() {
        return false;
    }
    decorate() {
        return (react_1.default.createElement(ImageComponent_1.ImageComponent, { src: this.__src, caption: this.__caption, nodeKey: this.__key }));
    }
    static importJSON(serializedNode) {
        return $createImageNode(serializedNode);
    }
    exportJSON() {
        return {
            ...super.exportJSON(),
            type: 'image',
            version: 1,
            src: this.__src,
            caption: this.__caption,
        };
    }
    exportDOM() {
        const figure = document.createElement('figure');
        const img = document.createElement('img');
        img.src = this.__src;
        figure.appendChild(img);
        if (this.__caption) {
            const caption = document.createElement('figcaption');
            caption.innerText = this.__caption;
            figure.appendChild(caption);
        }
        return { element: figure };
    }
}
exports.ImageNode = ImageNode;
function $createImageNode({ src, caption, }) {
    return new ImageNode(src, caption);
}
exports.$createImageNode = $createImageNode;
function $isImageNode(node) {
    return node instanceof ImageNode;
}
exports.$isImageNode = $isImageNode;
//# sourceMappingURL=ImageNode.js.map