import { $applyNodeReplacement, $isElementNode } from "lexical";
import { LinkNode } from "./link-node.js";
class AutoLinkNode extends LinkNode {
    static getType() {
        return 'autolink';
    }
    static clone(node) {
        return new AutoLinkNode({
            attributes: node.__attributes,
            key: node.__key
        });
    }
    static importJSON(serializedNode) {
        const node = $createAutoLinkNode({
            attributes: serializedNode.attributes
        });
        node.setFormat(serializedNode.format);
        node.setIndent(serializedNode.indent);
        node.setDirection(serializedNode.direction);
        return node;
    }
    static importDOM() {
        return null;
    }
    exportJSON() {
        return {
            ...super.exportJSON(),
            type: 'autolink',
            version: 1
        };
    }
    insertNewAfter(selection, restoreSelection = true) {
        const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection);
        if ($isElementNode(element)) {
            const linkNode = $createAutoLinkNode({
                attributes: this.__attributes
            });
            element.append(linkNode);
            return linkNode;
        }
        return null;
    }
}
function $createAutoLinkNode({ attributes }) {
    return $applyNodeReplacement(new AutoLinkNode({
        attributes
    }));
}
function $isAutoLinkNode(node) {
    return node instanceof AutoLinkNode;
}
export { $createAutoLinkNode, $isAutoLinkNode, AutoLinkNode };
