"use client";
import { jsx } from "react/jsx-runtime";
import { $applyNodeReplacement, DecoratorNode, createEditor } from "lexical";
import * as __rspack_external_react from "react";
const AdmonitionNodeComponent = /*#__PURE__*/ __rspack_external_react.lazy(async ()=>await import("./admonition-node-component.js"));
function convertAdmonitionElement(domNode) {
    if (domNode instanceof HTMLDivElement) {
        const type = domNode.dataset.type;
        const title = domNode.dataset.title;
        const node = $createAdmonitionNode({
            admonitionType: type,
            title
        });
        return {
            node
        };
    }
    return null;
}
class AdmonitionNode extends DecoratorNode {
    static getType() {
        return 'admonition';
    }
    static clone(node) {
        return new AdmonitionNode(node.__admonitionType, node.__title, node.__content, node.__key);
    }
    static importJSON(serializedNode) {
        const { admonitionType, title, content } = serializedNode;
        const node = $createAdmonitionNode({
            admonitionType,
            title
        });
        const nestedEditor = node.__content;
        const editorState = nestedEditor.parseEditorState(content.editorState);
        if (!editorState.isEmpty()) nestedEditor.setEditorState(editorState);
        return node;
    }
    static importDOM() {
        return {
            div: (_node)=>({
                    conversion: convertAdmonitionElement,
                    priority: 0
                })
        };
    }
    exportDOM() {
        const element = document.createElement('div');
        element.setAttribute('data-type', this.__admonitionType);
        element.setAttribute('data-title', this.__title);
        return {
            element
        };
    }
    exportJSON() {
        return {
            admonitionType: this.__admonitionType,
            title: this.__title,
            content: this.__content.toJSON(),
            type: 'admonition',
            version: 1
        };
    }
    isInline() {
        return false;
    }
    getTitle() {
        return this.__title;
    }
    setTitle(title) {
        const writable = this.getWritable();
        writable.__title = title;
    }
    getAdmonitionType() {
        return this.__admonitionType;
    }
    setAdmonitionType(admonitionType) {
        const writable = this.getWritable();
        writable.__admonitionType = admonitionType;
    }
    update(payload) {
        const writable = this.getWritable();
        const { admonitionType, title } = payload;
        if (null != admonitionType) writable.__admonitionType = admonitionType;
        if (null != title) writable.__title = title;
    }
    createDOM(config) {
        const div = document.createElement('div');
        div.setAttribute('data-type', this.__admonitionType);
        div.setAttribute('data-title', this.__title);
        const className = `${config.theme.admonition} admonition-${this.__admonitionType}`;
        if (void 0 !== className) div.className = className;
        return div;
    }
    updateDOM(prevNode, dom, config) {
        const admonitionType = this.__admonitionType;
        if (admonitionType !== prevNode.__admonitionType) {
            const className = `${config.theme.admonition} admonition-${admonitionType}`;
            if (void 0 !== className) dom.className = className;
            dom.setAttribute('data-type', admonitionType);
            return true;
        }
        if (this.__title !== prevNode.__title) {
            dom.setAttribute('data-title', this.__title);
            return true;
        }
        return false;
    }
    decorate() {
        return /*#__PURE__*/ jsx(AdmonitionNodeComponent, {
            admonitionType: this.__admonitionType,
            title: this.__title,
            content: this.__content,
            nodeKey: this.getKey()
        });
    }
    constructor(admonitionType, title, content, key){
        super(key);
        this.__admonitionType = admonitionType;
        this.__title = title;
        this.__content = content ?? createEditor();
    }
}
function $createAdmonitionNode({ admonitionType, title, content, key }) {
    return $applyNodeReplacement(new AdmonitionNode(admonitionType, title, content, key));
}
function $isAdmonitionNode(node) {
    return node instanceof AdmonitionNode;
}
export { $createAdmonitionNode, $isAdmonitionNode, AdmonitionNode };
